[英]SPARQL - AND & OR Filters on Literal
I am trying to understand how to do filtering in SPARQL with combined AND and OR conditions. 我试图了解如何在结合AND和OR条件的情况下在SPARQL中进行过滤。
I try to find all physicists living within Newton's lifetime via the Wikidata Query Service (query.wikidata.org). 我试图通过Wikidata查询服务(query.wikidata.org)找到所有生活在牛顿一生中的物理学家。 This is my query:
这是我的查询:
SELECT ?p1 ?p1Label ?p1t1 ?p1t2 ?p2 ?p2Label ?p2t1 ?p2t2
WHERE {
FILTER (?p1=wd:Q935) . # Newton
?p1 wdt:P569 ?p1t1 . # date of birth
?p1 wdt:P570 ?p1t2 . # date of death
?p2 wdt:P106 wd:Q169470 . # physicist
?p2 wdt:P569 ?p2t1 . # date of birth
?p2 wdt:P570 ?p2t2 . # date of death
{ FILTER (xsd:dateTime(?p2t1) > xsd:dateTime(?p1t1))
. FILTER (xsd:dateTime(?p2t1) < xsd:dateTime(?p1t2)) }
UNION
{ FILTER (xsd:dateTime(?p2t2) > xsd:dateTime(?p1t1))
. FILTER (xsd:dateTime(?p2t2) < xsd:dateTime(?p1t2)) }
UNION
{ FILTER (xsd:dateTime(?p2t1) < xsd:dateTime(?p1t1))
. FILTER (xsd:dateTime(?p2t2) > xsd:dateTime(?p1t2)) } .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY xsd:dateTime(?p2t1)
The query can be processed but does not yield any results. 可以处理查询,但不会产生任何结果。
Each one of the three { FILTER . 三个{FILTER。 FILTER } blocks works fine when used without the others.
FILTER}块在不使用其他块的情况下可以正常工作。
What am I doing wrong? 我究竟做错了什么?
{ FILTER (xsd:dateTime(?p2t1) > xsd:dateTime(?p1t1))
. FILTER (xsd:dateTime(?p2t1) < xsd:dateTime(?p1t2)) }
evaluates to empty. 计算为空。
UNION
does not "or" them together -- ||
UNION
不会将它们“或”在一起-- ||
does that. 做到这一点。
Each branch of the UNION
is a separate graph pattern. UNION
每个分支都是单独的图形模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.