I\'m currently looking for a way to query DBPedia\'s Infobox Onyology database via the SPARQL endpoint to get a list of the classes, the subclasses of a selected class, and
(1) Query for all existing classes:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?class
WHERE {
?s rdf:type ?class .
}
(2) Query for all properties used in any instance of class C:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?property
WHERE {
?s rdf:type <C> .
?s ?property ?o
}
It's quite possible that some of the properties aren't actually defined as such with:
?p a rdf:Property .
but any term in the middle position is by definition a property. So you might get more results with:
SELECT ?prop ?title WHERE { ?country a <http://dbpedia.org/ontology/Country>. ?country ?prop [] . ?prop rdfs:label ?title . } ORDER BY DESC(COUNT(DISTINCT ?country))
(reordered slightly, being selective at the start may improve performance)
This will get you all of the properties whose rdfs:domain
is SpaceMission
s:
select ?property where {
?property rdfs:domain <http://dbpedia.org/ontology/SpaceMission>
}
These properties all accept SpaceMission
as the subject.
Note that in RDF(S), it's not required to have an explicit rdfs:domain
statement for each property, because rdfs:domain
s can be implied by the usage of the property. You may find therefore that this query will give you a list of all properties that have been defined with a domain of SpaceMission
but won't give you a list of all properties that are actually used with all of the instances of SpaceMission
.
OK, so I've actually figured out more or less exactly how to do this, so I'm submitting this as an answer rather than just an edit. What seems to give me exactly what I'm looking for is to start by iterating through the class heirarchy using this query:
SELECT ?class ?label WHERE {
?class rdfs:subClassOf owl:Thing.
?class rdfs:label ?label.
FILTER(lang(?label) = "en")
}
Feeding the selected result into the query in place of owl:Thing each time.
Once the user has selected the lowest-level class that they'd like, to display a list of properties, in descending order by the number of entries in which they appear, I use this query:
SELECT ?prop ?title WHERE {
?country ?prop [].
?country a <http://dbpedia.org/ontology/Country>.
?prop rdf:type rdf:Property.
?prop rdfs:label ?title
} ORDER BY DESC(COUNT(DISTINCT ?country))
Of course, if you actually look at those results, there are some funky properties there that don't have very descriptive labels ("s"? What?), but this is at least what I was looking for in the first place.