SPARQL - get list of places in one country - sparql

I'm new to SPARQL and would like some help in my learning.
I want to get latitude and longitude of several places (neighborhoods, cities, states, regions, rivers, monuments, ..) of my country: Brazil.
I tried:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?s a dbo:Place .
?s geo:lat ?lat .
?s geo:long ?long .
?s a ?type .
?s a ?city .
?s rdfs:label "Rio de Janeiro"#en.
}
limit 10
I don't want to restrict my query to just "cities". I want to search for places by various attributes: "city", "river", "village", "mountain", "monuments", "hill", "island", "valley", "point", "peak" ...
Furthermore, I am not restricting the country ...
Anybody can help me?

Your query looks like the one in Get Place categories from DBpedia using SPARQL.
As it stands, your query is not limited to cities - it is just limited to dbo:Places that have the English name (label) "Rio de Janeiro". ?city is a variable; its name doesn't do anything special.
If you want any place, just remove the above mentioned triple patterns.
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?s a dbo:Place .
?s geo:lat ?lat .
?s geo:long ?long .
?s a ?type .
}
limit 10
This gets you 10 places with latitude and longitude and another class. You could browse DBpedia to see what kinds of places there are, decide whether you need dbo:Location_(feature) too and try subclasses of Place, Location too (as per DBpedia, getting the direct or indirect types of Place). To filter for country, you could add to your query
?s dbo:country <http://dbpedia.org/resource/Brazil> .
But not every place will have an explicit link to the country like this. You'll have to see what properties can help out with linking a place to its country.

Related

SPARQL query to find "notable" people

I am using live Dbpedia (http://dbpedia-live.openlinksw.com/sparql/) to get basic details of notable people. My query is:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?x0 ?name ?dob WHERE {
?x0 rdf:type foaf:Person.
?x0 rdfs:label ?name.
?x0 dbpedia-owl:birthDate ?dob.
FILTER REGEX(?name,"^[A-Z]","i").
} LIMIT 200
This works and I use LIMIT 200 to limit the output to a small number of people. My problem is the 200 people are random, and I want some way of measuring 'notability' such that I return 200 notable people, rather than 200 random people. There are over 500,000 people in Dbpedia.
My question is, how can I measure 'notability' and limit the query to return notable people only? I realize there is no 'notability' property and it is very subjective. I am happy to use any indirect or approximate measure such as number of links or number of references. But I don't know how to do this.
Edit : As a result of the helpful comments I improved the query to include page ranks:
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX vrank:<http://purl.org/voc/vrank#>
SELECT DISTINCT ?s ?name2 ?dob ?v
FROM <http://dbpedia.org>
FROM <http://people.aifb.kit.edu/ath/#DBpedia_PageRank>
WHERE {
?s rdf:type foaf:Person.
?s rdfs:label ?name.
?s dbo:birthDate ?dob.
?s vrank:hasRank/vrank:rankValue ?v.
FILTER REGEX(?name,"^[A-Z].*").
BIND (str(?name) AS ?name2)
} ORDER BY DESC(?v) LIMIT 100
The problem now is there are lots of duplicates, even though I am using DISTINCT.

How to query dbpedia.org with sparql

I'm very new in OpenData and try to write a query in SPARQL.
My goal is to get data for following set of criteria:
- Category: Home_automation
- select all items from type "Thing"
- with at least one entry in "is Product of"
- that have a picture-url with a German description
I tried the following:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
cat:Home_automation skos:broader ?x
}
But now I don't know how to add the other filters to the where clause.
I tried to user broader:... to get the items, but I think that was the wrong direction.
I tested the queries with: https://dbpedia.org/sparql
The result should be:
| (label) | (url)
|--------------------------|-----------------------------------
|"Kurzzeitwecker"#de | urls to the picture of the device
|"Staubsauger"#de | -||-
|"Waschmaschine"#de | -||-
|"Geschirrspülmaschine"#de | -||-
Does anyone have some tips please?
UPDATE: new query:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?s ?label WHERE {
?s ?p cat:Home_automation .
?s rdf:type owl:Thing .
?s rdfs:label ?label
FILTER (LANG(?label)='de')
}
order by ?p
It is not clear what you want. You must first know what exact related information dbpedia contains and how they are structured.
However, you can try discovering what types of relationships cat:Home_automation is involved in, thus, you may know better what you want.
I suggest starting by generic queries, to specify how cat:Home_automation occurs in dbpedia, then, you might be able to go more specific, and pose further queries.
A query to list triples where cat:Home_automation is an subject:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?p ?o WHERE {
cat:Home_automation ?p ?o
}
order by ?p
A query to list triples where cat:Home_automation is an object:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?s ?p WHERE {
?s ?p cat:Home_automation
}
order by ?p
check the results, see what is interesting for you, and then continue with further queries.

Not able to get Indian cities abstract from Sparql

I am trying to get abstract using Sqarql with dbpedia datasets.
When I am running the following query on Virtuoso,
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ rdfs:label ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
VALUES ?name { "London"#en }
}
LIMIT 10
I am getting the result, however if I modify the name to say 'Gokarna' which is a south indian tourist spot, I am not getting any data. However I do see the resource page online on dbpedia for Gokarna(http://dbpedia.org/page/Gokarna,_India). What am I doing wrong? I need to get similar data for close to 800 indian places.
When you use values, you'd get only those that exactly match your string. For Gokarna, that would work for #de, #it, #fr, but not for #en, as there the label is different, as you can see also from the previous answer.
I would suggest to use contains, instead of values:
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ rdfs:label ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
FILTER langMatches(lang(?name),"en")
FILTER CONTAINS (?name, "Gokarna" )
}
LIMIT 10
I am not that experience with Sqarql but as much i can see in your code and checked with dbpedia library...
it is not just Gokarna. it is "Gokarna,_India".
This should work..
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ rdfs:label ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
VALUES ?name { "Gokarna,_India"#en }
}
LIMIT 10
If you look through the DBpedia page for Gokarna, India that you linked to, you'll notice that its rdfs:label is "Gokarna, India". But its foaf:name is just "Gokarna". This would mean you should modify your query to:
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?abstract WHERE {
[ foaf:name ?name
; dbpedia-owl:abstract ?abstract
] .
FILTER langMatches(lang(?abstract),"en")
VALUES ?name { "Gokarna"#en }
}
LIMIT 10
Though this will return other Gokarnas too: Gokarna, Nepal, Gokarna, Bangladesh and Gokarna (film). If you want to remove these, you will have to figure out another filter (possibly dbo:country dbr:India).

Dbpedia/sparql: get population & lat/lng of all cities/towns/villages in UK

I'm entering the following query at http://dbpedia.org/sparql:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?s ?name ?value ?lat ?lng
WHERE {
?s a <http://dbpedia.org/ontology/PopulatedPlace> .
?s <http://dbpedia.org/property/name> ?name .
?s <http://dbpedia.org/property/populationTotal> ?value .
FILTER (?lng > -8.64 AND ?lng < 2.1 AND ?lat < 61.1 AND ?lat > 49.35 )
?s geo:lat ?lat .
?s geo:long ?lng .
}
(The bounding box is intended to be for the UK, the other option is to add <http://dbpedia.org/ontology/country> <http://dbpedia.org/resource/United_Kingdom> ., but there's a possibility that some places might not have been tagged with UK as the country).
The problem is that it doesn't seem to be pulling back many places (around 290).
Swapping population for populationTotal gives 1588 places, and I can't figure out (semantically) which one should be used.
Is this a limitation with the underlying data, or is there something that could be improved in the way I'm formulating the query?
Note: this question is mainly academic now as I got the info from http://download.geonames.org/export/dump/GB.zip, but I'd much prefer to use open data and the semantic web, so posting up this question to see if there was something I was missing, or to find out if there is a shortcoming in how the data is being scraped from Wikipedia and whether I can muck in.
Your query is only returning locations that have a value for populationTotal. For example, if Town A has "10,000" for populationTotal in the database, and Town B has NULL, only Town A will be returned.
If you want to return all locations in the UK, then you need to specify population as an optional parameter. This query will show you all the locations, as well as the populations for the ones that have that data.
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?s ?name ?value ?lat ?lng
WHERE {
?s a <http://dbpedia.org/ontology/PopulatedPlace> .
?s <http://dbpedia.org/property/name> ?name .
OPTIONAL { ?s <http://dbpedia.org/property/populationTotal> ?value . }
FILTER (?lng > -8.64 AND ?lng < 2.1 AND ?lat < 61.1 AND ?lat > 49.35 )
?s geo:lat ?lat .
?s geo:long ?lng .
}

dbpedia fetch entitites in language other than english

I'm trying to extract entity dictionary contains person name etc. from dbpedia using sparql.
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?name
WHERE {
?person a owl:Person .
?person dbpprop:name ?name . FILTER(lang(?name) = "en")
}
The query above did succeed, but when I change the language name to fr, there is nothing to fetch.
How can I fetch names in other languages?
Moreover, why can't I filter language using query below?
SELECT ?name
WHERE {
?person a owl:Person .
?person dbpprop:language "English"
?person dbpprop:name ?name .
}
// this query returns nothing
I tried to fetch all languages using
SELECT DISTINCT ?lanName
WHERE {
?person a owl:Person .
?person dbpprop:language ?lanName .
}
and the result set contains English.
You need to filter based on the language of the value of the property. Not every property will have values in different languages, but some properties will. It seems, from your example, that dbpprop:name doesn't have values in every language. You may find more values in other languages if you look on the other language specific DBpediae.
However, for something like a name, you'll probably get multi-language results if you use the rdfs:label property. For instance, to get the names of Barack Obama, Daniel Webster, and Johnny Cash in Russian, you could do:
select ?label {
values ?person { dbpedia:Johnny_Cash dbpedia:Barack_Obama dbpedia:Daniel_Webster }
?person rdfs:label ?label .
filter langMatches(lang(?label),"ru")
}
SPARQL results
As an aside, note the use of langMatches rather than equality for matching language tags. This is usually a better approach, because it will correctly handle the different language tags within a language For example (from the SPARQL specification), you can find both of the French literals:
"Cette Série des Années Soixante-dix"#fr .
"Cette Série des Années Septante"#fr-BE .
with langMatches(lang(?title),"fr"), but only the first one with lang(?title) = "fr".
You are looking for rdfs:label for a name, of course all the names are English, you are looking at the English dbpedia.
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
?person a owl:Person .
?person rdfs:label ?name .
FILTER(lang(?name) = "fr")
}
Again, for the second one, if you replace the name with the rdfs: label you can have:
PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
?person a owl:Person .
?person rdfs:label ?name .
?person dbpprop:language <http://dbpedia.org/resource/English_language>.
}