SPARQL:精确 rdfs:label 查询产生不一致的结果
SPARQL: Exact rdfs:label query yields inconsistent results
我正在尝试通过使用 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 .
}
returns
:Barcelona :Spain 41.3833 2.18333 1604555 "101.4"^^dbpedia:datatype/squareKilometre 12.0
但与行相同的块:
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 数据远非同质的,因此,您必须确保您的查询真正适合数据。例如,Bilbao 的 DBpedia 资源不属于 class dbo:City
:
SELECT * { dbr:Bilbao a ?cls }
其中属于classes
+------------------------------------------------------------+
| cls |
+------------------------------------------------------------+
| http://www.wikidata.org/entity/Q486972 |
| http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing |
| http://www.w3.org/2002/07/owl#Thing |
| 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 |
| ... |
+------------------------------------------------------------+
属性也是如此,您必须确保资源的所有属性都存在。如果不能这样做,请将三重模式包装到 OPTIONAL
子句中。请注意,由于左连接执行,此查询可能更昂贵。
我正在尝试通过使用 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 .
}
returns
:Barcelona :Spain 41.3833 2.18333 1604555 "101.4"^^dbpedia:datatype/squareKilometre 12.0
但与行相同的块:
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 数据远非同质的,因此,您必须确保您的查询真正适合数据。例如,Bilbao 的 DBpedia 资源不属于 class dbo:City
:
SELECT * { dbr:Bilbao a ?cls }
其中属于classes
+------------------------------------------------------------+
| cls |
+------------------------------------------------------------+
| http://www.wikidata.org/entity/Q486972 |
| http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing |
| http://www.w3.org/2002/07/owl#Thing |
| 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 |
| ... |
+------------------------------------------------------------+
属性也是如此,您必须确保资源的所有属性都存在。如果不能这样做,请将三重模式包装到 OPTIONAL
子句中。请注意,由于左连接执行,此查询可能更昂贵。