Reputation: 1037
I'm performing entity linking from a Python script from babelfy endpoint. When it is performed, I have an entity with two, one or none entries to a knowledge base: babelnet and 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. 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.
For example, given this real output, how should be the SPARQL query to get the coordinates?
Upvotes: 0
Views: 614
Reputation: 11067
You want the geo.lat
and geo.long
entries from the dbpedia entry.
A simple sparql to get those would be
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. The specs for geo
can be found here: 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.
If you wanted to apply a filter on the label name (i.e. to enact a search for something specific), that would be done by adding an additional filter on ?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:
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.
Upvotes: 1