Sparql 从OWL本体查询限制值
我开始学习如何对owl本体进行推理,并且在确定我尝试做的事情是否切实可行时遇到了一些问题 我使用的本体是葡萄酒本体;它引用了这个本体。我一直在玩Protege和Jena的推理引擎 我想做的是确定哪些葡萄酒可能与MealCourse实例相关。我已将Sparql 从OWL本体查询限制值,sparql,owl,ontology,rdfs,Sparql,Owl,Ontology,Rdfs,我开始学习如何对owl本体进行推理,并且在确定我尝试做的事情是否切实可行时遇到了一些问题 我使用的本体是葡萄酒本体;它引用了这个本体。我一直在玩Protege和Jena的推理引擎 我想做的是确定哪些葡萄酒可能与MealCourse实例相关。我已将LightMeatFowlCourse的一个实例添加到我的本体副本中: <owl:NamedIndividual rdf:about="http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#tes
LightMeatFowlCourse
的一个实例添加到我的本体副本中:
<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>
所以现在我尝试使用hasDrink属性来确定什么样的葡萄酒可以搭配这道菜。本体中为可与此属性关联的实例定义了几个限制:hasBody
、hasColor
,等等。以下是定义:
<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].
}
选择?p?val,其中{
rdfs:子类?限制。
?限制owl:onProperty。
?限制owl:allvalues来自[owl:onProperty?p;owl:hasValue?val]。
}
1。)RDF/XML是目前为止阅读和理解OWL最糟糕的格式。当您考虑使用SPARQL查询OWL时,我强烈建议您使用Turtle语法查看数据,因为这基本上是SPARQL图形模式格式(对变量进行模化等)。2) 使用SPARQL查询OWL可能会很糟糕,因为OWL公理和复杂类表达式将通过使用多个RDF三元组映射到RDF,通常带有空白节点、列表等,甚至可以再次嵌套。也就是说,可以查询您想要的内容,但是您必须提前知道您的公理的结构,因为使用SPARQL必须提供与您感兴趣的RDF(子)图相匹配的特定模式(未经测试和详细说明,以向您展示可能的结构):SELECT?p?val WHERE{rdfs:subassof?restriction。?restriction owl:onProperty。?restriction owl:allvalues from[owl:onProperty?p;owl:hasValue?val]。}
@AKSW:根据你在网站上看到的其他评论,我已经开始转向turtle语法,你是对的——理解查询的样子要清楚得多。在处理你的查询时,我确实遇到了一些你提到的列表问题,但你给我的查询直接影响了我的理解回答这个问题,如果你想加上它作为答案,我会接受的。谢谢!
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].
}