SPARQL查询中的OR操作

3
这个Wikidata的SPARQL查询展示了所有以-ow或-itz结尾的德国(Q183)定居点的名称和坐标。该查询链接如下:这里
我想将其扩展以查找德国和奥地利的定居点。
我尝试修改第8行,例如:
wdt:P17 (wd:Q183 || wd:Q40);

为了查找奥地利(Q40)的地点,但这不是一个有效的查询。有什么方法可以扩展查询以包括其他国家?
1个回答

10
据我所知,没有比这更简单的语法了。但是,您可以使用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)$").
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接