Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.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
Python SPARQL:Exact rdfs:label查询产生不一致的结果_Python_Sparql_Wikipedia_Dbpedia - Fatal编程技术网

Python SPARQL:Exact rdfs:label查询产生不一致的结果

Python SPARQL:Exact rdfs:label查询产生不一致的结果,python,sparql,wikipedia,dbpedia,Python,Sparql,Wikipedia,Dbpedia,我试图通过使用SPARQL进行显式搜索,从特定城市获取人口、纬度、经度等数据。下面的代码适用于巴塞罗那这样的城市,但对于毕尔巴鄂这样的城市不会产生任何结果。因此,以下是: SELECT Distinct ?city, ?country, ?lat, ?lon, ?population, ?area, ?elevation WHERE { ?city rdf:type <http://dbpedia.org/ontology/City> . ?city <http://

我试图通过使用SPARQL进行显式搜索,从特定城市获取人口、纬度、经度等数据。下面的代码适用于巴塞罗那这样的城市,但对于毕尔巴鄂这样的城市不会产生任何结果。因此,以下是:

SELECT Distinct ?city, ?country, ?lat, ?lon, ?population, ?area, ?elevation WHERE {
  ?city rdf:type <http://dbpedia.org/ontology/City> .
  ?city  <http://dbpedia.org/ontology/country> ?country .
  ?city  <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .
  ?city  <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lon .
  ?city  <http://dbpedia.org/ontology/populationTotal> ?population .
  ?city  <http://dbpedia.org/ontology/PopulatedPlace/areaTotal> ?area .
  ?city  <http://dbpedia.org/ontology/elevation> ?elevation;
rdfs:label "Barcelona"@en .
}
但与该行相同的块:

rdfs:label "Bilbao"@en .
空着回来。还有巴伦西亚、波哥大、比纳斯科等城市的失败。。。如果可能的话,我想在没有过滤器的情况下执行搜索。我得到了以下过滤查询的混合结果:

SELECT ?city, ?country, ?lat, ?lon, ?population, ?area, ?elevation, ?label  WHERE {
  ?city rdf:type <http://dbpedia.org/ontology/City> .
  ?city  <http://dbpedia.org/ontology/country> ?country .
  ?city  <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .
  ?city  <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lon .
  ?city  <http://dbpedia.org/ontology/populationTotal> ?population .
  ?city  <http://dbpedia.org/ontology/PopulatedPlace/areaTotal> ?area .
  ?city  <http://dbpedia.org/ontology/elevation> ?elevation;
rdfs:label ?label .
FILTER contains ( ?label, "Bilbao")
FILTER langMatches(lang(?label),'en')
}
LIMIT 100

任何想法都将不胜感激。

Dbpedia数据远不是同质的,因此,您必须确保您的查询真正符合数据。例如,毕尔巴鄂的DBpedia资源不属于dbo:City类:

选择*{dbr:Bilbao a?cls} 其中,它属于类

+------------------------------+ |cls| +------------------------------+ | http://www.wikidata.org/entity/Q486972 | | http://www.w3.org/2003/01/geo/wgs84_posSpatialThing | | http://www.w3.org/2002/07/owlThing | | http://umbel.org/umbel/rc/Village | | http://umbel.org/umbel/rc/PopulatedPlace | | http://umbel.org/umbel/rc/Location_Underspecified | | http://schema.org/Place | | http://dbpedia.org/ontology/Settlement | | http://dbpedia.org/ontology/PopulatedPlace | | http://dbpedia.org/ontology/Place | | http://dbpedia.org/ontology/Location | | http://dbpedia.org/class/yago/YagoPermanentlyLocatedEntity | | http://dbpedia.org/class/yago/YagoLegalActorGeo | | http://dbpedia.org/class/yago/YagoGeoEntity | | ... | +------------------------------+
属性也是如此,您必须确保资源的所有属性都存在。如果不能这样做,请将三重模式包装到可选子句中。注意,由于执行左连接,此查询可能会更昂贵。

谢谢@aksw。卓越的洞察力。我将深入探讨dbo:城市/地点/位置问题。
SELECT ?city, ?country, ?lat, ?lon, ?population, ?area, ?elevation, ?label  WHERE {
  ?city rdf:type <http://dbpedia.org/ontology/City> .
  ?city  <http://dbpedia.org/ontology/country> ?country .
  ?city  <http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?lat .
  ?city  <http://www.w3.org/2003/01/geo/wgs84_pos#long> ?lon .
  ?city  <http://dbpedia.org/ontology/populationTotal> ?population .
  ?city  <http://dbpedia.org/ontology/PopulatedPlace/areaTotal> ?area .
  ?city  <http://dbpedia.org/ontology/elevation> ?elevation;
rdfs:label ?label .
FILTER contains ( ?label, "Bilbao")
FILTER langMatches(lang(?label),'en')
}
LIMIT 100