且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 SPARQL 查询查找最短路径

更新时间:2023-02-17 17:36:35

AndyS 提供了所有元素来回答这个问题,但有一些拼写错误可能会使它们难以应用.正如他所说:

AndyS gave all the elements to answer this question, but there are some typos that might make it hard to apply them. As he says:

SPARQL 1.1 具有属性路径,其中包含任意数量的 * 运算符.

SPARQL 1.1 has property path which includes the * operator for any number of.

它不会告诉你路径是什么,也不会告诉你最短路径的长度——只告诉你是否有这样的路径.

It does not tell you what the path is nor the length of the shortest path - only whether there is such a path.

这样做的方法(基于 AndyS,但有两个小问题)是:

The way to do this (based on AndyS, but with two little fixes) is:

PREFIX : <http://graphtheory/>
PREFIX node: <http://graphtheory/node/>

ASK { node:1 :hasNeighbor* node:2 }

据我所知,不使用属性路径就无法做到这一点.

As far as I can tell, there is no way to do this without using property paths.