Retrieving DBPedia Infobox Categories

I'm currently looking for a way to query the DBPedia Infobox ondology database through the SPARQL endpoint to get a list of classes, subclasses of the selected class, and properties of this class. As far as I was able to find, you either need to know the property you are looking for, or look for something specific - all the examples I found are based on the idea that you want to find something specific (for example, the population of cities above a certain level and etc.), while I would like to build something where I can effectively β€œbrowse” categories. For example, starting with the list of subclasses "owl: Thing" on this hierarchical class hierarchy and presenting the user with a list of subclasses of the selected subclass. It seems possible to view something like this using a wiki mapping, but it would be preferable to directly query the SPARQL endpoint.

Is there a simple SPARQL query that returns the available classes and properties of these classes?

Update: I came up with a way to get the class hierarchy, it seems, by iterating through this query:

SELECT ?subject WHERE { ?subject rdfs:subClassOf owl:Thing } 

It returns a list of owl: Thing subclasses, and if I replace owl: Thing with one of the subclasses, I get a list of subclasses of this until there are no subclasses, after which I can select all resources that are of the type specified by the selected subclass. I'm still not quite sure how to get all the properties common to a subclass.

Update 2 is now closer. This request gets me all the properties (dbpedia: property children), which are also a country, as well as their names:

 SELECT DISTINCT ?prop ?title WHERE { ?country ?prop ?value. ?country a <http://dbpedia.org/ontology/Country>. ?prop rdf:type rdf:Property. ?prop rdfs:label ?title } 

In fact, everything that I really requested. The last thing I'm trying to do now is try to sort them by the number of pages on which they appear (presumably the most common properties will be of the greatest interest).

+7
source share
4 answers

OK, so I really understood more precisely how to do this, so I present this as an answer, not just editing. What seems to give me exactly what I'm looking for is to start by iterating through the class hierarchy using this query :

 SELECT ?class ?label WHERE { ?class rdfs:subClassOf owl:Thing. ?class rdfs:label ?label. FILTER(lang(?label) = "en") } 

Submission of the selected result in the request instead of an owl: Thing every time.

Once the user has selected the level class they need to display a list of properties, in descending order of the number of records 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 really look at these results, there are some funky properties that don't have very descriptive shortcuts ("s"? What?), But this is at least what I was looking for in the first place.

+7
source

(1) Request 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) Request 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 } 
+3
source

This will give you all the properties that rdfs:domain has SpaceMission s:

 select ?property where { ?property rdfs:domain <http://dbpedia.org/ontology/SpaceMission> } 

These properties all accept SpaceMission as an object.

Note that in RDF (S), you do not need to have an explicit rdfs:domain operator for each property, because rdfs:domain can be implied using this property. Therefore, you may find that this query will provide you with a list of all the properties that were defined with the SpaceMission domain, but it will not give you a list of all the properties that are actually used with all instances of SpaceMission .

+2
source

It is possible that some of the properties are not actually defined as such:

  ? pa rdf: Property. 

but any term in the middle position is by definition a property. This way you can get more results:

  SELECT? Prop? Title WHERE {
      ? country a <http://dbpedia.org/ontology/Country>.
      ? country? prop [].
      ? prop rdfs: label? title.
 } 
 ORDER BY DESC (COUNT (DISTINCT? Country))

(slightly streamlined, being selective at the beginning, may improve performance)

+1
source

All Articles