Frage

I'm trying to obtain a property that is on a superclass for an object I have found.

I have a list of universities found by this query:

SELECT * WHERE {
    ?University a dbpedia-owl:University.
    ?University dbpedia-owl:campus ?campus.
}
ORDER BY ?University LIMIT 10

I'm aware that University is a subclass of EducationalInstitution from these:

University contains the property campus, which is interesting, but EducationalInstitution contains the property locationCity, which I really want.

While I can grab the attribute campus that is directly a property of University, when I try to obtain the property locationCity, which lives on the parent class of EducationalInstitution, I get no results.

SELECT * WHERE {
    ?University a dbpedia-owl:University.
    ?University dbpedia-owl:locationCity ?loc
}
ORDER BY ?University LIMIT 10

What is the correct syntax for returning the properties of a parent class?

Or is my approach entirely incorrect, and I should begin my query by searching for EducationalInstitutions where has property University?

I've attempted the latter, too, but find no luck:

SELECT * WHERE {
   ?EducationalInstitution a dbpedia-owl:EducationalInstitution;
                           a dbpedia-owl:University.
   ?EducationalInstitution dbpedia-owl:locationCity ?City.
   }
ORDER BY ?University LIMIT 10

However, searching for a different field which belongs in University, not solely in EducationalInstitution, this does work:

SELECT * WHERE {
   ?EducationalInstitution a dbpedia-owl:EducationalInstitution;
                           a dbpedia-owl:University.
   ?EducationalInstitution dbpedia-owl:dean ?Dean.
   }
ORDER BY ?University LIMIT 10
War es hilfreich?

Lösung

OWL ontologies (what we're working with) aren't object oriented programming languages. Properties don't belong to classes. When we say that the domain of a property P is a class D, it means that when we see a triple on the property, e.g., X P Y, we can infer that X is a D. That's all it means. When the mapping page for University says that locationCity is a property on University, I think that what it means is that the domain of locationCity is a superclass of University, so it wouldn't be inconsistent if a University has a locationCity. I'm basing this on the results of the simple describe query describe dbpedia-owl:locationCity, which has these results (note that the domain of locationCity is Organisation, and that Organisation is a superclass of University):

@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dbpedia-owl:    <http://dbpedia.org/ontology/> .
@prefix owl:    <http://www.w3.org/2002/07/owl#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .

dbpedia-owl:locationCity
    rdf:type    owl:ObjectProperty ;
    rdfs:domain dbpedia-owl:Organisation ;
    rdfs:range  dbpedia-owl:City ;
    rdfs:label  "locatie stad"@nl , "ville"@fr , "location city"@en ;
    rdfs:comment    "City the thing is located."@en .

In general, it's useful to see what's actually in the data, and base your queries on that.For instance, you might look at the data that is defined for Rensselaer Polytechnic Institute and notice, for instance, that for the property dbpedia-owl:city it has the value dbpedia:Troy,_New_York. If you want to select things that have type dbpedia-owl:University (i.e., have dbpedia-owl:University as a value of the rdf:type property) and their values for the dbpedia-owl:city property, you just ask for it:

select ?university ?city where {
  ?university rdf:type dbpedia-owl:University .
  ?university dbpedia-owl:city ?city .
}

SPARQL results

In SPARQL, you can use a as an abbreviation for rdf:type, and when you have multiple triples with the same subject, you can combine them with the ; syntax, so we can make that query nicer looking as follows:

select ?university ?city where {
  ?university rdf:type dbpedia-owl:University ;
              dbpedia-owl:city ?city .
}

SPARQL results

Notice that I'm using the dbpedia-owl: properties here. These come from the DBpedia ontology, and that has much cleaner data than the raw infobox data (the dbpprop: properties). I've discussed this a bit more in this answer to Why there is differences in the number of links connected to the same property?.

Basing your queries on the data is actually pretty important. While the mappings wiki, as you saw, mentioned the locationCity property, it's not actually used on any Universities in the data:

select ?university ?city where {
  ?university a dbpedia-owl:University ;
              dbpedia-owl:locationCity ?city .
}

SPARQL results (no results)

You can even use SPARQL to find out what dbpedia-owl: properties have been used to relate Universities to Cities:

select distinct ?p where {
  ?university a dbpedia-owl:University ;
              ?p [ a dbpedia-owl:City ] .
  filter strstarts(str(?p),str(dbpedia-owl:))
}

SPARQL results

p
-------------------------------------------------
http://dbpedia.org/ontology/city
http://dbpedia.org/ontology/campus
http://dbpedia.org/ontology/state
http://dbpedia.org/ontology/affiliation
http://dbpedia.org/ontology/province
http://dbpedia.org/ontology/country
http://dbpedia.org/ontology/location
http://dbpedia.org/ontology/wikiPageRedirects
http://dbpedia.org/ontology/wikiPageDisambiguates
http://dbpedia.org/ontology/president
http://dbpedia.org/ontology/type

It's not immediately clear why some of those would be used (e.g., president, or type), but I can see where some might be used, if perhaps incorrectly (e.g., state, or province).

Andere Tipps

The answer seems to be the property is location, not locationCity.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top