繁体   English   中英

或在sparql查询中

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM