Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sparql查询未返回所需的输出_Sparql_Dbpedia - Fatal编程技术网

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

这是我的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

但问题是,有些国家失踪了,比如“瑞士”。你进入这个页面,你会看到它的类型是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
),但可以选择。