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
<
Given data like this (in RDF/XML):
or the same, in the more readable Turtle:
@prefix : .
@prefix rdfs: .
@prefix pizzas: .
@prefix owl: .
@prefix xsd: .
@prefix rdf: .
pizzas:Jim
a pizzas:Human , owl:NamedIndividual ;
pizzas:hasPizza pizzas:CheesePizza .
pizzas:hasPizza
a owl:ObjectProperty ;
rdfs:domain pizzas:Human ;
rdfs:range pizzas:Pizza .
pizzas:Human
a owl:Class .
pizzas:Pizza
a owl:Class .
a owl:Ontology .
pizzas:CheesePizza
a pizzas:Pizza , owl:NamedIndividual .
notice that the assertion Jim hasPizza CheesePizza is one triple in the graph. The domain and range axioms for the hasPizza object property are two triples: hasPizza rdfs:domain Human and hasPizza rdfs:range Pizza. SPARQL queries match query patterns against the triples in the graph. Thus, from a query like:
prefix :
select ?x ?y where {
?x :hasPizza ?y
}
you will get results such as
$ arq --data pizzas.ttl --query query.sparql
-----------------------
| x | y |
=======================
| :Jim | :CheesePizza |
-----------------------
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:
prefix :
prefix rdfs:
select ?domain ?range where {
:hasPizza rdfs:domain ?domain ;
rdfs:range ?range .
}
and you'll get results like this:
$ arq --data pizzas.ttl --query query.sparql
-------------------
| domain | range |
===================
| :Human | :Pizza |
-------------------