0
votes

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.

1
1.) RDF/XML is by far the worst format to read and understand OWL. When you're thinking about using SPARQL to query OWL, I'd highly recommend to look at your data in Turtle syntax because that's basically the SPARQL graph pattern format (modulo the variables etc.). 2) using SPARQL to query OWL can be horrible because OWL axioms and complex class expressions will be mapped to RDF by using multiple RDF triples, often with blank nodes, lists, etc. - and this can even be nested again.UninformedUser
That said, yes it's possible to query what you want, but you have to know the structure of your axioms in advance because with SPARQL have have to provide a specific pattern that matches the RDF (sub)graph you're interested inUninformedUser
a rough idea (untested and verbose to show you the possible structure): 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
@AKSW: Based on other comments I've seen from you around the site I was already starting to switch to turtle syntax, and you're right - it is a lot clearer to understand what the queries look like. Playing around with your query I did run into some of the issues with lists that you mentioned, but the query that you gave me does directly answer the question, so if you want to add it as an answer I'll accept it. Thanks!Matt McMinn

1 Answers

1
votes

The comment from AKSW gave the answer:

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]. 
}