SPARQL 查询 return 任意集合 objects
SPARQL query return arbitrary set of objects
我有一些数据包含 属性 hasNextSibling
。我希望能够查询任意一组兄弟姐妹。我可以轻松地获取特定点之后的所有兄弟姐妹,但是如何检索 X 和 Y 之间的兄弟姐妹。
例如,数据模型是Old-Lady-in-the-Shoe的children。一些兄弟姐妹依次是 Fred、Brandy、Chris、Zack、Emma、Brad [等等]。这个列表当然要长得多。我想要说 "give me all the siblings from Brandy to Emma" - 返回 Brandy、Chris、Zack、Emma 的能力。
我会有这样的查询:
SELECT ?name WHERE {
?kid rdfs:label 'Brandy' .
?kid local:hasNextSibling+ ?sib .
?sib rdfs:label ?name .
// this is where I need to stop if ?name = 'Emma'
// but the graph still needs to complete and return all the other siblings
}
我不能简单地过滤 ?name
小于我的结尾名称,因为标签(名称)不是任何可确定的或自然的顺序(因此需要 hasNextSibling 属性 来维护订单)。
假设你有这样的数据,孩子有标签和 hasNextSibling 属性:
@prefix : <urn:ex:> .
:a :label 'a' ; :hasNextSibling :b .
:b :label 'b' ; :hasNextSibling :c .
:c :label 'c' ; :hasNextSibling :d .
:d :label 'd' ; :hasNextSibling :e .
:e :label 'e' ; :hasNextSibling :f .
:f :label 'f' ; :hasNextSibling :g .
:g :label 'g' .
使用 属性 路径,您可以搜索具有向后 hasNextSibling 链到您想要的范围中的第一个以及向前 hasNextSibling 链到您想要的范围中的最后一个的孩子:
prefix : <urn:ex:>
select ?kid ?label where {
?kid ^:hasNextSibling* [:label 'b'] ;
:hasNextSibling* [:label 'd'] ;
:label ?label .
}
---------------
| kid | label |
===============
| :b | "b" |
| :c | "c" |
| :d | "d" |
---------------
如果您希望其中任何一个成为独占范围,您可以使用 +
属性 路径而不是 *
属性 路径。
prefix : <urn:ex:>
select ?kid ?label where {
?kid ^:hasNextSibling+ [:label 'b'] ;
:hasNextSibling+ [:label 'f'] ;
:label ?label .
}
---------------
| kid | label |
===============
| :c | "c" |
| :d | "d" |
| :e | "e" |
---------------
我有一些数据包含 属性 hasNextSibling
。我希望能够查询任意一组兄弟姐妹。我可以轻松地获取特定点之后的所有兄弟姐妹,但是如何检索 X 和 Y 之间的兄弟姐妹。
例如,数据模型是Old-Lady-in-the-Shoe的children。一些兄弟姐妹依次是 Fred、Brandy、Chris、Zack、Emma、Brad [等等]。这个列表当然要长得多。我想要说 "give me all the siblings from Brandy to Emma" - 返回 Brandy、Chris、Zack、Emma 的能力。
我会有这样的查询:
SELECT ?name WHERE {
?kid rdfs:label 'Brandy' .
?kid local:hasNextSibling+ ?sib .
?sib rdfs:label ?name .
// this is where I need to stop if ?name = 'Emma'
// but the graph still needs to complete and return all the other siblings
}
我不能简单地过滤 ?name
小于我的结尾名称,因为标签(名称)不是任何可确定的或自然的顺序(因此需要 hasNextSibling 属性 来维护订单)。
假设你有这样的数据,孩子有标签和 hasNextSibling 属性:
@prefix : <urn:ex:> .
:a :label 'a' ; :hasNextSibling :b .
:b :label 'b' ; :hasNextSibling :c .
:c :label 'c' ; :hasNextSibling :d .
:d :label 'd' ; :hasNextSibling :e .
:e :label 'e' ; :hasNextSibling :f .
:f :label 'f' ; :hasNextSibling :g .
:g :label 'g' .
使用 属性 路径,您可以搜索具有向后 hasNextSibling 链到您想要的范围中的第一个以及向前 hasNextSibling 链到您想要的范围中的最后一个的孩子:
prefix : <urn:ex:>
select ?kid ?label where {
?kid ^:hasNextSibling* [:label 'b'] ;
:hasNextSibling* [:label 'd'] ;
:label ?label .
}
---------------
| kid | label |
===============
| :b | "b" |
| :c | "c" |
| :d | "d" |
---------------
如果您希望其中任何一个成为独占范围,您可以使用 +
属性 路径而不是 *
属性 路径。
prefix : <urn:ex:>
select ?kid ?label where {
?kid ^:hasNextSibling+ [:label 'b'] ;
:hasNextSibling+ [:label 'f'] ;
:label ?label .
}
---------------
| kid | label |
===============
| :c | "c" |
| :d | "d" |
| :e | "e" |
---------------