sparql查询未返回所需的输出
这是我的sparql查询,用于获取包含该国家的某些属性的所有国家名称sparql查询未返回所需的输出,sparql,dbpedia,Sparql,Dbpedia,这是我的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
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
但问题是,有些国家失踪了,比如“瑞士”。你进入这个页面,你会看到它的类型是country。你也不会发现确切的“奥地利”而不是“奥地利帝国”。为什么?有一个名为“奥地利”的实体,它是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
),但可以选择。。