Does any one know how to query Classes with Object Property in Sparql? Assume we have an OWL file which contains follows
Human ----(hasPizza)---> Pizzas
Human and Pizzas are classes (or concepts). In SPARQL, this query returns nothing:
select ?x ?y where {
?x hasPizza ?y
}
But if I add two individuals (or entities) under those concepts like
Human:Jim ----(hasPizza)---> Pizzas:cheesePizza
that query will return ?x=Jim
and ?y=cheesePizza
How can I get ?x=Human
and ?y=Pizza
using SPARQL?
Given data like this (in RDF/XML):
or the same, in the more readable Turtle:
notice that the assertion
Jim hasPizza CheesePizza
is one triple in the graph. The domain and range axioms for thehasPizza
object property are two triples:hasPizza rdfs:domain Human
andhasPizza rdfs:range Pizza
. SPARQL queries match query patterns against the triples in the graph. Thus, from a query like:you will get results such as
because there is one triple in the graph whose predicate is
:hasPizza
, and that triple has a:Jim
as the subject, and:CheesePizza
as the object. It sounds like you're actually asking for the domain and range of the:hasPizza
property, which are also easy to retrieve. Use a query like this:and you'll get results like this: