[英]How to do `FILTER (x IN ( … ) )` in SPARQL?
I'm trying to load all the subtaxons of Biota/Q2382433 (ie entities with P271 "parent taxon" pointing to Q2382433) in Wikidata. 我正在尝试在Wikidata中加载Biota / Q2382433的所有子分类单元(即具有P271“父分类单元”的实体指向Q2382433)。
The following query works fine : 以下查询工作正常 :
SELECT ?item ?itemLabel
(GROUP_CONCAT(DISTINCT ?class; SEPARATOR=", ") AS ?classes)
WHERE {
?class wdt:P171 ?item.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
BIND(wd:Q2382443 AS ?item)
}
GROUP BY ?item ?itemLabel
With FILTER
instead of BIND
, it yields zero results : 使用FILTER
而不是BIND
,将产生零结果 :
SELECT ?item ?itemLabel
(GROUP_CONCAT(DISTINCT ?class; SEPARATOR=", ") AS ?classes)
WHERE {
?class wdt:P171 ?item.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
FILTER(?item in (wd:Q2382443))
}
GROUP BY ?item ?itemLabel
How can I get the query to work using FILTER
? 如何使用FILTER
使查询工作?
For some reason on Wikidata when itemLabel
is added to the SELECT clause, the filter won't work. 出于某些原因,将itemLabel
添加到SELECT子句时,Wikidata上的过滤器将无法工作。 However, if you remove it, the query works fine. 但是,如果将其删除,则查询工作正常。
You could also redeclare the triple pattern with a new variable name and filter on it: 您还可以使用新的变量名称重新声明三元模式并对其进行过滤:
SELECT ?item ?itemLabel
(GROUP_CONCAT(DISTINCT ?class; SEPARATOR=", ") AS ?classes)
WHERE {
?class wdt:P171 ?item .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
?class wdt:P171 ?parentTaxon .
FILTER(?parentTaxon IN (wd:Q2382443))
}
GROUP BY ?item ?itemLabel
Edit: VALUE
also works: 编辑: VALUE
也可以:
SELECT ?item ?itemLabel
(GROUP_CONCAT(DISTINCT ?class; SEPARATOR=", ") AS ?classes)
WHERE {
?class wdt:P171 ?item .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
VALUES ?item { wd:Q2382443 }
}
GROUP BY ?item ?itemLabel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.