2015-10-04 56 views
0

这是我的sparql查询来获取所有国家名称与该国家的一些财产。sparql查询没有返回所需的输出

SELECT distinct ?country ?capital ?currency ?lat ?long 
WHERE { 
    ?country rdf:type dbo:Country . 
    ?country dbo:capital ?capital . 
    ?country dbo:currency ?currency . 
?country geo:lat ?lat. 
?country geo:long ?long. 
} 
ORDER BY ?country 

但问题是,有些国家失踪,如“瑞士”。你去http://dbpedia.org/page/Switzerland这个页面,你会看到它的类型是国家。你也不会找到确切的“奥地利”而不是“奥地利_Empire”。为什么?有一个名为“奥地利”的实体,它是dbo:国家类型。

回答

2

瑞士似乎没有dbo:capital,这就是它未包含在查询结果中的原因。

如果你想获得甚至不具有的一些属性的效果,请使用OPTIONAL

SELECT distinct ?country ?capital ?currency ?lat ?long 
WHERE { 
    ?country rdf:type dbo:Country . 
    OPTIONAL 
    { 
    ?country dbo:capital ?capital . 
    ?country dbo:currency ?currency . 
    ?country geo:lat ?lat. 
    ?country geo:long ?long. 
    } 
} 
ORDER BY ?country 

虽然这个查询返回,即使实体不是国家(但出于某种原因是dbo:Country),如Cinema of Switzerland

+0

可选是要走的路。 – chile