我使用Allegrograph 4.13面对一个奇怪的行为
这是测试用例的数据
prefix : <http://example.com/example#>
INSERT DATA {
:A rdfs:label "A" .
:A :hasProp :Prop1 .
:Prop1 :Key "1" .
:Prop1 :Value "AA" .
:B :hasProp :Prop2 .
:Prop2 :Key "1" .
:Prop2 :Value "AA" .
:C :hasProp :Prop3 .
:C :hasProp :Prop4 .
:Prop3 :Key "1" .
:Prop3 :Value "AA" .
:Prop4 :Key "2" .
:Prop4 :Value "BB" .
}
鉴于:A,我需要找到具有完全相同属性的资源。 也就是说,我想找到:B但不是:C,因为:C有一个属性更多(Key&#34; 2&#34;和Value&#34; BB&#34;)
另见此问题Find individuals in SPARQL based on other relations / Compare sets
Joshua Taylor友情提供的以下查询直接使用资源(:A)并完全符合我的要求:
prefix : <http://example.com/example#>
select ?other ?k ?v {
:A :hasProp [ :Key ?k ; :Value ?v ] .
?other :hasProp [ :Key ?k ; :Value ?v ] .
filter not exists {
{ :A :hasProp [ :Key ?kk ; :Value ?vv ] .
filter not exists { ?other :hasProp [ :Key ?kk ; :Value ?vv ] .
}
}
union
{
?other :hasProp [ :Key ?kk ; :Value ?vv ] .
filter not exists { :A :hasProp [ :Key ?kk ; :Value ?vv ] .
}
}
}
}
答案:
-------------------
|other| k | v
|A | "1" | "AA"
|B | "1" | "AA"
-------------------
第二个是使用变量?a,因为我需要找到:首先根据某些标准(本例中为rdfs:label)
使用变量查询?a:
prefix : <http://example.com/example#>
select ?other ?k ?v {
?a rdfs:label "A" .
?a :hasProp [ :Key ?k ; :Value ?v ] .
?other :hasProp [ :Key ?k ; :Value ?v ] .
filter not exists {
{ ?a :hasProp [ :Key ?kk ; :Value ?vv ] .
filter not exists { ?other :hasProp [ :Key ?kk ; :Value ?vv ] .
}
}
union
{
?other :hasProp [ :Key ?kk ; :Value ?vv ] .
filter not exists { ?a :hasProp [ :Key ?kk ; :Value ?vv ] .
}
}
}
}
返回
-------------------
|other| k | v
|A | "1" | "AA"
|B | "1" | "AA"
|C | "1" | "AA"
-------------------
此查询还返回:C,这在我看来是错误的。
是否有人可以解释此行为或使用其他三重存储/ SPARQL引擎验证此测试用例?
根据评论中的请求,我添加了rdfs的前缀,并用变量替换了空白节点。这似乎没有效果。
prefix : <http://example.com/example#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?a ?pr1 ?pr2 ?other ?k ?v {
?a rdfs:label "A" .
# bind (:A as ?a) .
?a :hasProp ?pr1 .
?pr1 :Key ?k ; :Value ?v .
?other :hasProp ?pr2 .
?pr2 :Key ?k ; :Value ?v .
filter not exists {
{ ?a :hasProp ?pp1 .
?pp1 :Key ?kk ; :Value ?vv .
filter not exists { ?other :hasProp ?pp2 .
?pp2 :Key ?kk ; :Value ?vv .
}
}
union
{
?other :hasProp ?pp3 .
?pp3 :Key ?kk ; :Value ?vv .
filter not exists { ?a :hasProp ?pp4 .
?pp4 :Key ?kk ; :Value ?vv .
}
}
}
}
a pr1 pr2 other k v
A Prop1 Prop1 A "1" "AA"
A Prop1 Prop2 B "1" "AA"
A Prop1 Prop3 C "1" "AA"
如果我使用BIND(已注释)而不是使用rdfs:label的行,它看起来是一样的。
答案 0 :(得分:1)
我认为您在AllegroGraph中发现了一个错误。似乎添加?a rdfs:label“A”应该将?a 的值限制为:A ,这就是行为我们和耶拿见面。
Jena: VERSION: 2.11.0
Jena: BUILD_DATE: 2013-09-12T10:49:49+0100
ARQ: VERSION: 2.11.0
ARQ: BUILD_DATE: 2013-09-12T10:49:49+0100
RIOT: VERSION: 2.11.0
RIOT: BUILD_DATE: 2013-09-12T10:49:49+0100
prefix : <http://example.com/example#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?other ?k ?v {
?a rdfs:label "A" .
?a :hasProp [ :Key ?k ; :Value ?v ] .
?other :hasProp [ :Key ?k ; :Value ?v ] .
filter not exists {
{ ?a :hasProp [ :Key ?kk ; :Value ?vv ] .
filter not exists { ?other :hasProp [ :Key ?kk ; :Value ?vv ] .
}
}
union
{
?other :hasProp [ :Key ?kk ; :Value ?vv ] .
filter not exists { ?a :hasProp [ :Key ?kk ; :Value ?vv ] .
}
}
}
}
----------------------
| other | k | v |
======================
| :B | "1" | "AA" |
| :A | "1" | "AA" |
----------------------
提出重现此行为的最小示例并提交错误报告可能是有意义的。