[英]sparql query is not returning desired output
這是我的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/瑞士此頁面時,您會看到它的類型是國家。 您也找不到確切的“奧地利”,而是“ Austrian_Empire”。 為什么? 有一個名為“奧地利”的實體,它是dbo:Country類型。
瑞士似乎沒有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
)的實體,例如Switzerland Cinema of Switzerland 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.