sparql查询未返回所需的输出

时间:2015-10-04 14:48:38

标签: 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 ?long.
}
ORDER BY ?country

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

1 个答案:

答案 0 :(得分: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

相关问题