您至少可以使用 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 .
然后你可以使用这样的查询:
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
得到这些结果:
-----------------------
| colatitudinalPoints |
=======================
| "e, f, g, h" |
| "a, b, c, d" |
-----------------------
有一些字符串处理
group_concat(strafter(str(?westernpoint),str(:));separator=", ") as ?colatitudinalPoints
你可能不需要的;关键是它?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
并得到
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 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" |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
确保节点上升
您的其他要求更具挑战性:
我只对从西向东移动时所有节点的 xsd:integer 属性上升的列表感兴趣,但是在我找到第一个问题的解决方案后,这应该相对容易。
也就是说,如果你能在类似的情况下明确你想要什么
w --eastof-> x --eastof-> y --eastof-> z
| | | |
5 6 2 3
例如,你想拒绝整个链,因为节点不是全部升序,还是你想获得两个子链w x
并且y z
其中的值是升序的?可能两者都可以……</p>