Irshad Khan
Irshad Khan

Reputation: 6046

Get all Cities of Country from DBpedia using SPARQL

I would like to get all Cities of India from DBpedia database.

I tried many stackoverflow solutions but till now i have not got my required output.

How to fetch all Cities of Country using SPARQL.

Upvotes: 2

Views: 3630

Answers (2)

Irshad Khan
Irshad Khan

Reputation: 6046

I got solution to get Cities of Country. For Example if we want to fetch cities of India then use dbr:India in your Query

SELECT DISTINCT ?placeName WHERE {
 ?placeName a yago:City108524735 ; dbo:country dbr:India
}

Thanks @AKSW for your help.

Upvotes: 1

UninformedUser
UninformedUser

Reputation: 8465

Might be (for sure) incomplete since data in DBpedia is based on mappings from Wikipedia (here only the infoboxes):

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?s WHERE {
 ?s a dbo:City ;
    dbo:country dbr:India
}

Or you can try to use the Wikipedia categories:

PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?s WHERE {
 ?s dct:subject/skos:broader* dbc:Cities_and_towns_in_India
}

Upvotes: 2

Related Questions