计算节点之间的路径长度(边未知)?

Calculate length of path betwen nodes (with unknown edges)?

问题是如何在不知道边类型的情况下使用 sparql 查询计算三重存储 (RDF) 中两个节点(概念)之间的距离。本质上就是使用Dijkstras_algorithm 在三重存储中找到两个概念之间的较短路径。

如果我们知道egde的类型是可能的: Calculate length of path between nodes?

另一种解决方案是使用 类 距离(如果概念未从主要 类 扩展,则不起作用): Measuring distances among classes in RDF/OWL graphs

示例:

找出http://bioinformatics.ua.pt/coeus/resource/uniprot_P01008 and http://bioinformatics.ua.pt/coeus/resource/go_GO:0005576

之间的较短距离

您可以使用 Calculate length of path between nodes? 中使用的相同技术,但您需要使用通配符而不是特定的 属性。模式 (<>|!<>) 是一个通配符,因为每个 属性 要么是 <>,要么不是。您也可以使用 (:|!:),但只有当您定义了 : 前缀时才有效。 (<>|!<>) 将始终有效。这是一个例子:

@prefix : <urn:ex:>

:a :p :b .
:b :q :c .
:c :r :d .
:d :s :e .
prefix : <urn:ex:>

select ?start ?end (count(?mid) as ?length) {
  ?start (<>|!<>)* ?mid .
  ?mid (<>|!<>)+ ?end .
}
group by ?start ?end
------------------------
| start | end | length |
========================
| :a    | :b  | 1      |
| :a    | :c  | 2      |
| :a    | :d  | 3      |
| :a    | :e  | 4      |
| :b    | :c  | 1      |
| :b    | :d  | 2      |
| :b    | :e  | 3      |
| :c    | :d  | 1      |
| :c    | :e  | 2      |
| :d    | :e  | 1      |
------------------------