通过 ItemIdentifies 查询维基数据

Wikidata Query by ItemIdentifies

我想通过项目标识符查询给定城市的翻译。 为此,我在 karlsruhe

的 if 上查询 属性 p31

这是我的查询

 SELECT DISTINCT ?city ?label ?population WHERE {
  ?city (wdt:P31/wdt:P279*) wd:Q515. // is city
  ?city wdt:P31 wd:Q1040. //is karlsruhe
  ?city wdt:P1082 ?population.
  ?city rdfs:label ?label.
  FILTER(((LANG(?label)) = "de") || ((LANG(?label)) = "en") || ((LANG(?label)) = "it") || ((LANG(?label)) = "ru") || ((LANG(?label)) = "ro") || ((LANG(?label)) = "tr") || ((LANG(?label)) = "pl") || ((LANG(?label)) = "fr") || ((LANG(?label)) = "es") || ((LANG(?label)) = "hr"))
}

但我没有得到任何结果。

我做错了什么?

简而言之,问题是卡尔斯鲁厄不是a卡尔斯鲁厄。请仔细阅读 wdt:P31 的定义。

您的查询应该是:

SELECT DISTINCT ?city ?label ?population WHERE {
  VALUES (?city) { (wd:Q1040) }      # is Karlsruhe
  ?city (wdt:P31/wdt:P279*) wd:Q515  # is a city
  OPTIONAL { ?city wdt:P1082 ?population } 
  ?city rdfs:label ?label
  FILTER(LANG(?label) IN ("de", "en", "it", "ru", "ro", "tr", "pl", "fr", "es", "hr"))
}

为了更好地理解,可以这样重写上面的查询:

SELECT DISTINCT ?city ?label ?population WHERE {
  FILTER(?city IN (wd:Q1040))        # is Karlsruhe
  ?city (wdt:P31/wdt:P279*) wd:Q515  # is a city
  OPTIONAL { ?city wdt:P1082 ?population } 
  ?city rdfs:label ?label
  FILTER(LANG(?label) IN ("de", "en", "it", "ru", "ro", "tr", "pl", "fr", "es", "hr"))
}

在 RDFS++ 蕴涵下,甚至可以这样写:

SELECT DISTINCT ?city ?label ?population WHERE {
  ?city owl:sameAs wd:Q1040   # is Karlsruhe
  ?city wdt:P31 wd:Q515       # is a city
  OPTIONAL { ?city wdt:P1082 ?population } 
  ?city rdfs:label ?label
  FILTER(LANG(?label) IN ("de", "en", "it", "ru", "ro", "tr", "pl", "fr", "es", "hr"))
}