使用 SPARQL 获取图形路径 [英] getting a graph path using SPARQL
问题描述
我们有以下海龟数据集表示我们想要观察一些属性的图.
We have the following turtle dataset representing a graph where we want to observe some properties.
@prefix v1: <http://localhost:9091/graphe/> .
@prefix v2: <http://localhost:9091/graphe#> .
v1:a v2:p v1:b.
v1:a v2:q v1:f.
v1:a v2:p v1:g.
v1:b v2:p v1:c.
v1:c v2:q v1:h.
v1:c v2:p v1:i.
v1:c v2:p v1:d.
v1:d v2:p v1:e.
v1:f v2:p v1:g.
v1:f v2:q v1:l.
v1:f v2:p v1:k.
v1:g v2:p v1:c.
v1:g v2:p v1:f.
v1:h v2:p v1:n.
v1:i v2:q v1:j.
v1:j v2:p v1:o.
v1:j v2:q v1:n.
v1:k v2:p v1:l.
v1:l v2:p v1:g.
v1:m v2:q v1:g.
v1:n v2:p v1:m.
我们期望编写的查询必须打印源节点和目标节点之间的所有完整路径.
The query we are expecting to write must print all the full paths between a source and a destination node.
PREFIX g: <http://localhost:9091/graphe-ttl-1>
PREFIX t: <http://localhost:9091/graphe#>
PREFIX o: <http://localhost:9091/graphe/>
SELECT * WHERE {
GRAPH g: {
o:a t:p{*} o:o .
}}
这是我们到目前为止编写的查询,但由于没有任何变量表达式,因此没有得到任何输出.感谢您的帮助.
Here is the query we wrote so far but we are getting no output since we dont have any variables expression. Thank you for your help.
推荐答案
这会给你一个 & 之间的路径n 个节点.select ?start ?end (count(?mid) as ?length) where {values (?start ?end) { (:a :n) } ?start :p+ ?mid .?mid :p* ?end .}group by ?start ?end
This will give u path between a & n nodes.
select ?start ?end (count(?mid) as ?length) where {values (?start ?end) { (:a :n) } ?start :p+ ?mid . ?mid :p* ?end . }group by ?start ?end
这篇关于使用 SPARQL 获取图形路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!