检索 rdf:Class 的所有祖先

发布于 2024-08-06 06:20:24 字数 693 浏览 14 评论 0原文

想象一下以下分类法(非循环和有向图):

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

来日方长 2024-08-13 06:20:24

如果您已经在使用 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 of Model 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 the OntModel if you just want to do reasoning.

天赋异禀 2024-08-13 06:20:24

1)没有太多使用Jena,但是它的 OntTools 类似乎包含最低共同祖先的函数。如果智人与哺乳动物的最不共同祖先是哺乳动物,那么智人就是哺乳动物。但在底层,它使用递归 subClassOf 检索。

2)在一般情况下,不,SPARQL不支持任意深度树遍历。但是如果你知道 subClassOf 树的最大深度,那么你可以构造一个像

ASK {
  OPTIONAL {
    :HomoSapiens rdfs:subClassOf :Mammal
  }
  OPTIONAL {
    :HomoSapiens rdfs:subClassOf ?c .
    ?c rdfs:subClassOf :Mammal
  }
  OPTIONAL {
    :HomoSapiens rdfs:subClassOf ?c1 .
    ?c1 rdfs:subClassOf ?c2 .
    ?c2 rdfs:subClassOf :Mammal
  }

  # ... add
}

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

ASK {
  OPTIONAL {
    :HomoSapiens rdfs:subClassOf :Mammal
  }
  OPTIONAL {
    :HomoSapiens rdfs:subClassOf ?c .
    ?c rdfs:subClassOf :Mammal
  }
  OPTIONAL {
    :HomoSapiens rdfs:subClassOf ?c1 .
    ?c1 rdfs:subClassOf ?c2 .
    ?c2 rdfs:subClassOf :Mammal
  }

  # ... add
}
陌上芳菲 2024-08-13 06:20:24

laalto 是对的,几乎任何语义 Web 库都会通过递归 subClassOf 检索来完成此操作。解决这个问题的唯一方法是使用一些推理/推理引擎,当解析原始图时,它会向图添加额外的三元组,

例如,它会自动添加以下内容:

<my:Eukaryota> <rdf:type> <my:Organism>.
<my:Mammal> <rdf:type> <my:Organism>.
<my:Mammal> <rdf:type> <my:Eukaryota>.
<my:Primate> <rdfs:type> <my:Organism>.
<my:Primate> <rdfs:type> <my:Eukaryota>.
<my:Primate> <rdfs:type> <my:Mammal>.
# etc...

你在耶拿如何做到这一点我不知道当然,其他了解耶拿的人必须回答这个问题。

至于 SPARQL laalto 也是完全正确的,但在某些情况下,如果您查询的 Triple Store 和关联的 SPARQL 端点具有一些推理功能,您可能能够执行如下所示的简单查询

PREFIX my: <http://yournamespace.com>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
ASK { my:HomoSapiens rdf:type my:Mammal }

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:

<my:Eukaryota> <rdf:type> <my:Organism>.
<my:Mammal> <rdf:type> <my:Organism>.
<my:Mammal> <rdf:type> <my:Eukaryota>.
<my:Primate> <rdfs:type> <my:Organism>.
<my:Primate> <rdfs:type> <my:Eukaryota>.
<my:Primate> <rdfs:type> <my:Mammal>.
# etc...

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

PREFIX my: <http://yournamespace.com>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
ASK { my:HomoSapiens rdf:type my:Mammal }
吃→可爱长大的 2024-08-13 06:20:24

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
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文