ERG*_*ERG 6 ontology sparql jena semantics
我有一个关于SPARQL的问题.我有动物的本体论:
Animals (is a superclass with object property <hasColor>)
------ Mammals (subclass of Animals)
------------- Dog (subclass of Mammals)
---------------- dog1 (a instance with property <hasColor>="white")
---------------- dog2 (a instance with property <hasColor>="red" )
------ Bird (subclass of Animals)
Run Code Online (Sandbox Code Playgroud)
是否有可能找到SPARQL"所有动物,'白''或"所有动物实例"?倒退:我怎么知道,如果一个实例(dog1)属于动物?
注意:类层次结构的深度和广度是事先未知的.
此外,下面的查询将无法正常工作
SELECT ?x WHERE {?x rdfs:subClassOf :Animals . ?x :has?olor "white"}
Run Code Online (Sandbox Code Playgroud)
并且下一个查询(查找所有动物,即'白色')仅在已知类层次结构的深度时才起作用.(所以,如果层次结构是已知的,我可以让指定的步骤(从层次结构底部的顶部)要达到的目标:在这种情况下,2个步骤.
SELECT ?z WHERE {
?x rdfs:subClassOf :Animals .
?y rdfs:subClassOf ?x .
?z rdf:type ?y .
?z :hasColor "white"
}
Run Code Online (Sandbox Code Playgroud)
下一个例子也是如此 - "查找动物的所有实例"
SELECT ?z WHERE {
?x rdfs:subClassOf :Animals .
?y rdfs:subClassOf ?x .
?z rdf:type ?y .
}
Run Code Online (Sandbox Code Playgroud)
怎么办,如果不知道的是什么?
查询将使用SDB处理(是Jena的一个组件).
我想要的东西:
select ?x where {?x rdfs:subClassOf :Animals . ?x :has?olor "white"})
UPD."查找所有动物(实例),即'白色'"的解决方案可能如下所示:
SELECT?y WHERE {?x rdfs:subClassOf*:动物.?rdf:输入?x.?y:hasColor"white"}
Rom*_*sse 12
您可以在SPARQL查询中使用传递性(使用*):
SELECT ?y WHERE { ?x rdfs:subClassOf* :Animals .
?y rdf:type ?x .
?y :hasColor "white" }
Run Code Online (Sandbox Code Playgroud)