首页 > 编程, 语义网 > How to explore an ontology using SPARQL 如何浏览一个本体

How to explore an ontology using SPARQL 如何浏览一个本体

This article gives some typical SPARQL queries I used for getting familiar with an ontology which is only accessible by a querying endpoint.

1. Classes used

SELECT count(?x) ?type
WHERE{
 ?x a ?type.
}
GROUP BY ?type

2. OWL Classes

Sometime also need to find instances of rdfs:Class

SELECT ?x
WHERE{
 ?x a owl:Class .
}LIMIT 100

Instance counting

SELECT count(?y) ?x
WHERE{
 ?x a owl:Class .
 ?y a ?x .
}
GROUP BY ?x

3. Class Hierarchy

SELECT ?s ?o
WHERE{
 ?s rdfs:subClassOf ?o .
}
LIMIT 100

4. Properties used

SELECT DISTINCT ?p
WHERE{
 ?x ?p ?o .
}
ORDER BY ASC(?p)
LIMIT 100

5. Property Axioms
Domains and ranges

SELECT ?s ?domain ?range
WHERE{
 ?s a rdf:Property .
 ?s rdfs:domain ?domain .
 ?s rdfs:range ?range .
}
ORDER BY ?p
LIMIT 100

Inverse Properties

SELECT *
WHERE{
 ?p1 owl:inverseOf ?p2 .
}
ORDER BY ?p1
LIMIT 100

6. Instances (Triples)

Total triples:

SELECT count(*)
WHERE{
 ?s ?p ?o .
}

Triples by property

SELECT (count(*) AS ?c) ?p
WHERE{
 ?s ?p ?o .
}
GROUP BY ?p
ORDER BY ?c

7. Class Slots

Example query

SELECT DISTINCT ?p
WHERE{
 ?s a loticoowl:Member .
 ?s ?p ?o .
}
ORDER BY ?p
LIMIT 100

Some properties are used by instances with no class membership

SELECT DISTINCT ?p
WHERE{
?s ?p ?o .
OPTIONAL { ?s a ?x }
FILTER ( ! bound(?x) )
}

References:

Advertisements
分类:编程, 语义网
  1. 还没有评论。
  1. 2012/04/16 @ 01:32

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: