Here is a small ontology called wildlife.owl
, created by Protégé, in which I have classes animal
, carnivore
, herbivore
, lion
, giraffe
, and individuals Léo
(a lion
), Gigi
(a giraffe
) and Giginou
(also a giraffe
). In the ontology I only declare that lion ⊏ carnivore ⊏ animal
.
When I ask for the instances of animal
in the DL Query tab of Protégé, I get, among others, Léo
(which is a lion
, hence a carnivore
, hence an animal
).
But when I write the following SPARQ Query:
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 xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX me: <file:wildlife.owl#>
SELECT ?b
WHERE { ?b rdf:type me:animal }
I don't get any instance. Same result when I replace me:animal
by me:carnivore
. Only when I replace it by me:lion
I get the desired result Léo
.
Why is DL Query doing the inference (allowing me to obtain Léo
as instance of the animal
class) and not SPARQL Query?
What can I do to get the same result in SPARQL Query?
Thanks to the answer by @UninformedUser I now know that I must use the Snap SPARQL Query and not the SPARQL Query.
My next question concerns Python: when I send the SPARQL Query using Owlready2 and RDFlib, again I get no result:
from owlready2 import *
from rdflib import *
onto = get_ontology("wildlife.owl").load()
sync_reasoner([onto])
graph = default_world.as_rdflib_graph()
print(list(graph.query_owlready("""
PREFIX rdf-syntax: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX me: <file:wildlife.owl#>
SELECT ?b WHERE {
?b rdf-syntax:type me:animal .
}""")))
How can I get this query use OWL Reasoner?