列出DBpedia的国家 [英] List countries from DBpedia
问题描述
尝试查询DBpedia以获取具有 dbo:longName
属性和列出的每个国家的首都的所有国家/地区的列表,但返回0个结果。无法看到查询出了什么问题。
Trying to query DBpedia for a list of all countries with the dbo:longName
property and the capital of each country listed but get 0 results returned. Can't see whats wrong with the query.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country ?capital
WHERE {
?country a dbo:longName ;
dbo:capital ?capital .
}
缺少什么?
推荐答案
您丢失了?country
的 rdf:type
的信息 dbo:Country
而不是 dbo:longName
。正确的查询应该是:
You are missing that ?country
has a rdf:type
of dbo:Country
and not dbo:longName
. The right query should be:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country ?capital
WHERE {
?x a dbo:Country.
?x dbo:longName ?country.
?x dbp:capital ?capital
}
更新
根据您的评论,您需要国家的URI及其首都。因此,您不需要 dbo:longName
,因为您不需要国家标签名称。您将选择实例:
Update
Based on your comment you want the URI's of the country and their capital. Therefore, you don't need dbo:longName
, because you don't want the country label name. You will select the instances:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country ?capital
WHERE {
?country a dbo:Country.
?country dbo:capital ?capital
}
请注意,结果将使已经灭绝的国家。如果要过滤已结束的国家/地区,则应使用以下命令获得此结果:
Note that results will bring countries that are extinct. If you want to filter countries that have ended, you should get this result with:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country ?capital
WHERE {
?country a dbo:Country.
?country dbo:capital ?capital.
FILTER NOT EXISTS { ?country dbo:dissolutionYear ?yearEnd }
}
这篇关于列出DBpedia的国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!