简体   繁体   English

查询以查找OWL本体中两个节点之间的所有路径

[英]Query to find all the path between two nodes in a OWL ontology

I am new in Sparql. 我是Sparql的新手。 I have a car ontology in OWL format. 我有OWL格式的汽车本体。 I am trying to write a query that takes names of two nodes from me and shows all the existing paths between them. 我正在尝试编写一个查询,该查询使用我的两个节点的名称并显示它们之间的所有现有路径。 For example in the following picture: example of my ontology's graph , if the input nodes are G and E, the path between them can be G cbe, G cadbe, G ca thing be, G h I e 例如下图: 本体图的示例 ,如果输入节点是G和E,则它们之间的路径可以是G cbe,G cadbe,G cathing,G h I e

I have used apache Jena to connect to my ontology from Eclipse. 我已经使用apache Jena从Eclipse连接到我的本体。 Now I need to write the query mentioned above. 现在,我需要编写上述查询。 Is there any example that can help me to write the query? 有没有可以帮助我编写查询的示例?

This not a use case where SPARQL shines. 这不是SPARQL发光的用例。 Although SPARQL uses graphs as a metaphor, it is not really ideal for implementing classical graph algorithms. 尽管SPARQL使用图作为隐喻,但是对于实现经典图算法而言,它并不是理想的选择。

In some cases, it may be easiest to implement things using multiple, iterative queries. 在某些情况下,使用多个迭代查询来实现事情可能是最简单的。 In other cases, it may be easier to use SPARQL to construct a subgraph containing the relevant individuals and property assertions, then uses that as input to one of the usual algorithms. 在其他情况下,使用SPARQL构造包含相关个体和属性声明的子图可能更容易,然后将其用作常规算法之一的输入。

Note that the problem of finding all paths between two nodes is NP-hard , so reducing the number of nodes that need to be considered is a good thing. 请注意, 查找两个节点之间的所有路径的问题是NP难题 ,因此减少需要考虑的节点数量是一件好事。 You may want to instead look for the top k shortest paths - the results of the ESWC 2016 challenge on this topic are now available ; 您可能需要寻找最短的k条最短路径-ESWC 2016挑战赛有关该主题的结果现在已经可用 unfortunately the papers aren't currently self-archived or open access. 不幸的是,这些文件目前还没有自存档或开放访问。

Depending on the implementation of the triple store, and the structure of the graph, it may be feasible to find all the triples involved in some path between a and b by looking for every c such that a owl:topObjectProperty+ ?c and ?c owl:topObjectProperty+ b . 根据三重存储和图形的结构的实现,它可能是可行的寻找每一个C找到所有参与AB之间的一些路径的三元组使得猫头鹰:??topObjectProperty + CC猫头鹰:topObjectProperty + b It is also possible that this kind of query may cause the server to melt, or your DBA to tie you to a chair and do evil things with UPS parts. 这种查询也有可能导致服务器崩溃,或者您的DBA将您绑在椅子上,并对UPS零件进行恶意处理。

Some systems provide extensions that make implementing such algorithms easier- for example AllegroGraph has non-standard support for first class paths . 某些系统提供了扩展,使实现这些算法更加容易-例如AllegroGraph对一流路径具有非标准支持。

I think the best way to do that is to implement an algorithm for it! 我认为最好的方法是为它实现一个算法! I don't think this task could be completed using SPARQL or some querying method. 我认为使用SPARQL或某些查询方法无法完成此任务。 I have implemented the following algorithm in Java and Jena to find all the directed paths connecting a set of nodes in an OWL ontology. 我已经在Java和Jena中实现了以下算法,以找到连接OWL本体中的一组节点的所有定向路径。 You can use your two required nodes as your input. 您可以使用两个必需的节点作为输入。

Given a graph G= (V, E) that is: 给定一个图G= (V, E)为:

  1. directed, 指示
  2. acyclic, 非循环的
  3. non-weighted, 非加权
  4. may have more than one edge between two vertices (thus, source and destination are not enough to determine an edge). 可能在两个顶点之间有一个以上的边(因此,源和目的地不足以确定一个边)。

And given a set of vertices, let's call them vSet ; 给定一组顶点,我们称它们为vSet that contains a vertex vRoot ; 包含顶点vRoot ; we need to find ALL paths pSet between vSet elements respecting the following: 我们需要遵循以下条件找到vSet元素之间的所有路径pSet

  1. any vertex that appears as a source for some path in pSet must be reachable from vRoot. 从vRoot必须可以访问任何显示为pSet某些路径来源的顶点。
  2. any path in pSet must has its source and destination from vSet , and must not contain any other vertex of vSet . 在任何路径pSet必须具有从其源和目的地vSet ,并且不能包含任何其它顶点vSet

The following algorithm is similar to BFS, that starts from vRoot (according to 1 above), grow each of the current paths with one edge per an iteration until it reaches another vertex v1 of vSet ; 下面的算法类似于BFS,它从vRoot (根据上面的1)开始,每次迭代用一条边增长当前路径,直到到达vSet另一个顶点v1 vSet then store this reaching path and start growing new set of paths starting from v1 . 然后存储此到达路径,并开始从v1开始增长一组新路径。

Here is the pseudo code: 这是伪代码:

output = ∅;
maxLengthPaths = ∅;
1. add all edges that vRoot is there source to maxLengthPaths
2. while size(maxlengthpaths) != ∅ do
  (a) paths := ∅;
  (b) extendedPaths := ∅;
  (c) foreach path p in maxLengthPaths do
    i. if (destination of p in vSet)
      1. add p to output 
      2. for each edge e that destination of p is its source
        A. add e to extendedPaths
    ii. else
      1. add p to paths
    iii. for path p1 in paths 
      1. for each edge that destination of p1  is its source
        A. extend p1 by a edge and add it to extendedPaths
  (d) maxLengthPaths = extendedPaths

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM