带量词的SPARQL查询

带量词的SPARQL查询,sparql,Sparql,我需要使用诸如ANY之类的量词进行查询(∀). 例如: 资料 查询就像 :a -> ?y -> ?z . ?z a :target_type . ∀?y, ?y is not a :target_type . (Here's the problem) 那么我希望得到?z只包含:c 如何通过sparql获得结果?听起来像是您在要求 选择?z其中{ :a:是的。 y:到z。 ?z a:目标类型。 筛选器不存在{ ?y a:目标类型 } } 这会找到任何?z,以便: z a:目标类型

我需要使用诸如ANY之类的量词进行查询(∀). 例如:

资料

查询就像

:a -> ?y -> ?z .
?z a :target_type .
∀?y, ?y is not a :target_type . (Here's the problem)
那么我希望得到?z只包含:c
如何通过sparql获得结果?

听起来像是您在要求

选择?z其中{
:a:是的。
y:到z。
?z a:目标类型。
筛选器不存在{
?y a:目标类型
}
}
这会找到任何?z,以便:

  • z a:目标类型;以及
  • :a
    连接到连接到?z的某物;以及
  • 并非是
    ?y a:targetType
这意味着:a通过某个?y连接到
:z
,因此?y不是:targetType。但是,如果要确保没有这样的?y是:targetType,您可以使用:

选择?z其中{
:a:to/:to?z。
?z a:目标类型。
筛选器不存在{
:a:是的。
y:到z。
?y a:目标类型
}
}

这是图形和查询结果。我期望的是结果“:d”,而不是“:d和:g”

@前缀ns:。
@前缀rdf:。
ns:a ns:to ns:b。
ns:b ns:to ns:c。
ns:c ns:to ns:d。
ns:d ns:to ns:e。
ns:e ns:to ns:f。
ns:f ns:to ns:g。
ns:gs:to ns:h。
ns:a rdf:type ns:target。
ns:d rdf:type ns:target。
ns:g rdf:type ns:target。

您是否尝试过这样的方法:
SELECT*WHERE{:a:to*?first\u tgt\u type a:target\u type FILTER NOT EXISTS{?first\u tgt\u type a:target\u type}}
是的,我尝试过这种方法。但是“NOT EXISTS”是一个存在量词,所以当y是:d,z是:f时,它也满足模式(例如:SELECT?z WHERE){:a:to+?y.?y:to+?z.?z a:target_type.过滤器不存在{y a:target_type},它返回?z是包含:c,:e,:f)的列表。你说的不对。你的约束
∀?y、 ?y不是更正式的目标类型
∀?y:∃ (?y a:target_type)可根据普通法重新制定为
∃?y:(?y a:target_type)
,因此建议的查询是正确的。
不存在
表示缺少给定的信息。您需要
:to*
加上一个附加的三重模式。请参见下面我的答案。我有一个更具体的问题描述。请参见下面我的答案。我有一个更具体的问题描述。
:a -> ?y -> ?z .
?z a :target_type .
∀?y, ?y is not a :target_type . (Here's the problem)
@prefix ns: <http://example/> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

ns:a ns:to ns:b .
ns:b ns:to ns:c .
ns:c ns:to ns:d .
ns:d ns:to ns:e .
ns:e ns:to ns:f .
ns:f ns:to ns:g .
ns:g ns:to ns:h .

ns:a rdf:type ns:target .
ns:d rdf:type ns:target .
ns:g rdf:type ns:target .