I have a list of places in the UK. I want to get their latitude and longitude information from the http://dbpedia.org. I have just started to learn SPARQL, and I am not very familiar with the DBpedia. Currently, I am trying to retrieve at least one place, but so far no success. If I manage to get one place, then I will try to get all the places.
The list of places are like the following:
Llandysul
Rostrevor
Lee on the Solent
.
.
.
What I want to get is The place name, Latitude, Longitude. How can achieve this with the SPARQL?
I have tried the following query on http://dbpedia.org/sparql getting at least the information of one place (Llandysul) but even this did not work.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT DISTINCT ?place ?lat ?lng
WHERE {
?place a dbo:Place.
?place rdfs:label "Llandysul".
?place geo:lat ?lat .
?place geo:long ?lng .
}
What am I doing wrong? How can get the information of one place initially, and in the next step information of all place inside a list? Furthermore, if I could add a condition to make sure the place belongs to the UK, that would be great.
Many thanks.
I think this query will get what you want, but note that you must have the correct label; there are no partial matches (so "Lee on the Solent"@en
won't get you "Lee-on-the-Solent"@en
) --
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT DISTINCT ?place ?label ?lat ?lng
WHERE {
?place a dbo:Place .
?place rdfs:label ?label
FILTER ( ?label IN ( "Llandysul"@en,
"Rostrevor"@en,
"Lee-on-the-Solent"@en
) ) .
?place geo:lat ?lat .
?place geo:long ?lng .
}
As @JoshuaTaylor suggests, you could also use this query variant (results) --
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT DISTINCT ?place ?label ?lat ?lng
WHERE {
?place a dbo:Place .
?place rdfs:label ?label
VALUES ?label { "Llandysul"@en
"Rostrevor"@en
"Lee-on-the-Solent"@en} .
?place geo:lat ?lat .
?place geo:long ?lng .
}
There shouldn't be much difference between the two; perhaps a bit faster with the second.