0
votes

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?

1
what have you done so far? I mean, this is one of the most simple queries. - UninformedUser
here: select * { <http://dbpedia.org/resource/Madrid> geo:lat ?lat ; geo:long ?long } - so does this help you, what do you do if you need something else? - UninformedUser
@UninformedUser That's just what I need. Just one more thing, how would be the query to get the coordinates by the entity name in case a dbpedia entry is not retrieved? - Luiscri
select * { ?s rdfs:label "Madrid"@en ; geo:lat ?lat ; geo:long ?long } - main disadvantages: 1) it has to be exact match and more important 2) multiple entities can have the same label. That why with URIs you'd have a unique identifier of the entity - UninformedUser
Thank you very much. Just one more thing: I'm tryng to replicate this functionality with the sparql query editor of Babelfy [babelnet.org/sparql/]. However, I don't know what should I put after they entry link. Do you know how to get the coordinates from a babelnet entry, for example, the one I posted on the question? By the way, if you want post your answers and I will select it as correct one. Thanks for your help - Luiscri

1 Answers

0
votes

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.