2015-10-04 29 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