[英]Get lat and long coordinates from location name using dbpedia sparql
I'm performing entity linking from a Python script from babelfy endpoint .我正在执行来自babelfy endpoint的 Python 脚本的实体链接。 When it is performed, I have an entity with two, one or none entries to a knowledge base: babe.net and dbpedia.执行时,我有一个实体,其中包含两个、一个或没有知识库条目:babe.net 和 dbpedia。
Once I have this, I want to get the latitude and longitude coordinates of the entity place I have just received.一旦我有了这个,我想得到我刚刚收到的实体地点的经纬度坐标。 What is the best way to achieve this?实现这一目标的最佳方法是什么?
I have been reading some options and I think that a solid way of having this done is doing a Python request to dbpedia sparql endpoint .我一直在阅读一些选项,我认为完成此操作的可靠方法是向dbpedia sparql endpoint发出 Python 请求。 However I'm completely new to SPARQL and I don't know how I could, by giving the place name or more easily the entity entry, get those lat and long coordinates.但是,我是 SPARQL 的新手,我不知道如何通过提供地名或更轻松地输入实体条目来获取那些纬度和经度坐标。
For example, given this real output, how should be the SPARQL query to get the coordinates?例如,给定这个真实的 output,SPARQL 查询应该如何获取坐标?
You want the geo.lat
and geo.long
entries from the dbpedia entry.您需要 dbpedia 条目中的geo.lat
和geo.long
条目。
A simple sparql to get those would be一个简单的 sparql 来获得这些将是
select ?name ?lat ?long
where {
?s rdfs:label ?name.
?s geo:lat ?lat.
?s geo:long ?long.
}
You might have to fiddle about with including the appropriate PREFIX
details for rdfs
and geo
but reading around should sort that out.您可能需要为rdfs
和geo
添加适当的PREFIX
详细信息,但仔细阅读应该可以解决这个问题。 The specs for geo
can be found here: https://www.w3.org/2003/01/geo/#vocabulary geo
的规范可以在这里找到: https://www.w3.org/2003/01/geo/#vocabulary
Run as above, the endpoint should report all entities in dbpedia tagged with latitude and longitude details.如上运行,端点应报告 dbpedia 中标记有纬度和经度详细信息的所有实体。
If you wanted to apply a filter on the label name (ie to enact a search for something specific), that would be done by adding an additional filter on ?s rdfs:label "Madrid".
如果您想对 label 名称应用过滤器(即对特定内容进行搜索),可以通过在?s rdfs:label "Madrid".
for example.例如。
Similarly, if you wanted to query directly using the entity URI, then just replace references to the ?s
in the query with the specific URI you want, or add the line:同样,如果您想直接使用实体 URI 进行查询,则只需将查询中对?s
的引用替换为您想要的特定 URI,或添加以下行:
BIND (<http://dbpedia.org/resource/Madrid> AS ?s)
To set the ?s
variable to be something specific and retrieve the details of just that entry.将?s
变量设置为特定的内容并检索该条目的详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.