wikidata查询错过了欧洲国家

问题描述 投票:1回答:1

我对wikidata使用以下查询;

SELECT ?country ?countryLabel
      WHERE
      {
        ?country   wdt:P30 wd:Q46;
                   wdt:P31 wd:Q6256.
        SERVICE wikibase:label { bd:serviceParam wikibase:language
        "[AUTO_LANGUAGE],en". }
      }

P30是大陆的地方; Q46是欧洲; P31是实例,Q6256是国家;

https://query.wikidata.org/#SELECT%20%3Fcountry%20%3FcountryLabel%0A%20%20%20%20%20%20WHERE%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3Fcountry%20%20%20wdt%3AP30%20wd%3AQ46%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wdt%3AP31%20wd%3AQ6256.%0A%20%20%20%20%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%0A%20%20%20%20%20%20%20%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%20%20%20%20%7D

然而,此查询仅返回欧洲的15个国家。例如瑞典似乎没有返回,尽管瑞典似乎与https://www.wikidata.org/wiki/Q34的查询相符

因此,即使查询似乎是正确的,但它却遗漏了许多国家。关于如何解决这个问题的任何想法?

在比较两个条目时;一个用于德国/瑞典(没有出现)和挪威确实出现,我可以发现的差异是德国/瑞典的主权国家优先级别,而国家的正常级别。这可能是WHERE子句决定仅显示首选排名(如果存在)的原因;并跳过其余的陈述。如果是这种情况,我怀疑它是;我想知道是否有办法覆盖查询引擎的行为,以搜索具有首选排名或正常排名的所有语句。

sparql wikipedia wikidata
1个回答
0
投票

通过使用陈述来绕过真正的国家,我得到了更好的国家选择。这些陈述能够提取所有陈述,即使是那些排名正常的陈述。

SELECT DISTINCT ?country ?countryLabel
      WHERE
      {
        ?country   wdt:P30 wd:Q46.
        ?country p:P31 ?country_instance_of_statement .
        ?country_instance_of_statement ps:P31 wd:Q6256 .
        SERVICE wikibase:label { bd:serviceParam wikibase:language
        "[AUTO_LANGUAGE],en". 
        }
        filter not exists{?country p:P31/ps:P31 wd:Q3024240 }
      } 
      order by ?countryLabel

我还有一些额外的国家出现;比如德意志帝国。但我认为这是一个不同的问题需要解决。

https://query.wikidata.org/#SELECT%20distinct%20%3Fcountry%20%3Fcountry_instance_of_statement%20%3FcountryLabel%0A%20%20%20%20%20%20WHERE%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3Fcountry%20%20%20wdt%3AP30%20wd%3AQ46.%0A%20%20%20%20%20%20%20%20%3Fcountry%20p%3AP31%20%3Fcountry_instance_of_statement%20.%0A%20%20%20%20%20%20%20%20%3Fcountry_instance_of_statement%20ps%3AP31%20wd%3AQ6256%20.%0A%20%20%20%20%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%0A%20%20%20%20%20%20%20%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20filter%20not%20exists%7B%3Fcountry%20p%3AP31%2Fps%3AP31%20wd%3AQ3024240%20%7D%0A%20%20%20%20%20%20%7D%20%0A

请注意,country_instance_of_statement捕获所有语句,而不考虑排名。一旦我拥有那些,我使用'ps:P31 wd:Q6256'来取出那些有国家(“wd:Q6256”)作为对象。

我在上面提到了@AKSW的建议。

对于那些想要使用国家结束时间的另一种方法的人来说,这就是sparql

SELECT distinct ?country ?countryLabel
      WHERE
      {
        ?country   wdt:P30 wd:Q46.
        ?country p:P31 ?country_instance_of_statement .
        ?country_instance_of_statement ps:P31 wd:Q6256 .
        filter not exists {?country_instance_of_statement pq:P582 ?endTime }
        SERVICE wikibase:label { bd:serviceParam wikibase:language
        "[AUTO_LANGUAGE],en". 
        }
      } 
      order by ?countryLabel

https://query.wikidata.org/#SELECT%20distinct%20%3Fcountry%20%3Fcountry_instance_of_statement%20%3FcountryLabel%0A%20%20%20%20%20%20WHERE%0A%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3Fcountry%20%20%20wdt%3AP30%20wd%3AQ46.%0A%20%20%20%20%20%20%20%20%3Fcountry%20p%3AP31%20%3Fcountry_instance_of_statement%20.%0A%20%20%20%20%20%20%20%20%3Fcountry_instance_of_statement%20ps%3AP31%20wd%3AQ6256%20.%0A%20%20%20%20%20%20%20%20filter%20not%20exists%20%7B%3Fcountry_instance_of_statement%20pq%3AP582%20%3FendTime%20%7D%0A%20%20%20%20%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%0A%20%20%20%20%20%20%20%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%20%0A

© www.soinside.com 2019 - 2024. All rights reserved.