I'm starting to learn how inferencing works against an owl ontology, and having a bit of a problem determining if what I'm trying to do is actually possible.
The ontology that I'm using is the wine ontology located here; it references this food ontology. I've been playing around with the inferencing engines in both Protege and Jena.
What I'm trying to do is determine the wines that could be associated with a MealCourse instance. I've added an instance of the LightMeatFowlCourse
to my copy of the ontology:
<owl:NamedIndividual rdf:about="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#test">
<rdf:type rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#LightMeatFowlCourse"/>
<food:hasFood rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#Chicken" />
</owl:NamedIndividual>
Now I can see the types, both asserted and inferred, of this instance, so I believe that inferencing is working - here's the output of the types for this instance in Jena:
http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#LightMeatFowlCourse
http://www.w3.org/2002/07/owl#NamedIndividual
http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#MealCourse
http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#ConsumableThing
http://www.w3.org/2000/01/rdf-schema#Resource
So now I'm trying to use the hasDrink
property to determine what kinds of wine could go with this course. There are several restrictions defined in the ontology for instances that can be associated with this property: hasBody
, hasColor
, etc. - here's the definition:
<owl:Class rdf:about="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#LightMeatFowlCourse">
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#MealCourse"/>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#hasFood"/>
<owl:allValuesFrom rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#LightMeatFowl"/>
</owl:Restriction>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#MealCourse"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#hasDrink"/>
<owl:allValuesFrom>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#hasBody"/>
<owl:hasValue rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#Medium"/>
</owl:Restriction>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#hasDrink"/>
<owl:allValuesFrom>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#hasColor"/>
<owl:hasValue rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#White"/>
</owl:Restriction>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#hasDrink"/>
<owl:allValuesFrom>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#hasFlavor"/>
<owl:hasValue rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#Moderate"/>
</owl:Restriction>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#hasDrink"/>
<owl:allValuesFrom>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#hasSugar"/>
<owl:hasValue rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#Dry"/>
</owl:Restriction>
</owl:allValuesFrom>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
Can I A) get these restrictions, so I can determine what kinds of wine would be a match for my MealCourse instance, and B) perform that query to get the list of instances that are a match?
I've been reading through the w3c documents on querying OWL relationships and I'm pretty sure this can be done, but I'm having a real problem coming up with the SPARQL - I feel like I'm missing something pretty obvious, but I'm not sure what exactly I should be looking at.
SELECT ?p ?val WHERE { <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#LightMeatFowlCourse> rdfs:subClassOf ?restriction . ?restriction owl:onProperty <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#hasDrink>. ?restriction owl:allValuesFrom [owl:onProperty ?p; owl:hasValue ?val]. }
– UninformedUser