使用 OWL ontology 中的限制值查询

Querying with restriction values from an OWL ontology

我开始学习推理如何针对 owl ontology,并且在确定我正在尝试做的事情是否真的可行时遇到了一些问题。

我用的ontology是ontology位于here; it references this foodontology的酒。我一直在研究 Protege 和 Jena 中的推理引擎。

我想要做的是确定 可以 与 MealCourse 实例关联的葡萄酒。我已将 LightMeatFowlCourse 的一个实例添加到 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>

现在我可以看到此实例的断言类型和推断类型,因此我相信推理有效 - 这是 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

所以现在我正在尝试使用 hasDrink 属性 来确定哪种葡萄酒可以搭配这门课程。在 ontology 中定义了几个限制,用于可以与此 属性 相关联的实例:hasBodyhasColor 等 - 这里是定义:

<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>

我能否 A) 获得这些限制,以便我可以确定哪种葡萄酒适合我的 MealCourse 实例,以及 B) 执行该查询以获取匹配的实例列表?

我一直在阅读有关查询 OWL 关系的 w3c 文档,我很确定这是可以做到的,但是我在使用 SPARQL 时遇到了一个真正的问题 - 我觉得我遗漏了一些非常明显的东西,但我不确定我到底应该看什么。

AKSW的评论给出了答案:

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