wikidata 查询遗漏了欧洲国家 [英] wikidata query missing out countries in Europe

查看:48
本文介绍了wikidata 查询遗漏了欧洲国家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对维基数据使用以下查询;

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

其中 P30 是大陆;Q46是欧洲;P31是Instance Of,Q6256是country;

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%3F国家%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%2020%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 子句决定仅显示首选排名(如果存在)的原因;并跳过剩余的语句.如果是这种情况,我怀疑是这样;我想知道是否有一种方法可以覆盖查询引擎的行为,以搜索具有首选排名或正常排名的所有语句.

解决方案

通过使用语句绕过真相时,我可以更好地选择国家/地区.语句能够拉出所有语句,即使是普通级别的语句.

SELECT DISTINCT ?country ?countryLabel在哪里{?国家 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".}过滤器不存在{?国家 p:P31/ps:P31 wd:Q3024240 }}按 ?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%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' 来拉出那些以 country ("wd:Q6256") 作为对象的.

我在上面添加了来自@AKSW 的建议.

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

SELECT distinct ?country ?countryLabel在哪里{?国家 wdt:P30 wd:Q46.?country p:P31 ?country_instance_of_statement .?country_instance_of_statement ps:P31 wd:Q6256.过滤器不存在 {?country_instance_of_statement pq:P582 ?endTime }SERVICE wikibase:label { bd:serviceParam wikibase:language"[AUTO_LANGUAGE],en".}}按 ?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%20%20%3Fcountry_instance%20%20%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

I am using the following query against wikidata;

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

where P30 is continent; Q46 is Europe; P31 is Instance Of and Q6256 is country;

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

Yet this query only returns 15 countries of Europe. For instance Sweden is not returned even though Sweden appears to match the query at https://www.wikidata.org/wiki/Q34

So even though the query seems to be correct yet it is missing out many countries. Any ideas on how to resolve this?

While comparing the two entries; one for Germany/Sweden (which do not show up) and Norway which does show up, the difference I could find was that Germany/Sweden has a preferred rank for Sovereign State while just a normal rank for Country. This could be a reason where the WHERE clause decides to only show the preferred rank if it exists; and skip the remaining statements. If this be the case and I suspect it is; I wonder if there is a way to override the behavior of the query engine to search through all statements with either a preferred rank or a normal rank.

解决方案

I am getting a better selection of countries when going around the truthy's by using statements. The statements are able to pull out all the statements even those with normal ranks.

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

I still have a few extra countries showing up; such as German Empire. But I think that's a different problem to fix.

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

Note that country_instance_of_statement captures all the statements irrespective of rank. And once I have those than I use 'ps:P31 wd:Q6256' to pull out those that have country ("wd:Q6256") as the object.

I have added in suggestions from @AKSW above.

And for those who want another approach using end time for country, this is the 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

这篇关于wikidata 查询遗漏了欧洲国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆