我需要一些帮助来从我的商店中选择合适的三元组......
<a> a <type/1> .
<b> a <type/1> .
<c> a <type/1> .
<c> a <type/2> .
我只想选择 type/1 而不是 type/2 的元素
使用 sparql 选择查询实现此目的的最佳方法是什么?
我正在寻找类似的东西:
select ?a where
{
?a a <type/1> .
!{ ?a a <type/2> }
}
谢谢,
:)
我需要一些帮助来从我的商店中选择合适的三元组......
<a> a <type/1> .
<b> a <type/1> .
<c> a <type/1> .
<c> a <type/2> .
我只想选择 type/1 而不是 type/2 的元素
使用 sparql 选择查询实现此目的的最佳方法是什么?
我正在寻找类似的东西:
select ?a where
{
?a a <type/1> .
!{ ?a a <type/2> }
}
谢谢,
:)
An alternative SPARQL 1.1 solution is to use MINUS e.g.
SELECT ?a
WHERE
{
?a a <type/1> .
MINUS { ?a a <type/2> . }
}
MINUS subtracts solutions that match its triple pattern from the existing matches.
In most cases using FILTER NOT EXISTS { } and MINUS { } are equivalent but beware there are some corner cases where this is not true - see the SPARQL 1.1 specification for some examples of this.
在 SPARQL 1.0 中,这有点棘手:
SELECT ?a WHERE {
?a a <type/1>.
OPTIONAL {
?a a ?othertype .
FILTER (?othertype = <type/2>)
}
FILTER (!BOUND(?othertype))
}
该OPTIONAL子句对具有?othertype的任何?a内容都具有约束力<type/2>,而对没有它的任何?a内容均不具有约束力。
然后最后FILTER只选择那些?a未绑定的行。
在 SPARQL 1.1 中,这要容易得多:
SELECT ?a WHERE {
?a a <type/1>.
FILTER NOT EXISTS { ?a a <type/2> . }
}