Geolocation 试图使用DBPEDIA计算出一个区域内超过2000000人的所有城市
嗨,我正在尝试定位一个区域内的所有城市,那里的人口超过一个临界值 这个SPARQL查询工作得很好Geolocation 试图使用DBPEDIA计算出一个区域内超过2000000人的所有城市,geolocation,sparql,geospatial,dbpedia,Geolocation,Sparql,Geospatial,Dbpedia,嗨,我正在尝试定位一个区域内的所有城市,那里的人口超过一个临界值 这个SPARQL查询工作得很好 SELECT DISTINCT * WHERE { ?city rdfs:label ?citylabel ; dbpedia-owl:country ?country ; dbpedia-owl:populationTotal ?population . { ?city rdf:type dbped
SELECT DISTINCT *
WHERE {
?city rdfs:label ?citylabel ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?population .
{ ?city rdf:type dbpedia-owl:City }
UNION
{ ?city rdf:type dbpedia-owl:Settlement }
UNION
{ ?city rdf:type dbpedia-owl:Town }
?city geo:geometry ?geo .
?country rdfs:label ?countrylabel .
FILTER (
lang(?countrylabel) = 'en' &&
bif:st_intersects(?geo, bif:st_point(2.0, 50.0), 200) &&
?population > 1000000
)
}
给我坐标(2,50)附近200公里的点-靠近巴黎
然而,当我将thrshold更改为2000000时,结果似乎是随机的
SELECT DISTINCT *
WHERE {
?city rdfs:label ?citylabel ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?population .
{ ?city rdf:type dbpedia-owl:City }
UNION
{ ?city rdf:type dbpedia-owl:Settlement }
UNION
{ ?city rdf:type dbpedia-owl:Town }
?city geo:geometry ?geo .
?country rdfs:label ?countrylabel .
FILTER (
lang(?countrylabel) = 'en' &&
bif:st_intersects(?geo, bif:st_point(2.0, 50.0), 200) && ?population > 2000000
)
}
我做错了什么
编辑
我原来的帖子上少了一些信息。
1) 我正在尝试在我的个人服务器上运行查询。在DBPedia.org上,查询似乎运行良好。
2) 我遵循这个链接来启用空间查询。总结一下,我已经运行了DB.DBA.RDF_GEO_FILL()来创建几何体属性/索引,后跟检查点。我想没有别的办法了。
3) 下面的查询更清楚地说明了结果的随机性:
SELECT DISTINCT ?countrylabel
(group_concat(distinct ?citylabel ; separator = "||")
AS ?city_set)
WHERE {
?city rdfs:label ?citylabel ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?population .
# City is a Town or Settlement or City
{ ?city rdf:type dbpedia-owl:City }
UNION
{ ?city rdf:type dbpedia-owl:Settlement }
UNION
{ ?city rdf:type dbpedia-owl:Town }
?city geo:geometry ?geo .
?country rdfs:label ?countrylabel .
FILTER (
lang(?countrylabel) = "en" &&
bif:st_intersects(?geo, bif:st_point(2.0, 48.0), 200) &&
?population > 2000000.0
)
}
正如你所见,回到巴黎。请注意,纬度是48.0
{"head": {
"link": [],
"vars": [
"countrylabel",
"city_set"
]
},
"results": {
"distinct": false,
"ordered": true,
"bindings": [
{
"countrylabel": {
"type": "literal",
"xml:lang": "en",
"value": "France"
},
"city_set": {
"type": "literal",
"value": "Paris"
}
}
]
}}
但是当我把纬度改为50时。一切都变了:
SELECT DISTINCT ?countrylabel
(group_concat(distinct ?citylabel ; separator = "||")
AS ?city_set)
WHERE {
?city rdfs:label ?citylabel ;
dbpedia-owl:country ?country ;
dbpedia-owl:populationTotal ?population .
# City is a Town or Settlement or City
{ ?city rdf:type dbpedia-owl:City }
UNION
{ ?city rdf:type dbpedia-owl:Settlement }
UNION
{ ?city rdf:type dbpedia-owl:Town }
?city geo:geometry ?geo .
?country rdfs:label ?countrylabel .
FILTER (
lang(?countrylabel) = "en" &&
bif:st_intersects(?geo, bif:st_point(2.0, 50.0), 200) &&
?population > 2000000.0
)
}
结果是疯狂的(!!!):
因此,我猜大师创建的索引有问题,但我不知道该怎么办。我不确定你说的结果“似乎是随机的”是什么意思。我不确定法国有多少地方的人口超过200万,但查询返回两个地方:巴黎和诺德。如果您稍微清理一下查询(例如,使用value简化联合,并使用属性路径正确处理?country变量(除非您想要country变量,在这种情况下保留它),并使用langMatches而不是lang(…)=…,并过滤城市标签的语言:
选择distinct*其中{
值?类型{dbpedia owl:City dbpedia owl:collection dbpedia owl:Town}
城市a型;
rdfs:标签?城市标签;
dbpedia owl:country/rdfs:label?countrylabel;
dbpedia-owl:populationTotal?人口;
几何?几何
过滤器(langMatches(lang(?countrylabel),'en')
&&langMatches(lang(?citylabel),'en')
&&bif:st_相交(?geo,bif:st_点(2.0,50.0),200)
&&?人口>200万)
}
什么意思?结果看起来是随机的?当我运行第二个查询时,我得到巴黎和诺德作为结果。(我不知道法国的哪些城市应该符合条件。)此外,您可以使用值简化
{city a type1}联合{city a type2}…
。您可以使用值?键入{dbpedia-owl:City-dbpedia-owl:Town-dbpedia-owl:collection}?城市a?类型
。在我看来,要干净得多。而且,你可能应该使用langMatches(lang(?countrylabel),'en')
而不是lang(?countrylabel)='en'
。好的,这可能是一个virtuoso版本的问题。当我从virtuoso 7.1切换到7.2时,一切似乎都正常。我将运行更多的测试。当我查询dbpedia.org端点时,结果非常好。问题出在我个人的virtuoso安装上。相同查询的结果是墨西哥的一个城市和其他地方韩国的r one。这是随机的。没有人口限制,一切都与dbpedia端点一样有效。@Fernandofereira我会检查是否需要做些什么来启用地理空间bif功能。是的,我会检查。无论如何,感谢您对查询的帮助。您的提示确实让它变得更好。我还会编辑原帖,让我的问题更清楚
{"head": {
"link": [],
"vars": [
"countrylabel",
"city_set"
]
},
"results": {
"distinct": false,
"ordered": true,
"bindings": [
{
"countrylabel": {
"type": "literal",
"xml:lang": "en",
"value": "Poland"
},
"city_set": {
"type": "literal",
"value": "Lublin Voivodeship||Voivodia de Lublin"
}
},
{
"countrylabel": {
"type": "literal",
"xml:lang": "en",
"value": "Mexico"
},
"city_set": {
"type": "literal",
"value": "Guanajuato"
}
},
{
"countrylabel": {
"type": "literal",
"xml:lang": "en",
"value": "United Kingdom"
},
"city_set": {
"type": "literal",
"value": "Inner London"
}
},
{
"countrylabel": {
"type": "literal",
"xml:lang": "en",
"value": "Nigeria"
},
"city_set": {
"type": "literal",
"value": "Kano (estado)||Kano State"
}
}
]
}
}