检索 rdf:Class 的所有祖先
想象一下以下分类法(非循环和有向图):
<my:Eukaryota> <rdfs:subClassOf> <my:Organism>.
<my:Mammal> <rdfs:subClassOf> <my:Eukaryota>.
<my:Primate> <rdfs:subClassOf> <my:Mammal>.
<my:HomoSapiens> <rdfs:subClassOf> <my:Primate>.
<my:Bacteria> <rdfs:subClassOf> <my:Organism>.
<my:Escherichia> <rdfs:subClassOf> <my:Bacteria>.
1) 是否可以使用 Jena OWL API 来检查如果给定资源(例如 HomoSapiens)是“哺乳动物”的子类,而无需递归检索所有父节点?
2)与SPARQL有同样的问题。
谢谢
Imagine the following Taxonomy (acyclic & directed graph):
<my:Eukaryota> <rdfs:subClassOf> <my:Organism>.
<my:Mammal> <rdfs:subClassOf> <my:Eukaryota>.
<my:Primate> <rdfs:subClassOf> <my:Mammal>.
<my:HomoSapiens> <rdfs:subClassOf> <my:Primate>.
<my:Bacteria> <rdfs:subClassOf> <my:Organism>.
<my:Escherichia> <rdfs:subClassOf> <my:Bacteria>.
1) Is it possible with the Jena OWL API to check if a given resource (e.g. HomoSapiens) is a subclass of 'Mammal' without recursively retrieving all the parents nodes ?
2) The same question with SPARQL.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您已经在使用 Jena,则可以使用 Pellet 的 SPARQL-DL 查询引擎,它应该允许您以本体感知的方式查询个人。
或者,您可以使用 Jena 的
InfModel
而不是Model
接口,将推理器(和本体)附加到它,然后运行 RobV 提到的查询。如果您愿意,可以使用 Pellet 的推理机。如果您只想进行推理,则不需要使用OntModel
。If you're already using Jena, you can use use Pellet's SPARQL-DL query engine, which should let you query individuals in an ontology-aware way.
Alternately, you can use Jena's
InfModel
instead ofModel
interface, attach a reasoner (and ontology) to it, and then run the query RobV mentions. You can use Pellet's reasoner for this if you wanted. You don't need to use theOntModel
if you just want to do reasoning.1)没有太多使用Jena,但是它的 OntTools 类似乎包含最低共同祖先的函数。如果智人与哺乳动物的最不共同祖先是哺乳动物,那么智人就是哺乳动物。但在底层,它使用递归 subClassOf 检索。
2)在一般情况下,不,SPARQL不支持任意深度树遍历。但是如果你知道 subClassOf 树的最大深度,那么你可以构造一个像
1) Haven't used Jena much, but its OntTools class seems to contain functions for lowest common ancestor. If the least common ancestor of HomoSapiens and Mammal is Mammal, then HomoSapiens is a Mammal. Under the hood it uses recursive subClassOf retrieval though.
2) In the generic case, no, SPARQL does not support arbitrary depth tree traversal. But if you know the maximum depth of the subClassOf tree, then you can construct a query like
laalto 是对的,几乎任何语义 Web 库都会通过递归 subClassOf 检索来完成此操作。解决这个问题的唯一方法是使用一些推理/推理引擎,当解析原始图时,它会向图添加额外的三元组,
例如,它会自动添加以下内容:
你在耶拿如何做到这一点我不知道当然,其他了解耶拿的人必须回答这个问题。
至于 SPARQL laalto 也是完全正确的,但在某些情况下,如果您查询的 Triple Store 和关联的 SPARQL 端点具有一些推理功能,您可能能够执行如下所示的简单查询
laalto is right, pretty much any Semantic Web library is going to do it via recursive subClassOf retrieval. Only way you might get around this would be to have some inference/reasoning engine which would add additional Triples to the Graph as the original Graph is parsed
So for example it would automatically add the following:
How you do this in Jena I'm not sure, someone else who knows Jena would have to answer that.
As for SPARQL laalto is again entirely correct, in some cases though you might be able to do a simple query like the following if the Triple Store and the associated SPARQL endpoint you query have some inference capabilities
SPARQL 1.1 具有任意深度图遍历。可以用于此目的。请参阅 BioStar 处的相关问题 询问
{
:智人 rdfs:subClassOf+ :哺乳动物
}
SPARQL 1.1 has arbitrary depth graph traversal. Which can be used for this. See related question at BioStar
ASK {
:HomoSapiens rdfs:subClassOf+ :Mammal
}