Querying with restriction values from an OWL ontology
我开始学习如何针对猫头鹰本体进行推理,并且在确定我正在尝试做的事情是否真的可行时遇到了一些问题。
我使用的本体是位于此处的葡萄酒本??体;它引用了这个食物本体。我一直在使用 Protege 和 Jena 中的推理引擎。
我要做的是确定可能与 MealCourse 实例相关联的葡萄酒。我已将
1 2 3 4 | <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 中这个实例的类型输出:
1 2 3 4 5 | 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 |
所以现在我正在尝试使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <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 的评论给出了答案:
1 2 3 4 5 | 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]. } |