我对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是国家;
然而,此查询仅返回欧洲的15个国家。例如瑞典似乎没有返回,尽管瑞典似乎与https://www.wikidata.org/wiki/Q34的查询相符
因此,即使查询似乎是正确的,但它却遗漏了许多国家。关于如何解决这个问题的任何想法?
在比较两个条目时;一个用于德国/瑞典(没有出现)和挪威确实出现,我可以发现的差异是德国/瑞典的主权国家优先级别,而国家的正常级别。这可能是WHERE子句决定仅显示首选排名(如果存在)的原因;并跳过其余的陈述。如果是这种情况,我怀疑它是;我想知道是否有办法覆盖查询引擎的行为,以搜索具有首选排名或正常排名的所有语句。
通过使用陈述来绕过真正的国家,我得到了更好的国家选择。这些陈述能够提取所有陈述,即使是那些排名正常的陈述。
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
我还有一些额外的国家出现;比如德意志帝国。但我认为这是一个不同的问题需要解决。
请注意,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