【发布时间】:2020-07-03 01:11:07
【问题描述】:
我正在尝试从 WikiData 查询中清除一些结果。例如,如果您查找 IBM,您会看到它的多个条目...我只想显示相同“wd:”项目的第一个结果。
有没有办法在这种情况下使用 FILTER 或 EXISTS?比如,如果找到 ?item 结果,继续……等等?如何处理 SPARQL sintax 中的这个示例?
我曾尝试使用“GROUP BY”来做到这一点,因为我看到一些人提到它,但它不起作用。
SELECT DISTINCT (SAMPLE (?item) AS ?item) ?itemLabel ?website ?countryLabel ?industryLabel ?headquartersLabel
WHERE {
?item wdt:P452 ?industry ;
wdt:P17 ?country .
FILTER((?industry = wd:Q11661) ||
(?industry = wd:Q11016) ||
(?industry = wd:Q880371) ||
(?industry = wd:Q3966) ||
(?industry = wd:Q1481411)||
(?industry = wd:Q1540863)||
(?industry = wd:Q638608))
OPTIONAL{ ?item wdt:P856 ?website . } # gets website
OPTIONAL{ ?item wdt:P159 ?headquarters . }
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en"
}
} GROUP BY ?item ?itemLabel ?website ?countryLabel ?industryLabel ?headquartersLabel
我也尝试过使用嵌套选择,它可以工作,但它不会返回表格的其余部分。
SELECT ?item ?itemLabel ?website ?country ?countryLabel ?industry ?industryLabel
WHERE {
SELECT DISTINCT ?item WHERE {
?item wdt:P452 ?industry ;
wdt:P17 ?country .
FILTER((?industry = wd:Q11661) ||
(?industry = wd:Q11016) ||
(?industry = wd:Q880371) ||
(?industry = wd:Q3966) ||
(?industry = wd:Q1481411)||
(?industry = wd:Q1540863)||
(?industry = wd:Q638608))
OPTIONAL{ ?item wdt:P856 ?website . } # gets website
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,ar,be,bg,bn,ca,cs,da,de,el,en,es,et,fa,fi,he,hi,hu,hy,id,it,ja,jv,ko,nb,nl,eo,pa,pl,pt,ro,ru,sh,sk,sr,sv,sw,te,th,tr,uk,yue,vec,vi,zh"
}}
}
ORDER BY ?item
【问题讨论】: