[英]OR in sparql query
Wikidata上的這個sparql查詢顯示了德國(Q183)中所有以-ow或-itz結尾的名稱的地方。
我想將其擴展到德國和奧地利等地。
我嘗試將第8行修改為:
wdt:P17 (wd:Q183 || wd:Q40);
為了尋找奧地利的地方(Q40),但這不是有效的查詢。
如何將查詢擴展到其他國家/地區?
Afaik沒有這么簡單的語法。 但是,您可以使用UNION
達到相同的效果:
SELECT ?item ?itemLabel ?coord
WHERE
{
?item wdt:P31/wdt:P279* wd:Q486972;
rdfs:label ?itemLabel;
wdt:P625 ?coord;
{?item wdt:P17 wd:Q183}
UNION
{?item wdt:P17 wd:Q40}
FILTER (lang(?itemLabel) = "de") .
FILTER regex (?itemLabel, "(ow|itz)$").
}
或者作為替代,使用VALUES
創建一個包含兩個國家的新變量:
SELECT ?item ?itemLabel ?coord
WHERE
{
VALUES ?country { wd:Q40 wd:Q183 }
?item wdt:P31/wdt:P279* wd:Q486972;
wdt:P17 ?country;
rdfs:label ?itemLabel;
wdt:P625 ?coord;
FILTER (lang(?itemLabel) = "de") .
FILTER regex (?itemLabel, "(ow|itz)$").
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.