I want to make a SPARQL query which returns a list of all Ontology classes/properties which are related to Person
. For eg., like the subclasses (derived from) of Person
<rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Person"/>
or have a domain/range of Person
<rdfs:domain rdf:resource="http://dbpedia.org/ontology/Person"/>
.
For example, the results like "http://dbpedia.org/ontology/OfficeHolder"
& "http://dbpedia.org/ontology/Astronaut"
should be returned by the query, as the first one has rdfs:domain
Person while the second one was a rdfs:subClassOf
Person.
Here's the query I've written:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
select distinct ?s
where {
{
?s rdfs:domain dbo:Person .
}
union
{
?s rdfs:range dbo:Person .
}
union
{
?s rdfs:subClassOf dbo:Person .
}
}
Now, this query returns a list of all the classes that explicitly mention Person
in their Properties, but miss out classes like Singer
, which is a subclass of MusicalArtist
, which is in the domain of Person.
I want a query that lists out all such classes/properties, which are related to Person, directly or by "inheritance". Any suggestions?
It seems, you confuse classes with properties... Read carefully RDFS 1.1, it is short.
If you want to retrieve both classes and properties "related to" dbo:Person
, use property paths:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?p ?s WHERE
{
{
?s (rdfs:subPropertyOf|owl:equivalentProperty|^owl:equivalentProperty)*/
rdfs:domain/
(rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)*
dbo:Person .
BIND (rdfs:domain AS ?p)
}
UNION
{
?s (rdfs:subPropertyOf|owl:equivalentProperty|^owl:equivalentProperty)*/
rdfs:range/
(rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)*
dbo:Person .
BIND (rdfs:range AS ?p)
}
UNION
{
?s (rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)*
dbo:Person .
BIND (rdfs:subClassOf AS ?p)
}
# FILTER (STRSTARTS(STR(?s), "http://dbpedia.org/"))
}