是否有可能通过与SPARQL的传递关系获得连接的节点列表?我有以这种方式连接的元素:
?a g:eastOf ?b
?b g:eastOf ?c
…
Run Code Online (Sandbox Code Playgroud)
并非所有节点都相互连接,因为有些节点更向南.只有当节点垂直在同一平面上时,才会存在g:eastOf关系.这意味着有几组节点彼此没有连接.
我想得到所有这些节点组(基本上是列表列表).有没有办法在SPARQL中做到这一点?该SELECT陈述需要有限数量的变量,并且不能以某种方式表达"某事物列表".
我只对xsd:integer所有节点的属性从西向东升的列表感兴趣,但是在我得到第一个问题的解决方案后,这应该相对容易.
您可以使用SPARQL 1.1执行至少部分操作.
假设您有数据,其中有两组点基于以下形式构成一行:eastOf:
@prefix : <http://stackoverflow.com/q/4056008/1281433/>
:a :eastOf :b .
:b :eastOf :c .
:c :eastOf :d .
:e :eastOf :f .
:f :eastOf :g .
:g :eastOf :h .
Run Code Online (Sandbox Code Playgroud)
然后你可以使用这样的查询:
prefix : <http://stackoverflow.com/q/4056008/1281433/>
select (group_concat(strafter(str(?westernpoint),str(:));separator=", ") as ?colatitudinalPoints)
where {
?easternmost :eastOf* ?westernpoint .
filter not exists { ?easternmoster :eastOf ?easternmost }
}
group by ?easternmost
Run Code Online (Sandbox Code Playgroud)
得到这些结果:
-----------------------
| colatitudinalPoints |
=======================
| "e, f, g, h" |
| "a, b, c, d" |
-----------------------
Run Code Online (Sandbox Code Playgroud)
有一些字符串处理
group_concat(strafter(str(?westernpoint),str(:));separator=", ") as ?colatitudinalPoints
Run Code Online (Sandbox Code Playgroud)
你可能不需要; 关键在于它?westernpoint是东部以西的点的IRI ?easternmost(实际上包括?easternmost,因为我们*在属性路径中使用),然后我们需要以某种方式将它们连接在一起.在这里,我做了一些字符串处理,使结果更漂亮.你可以轻松做到
prefix : <http://stackoverflow.com/q/4056008/1281433/>
select (group_concat(?westernpoint;separator=", ") as ?colatitudinalPoints)
where {
?easternmost :eastOf* ?westernpoint .
filter not exists { ?easternmoster :eastOf ?easternmost }
}
group by ?easternmost
Run Code Online (Sandbox Code Playgroud)
得到
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| colatitudinalPoints |
============================================================================================================================================================================================
| "http://stackoverflow.com/q/4056008/1281433/e, http://stackoverflow.com/q/4056008/1281433/f, http://stackoverflow.com/q/4056008/1281433/g, http://stackoverflow.com/q/4056008/1281433/h" |
| "http://stackoverflow.com/q/4056008/1281433/a, http://stackoverflow.com/q/4056008/1281433/b, http://stackoverflow.com/q/4056008/1281433/c, http://stackoverflow.com/q/4056008/1281433/d" |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
您的其他要求更具挑战性:
我只对所有节点的xsd:integer属性从西向东升序的列表感兴趣,但在我得到第一个问题的解决方案后,这应该相对容易.
也就是说,如果你可以在类似的情况下准确地澄清你想要的东西
w --eastof-> x --eastof-> y --eastof-> z
| | | |
5 6 2 3
Run Code Online (Sandbox Code Playgroud)
例如,你想拒绝整个链,因为节点不是全部提升,或者你想获得两个子链w x,y z其中值是递增的?有可能做到两个......
| 归档时间: |
|
| 查看次数: |
1307 次 |
| 最近记录: |