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.
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
}
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.
Related
i want to display the countries with their net value/income or something similiar through accessing the data through DBPedia. and further insert them into an already created table.
Unfortunately i dont get any results with my code.
Try the following query to list the type of entities that has a dbp:income as a property. you will notice that dbo:Country is not the list, that's why the result you got was empty.
prefix dbp: <http://dbpedia.org/property/>
select distinct ?type
where {
?s a ?type.
?s dbp:income ?income
}
My suggestion is to use dbp:gdpNominal instead of the dbp:income property in your query :
prefix dbp: <http://dbpedia.org/property/>
prefix dbo: <http://dbpedia.org/ontology/>
select distinct ?country_name ?income
where {
?country a dbo:Country.
?country rdfs:label ?country_name. FILTER (lang(?country_name) = 'en')
?country dbp:gdpNominal ?income.
}
I am new to querying DBPedia using Sparql. I would like to find people related to a person X using DBPedia.
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpr: <http://dbpedia.org/resource/>
PREFIX dbpo: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?P
WHERE {dbpr:Chuck_Norris}
In case you want the people directly related to a person, then you need two triple patterns, one having the person as a subject and another as an object. Here is one way to construct such a query:
SELECT DISTINCT ?has ?of ?person
WHERE {
{?person a foaf:Person;
?of dbr:Chuck_Norris}
UNION
{?person a foaf:Person.
dbr:Chuck_Norris ?has ?person}
}
I'm using dbr: as this is a predefined prefix in DBpedia.
In some cases, you'll get different results if you query on http://live.dbpedia.org/sparql
Now, this query has a limitation. It will get you only relations to other DBpedia resources. Quite often there might be related persons asserted as literals. I don't know of an elegant way to get them, but one way would be to ask for a list of properties that are known to be used for person relations. Here is an example with a list with one value for dbp:spouse:
SELECT DISTINCT ?has ?of ?person
WHERE {
{?person a foaf:Person;
?of dbr:Chuck_Norris}
UNION
{?person a foaf:Person.
dbr:Chuck_Norris ?has ?person}
UNION
{values ?has {dbp:spouse}
dbr:Chuck_Norris ?has ?person .}
}
From http://live.dbpedia.org/sparql this will bring you additionally:
has | person
---------------------------------------------------------
http://dbpedia.org/property/spouse | "Dianne Holechek"#en
http://dbpedia.org/property/spouse | "Gena O'Kelley"#en
---------------------------------------------------------
In general asking for literals like that will bring you a lot of garbage results, which you can reduce using string filters.
What I want from my sparql query is to not only get a list of all the European countries, but I want all the info they have. For instance, their capital, currency, areaKM and so on. The end goal is to use the datasets I aquired in protege. The query I have tried looked like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX db: <http://dbpedia.org/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT DISTINCT ?country ?capital ?area ?currency ?wealth
WHERE {
?country rdf:type yago:EuropeanCountries;
dbo:capital ?capital;
dbp:areaKm ?area;
dbp:currencyCode ?currency;
dbp:gdpPppPerCapita ?wealth .
}
This seemed to work at first, but as of yesterday it won't anymore. So my question is, how do i get all european countries and their properties given by dbpedia using sparql.
Thanks in advance!
Since yesterday, DBpedia 2016-04 is loaded into http://dbpedia.org/sparql and as far as I can see, the YAGO data isn't loaded (yet?)
At least, this simplified query already doesn't return any result:
PREFIX yago: <http://dbpedia.org/class/yago/>
SELECT DISTINCT * WHERE {
?country a yago:EuropeanCountries
}
Alternative query using the DBpedia categories (and your YAGO type is more or less the same):
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT *
WHERE
{ ?country dct:subject <http://dbpedia.org/resource/Category:Countries_in_Europe> ;
dbo:capital ?capital
OPTIONAL
{ ?country dbp:areaKm ?area }
OPTIONAL
{ ?country dbp:currencyCode ?currency }
OPTIONAL
{ ?country dbp:gdpPppPerCapita ?wealth }
}
Note, that I put some properties into an OPTIONAL as at least for dbp:currencyCode and dbp:gdpPppPerCapita there is no data (anymore?).
I need to get all awarded movies on 80th Award Ceremony
I tried to write SPARQL query:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix dbpedia-owl: <http://dbpedia.org/ontology/>
prefix movie: <http://data.linkedmdb.org/resource/movie/>
prefix award: <http://data.linkedmdb.org/page/film_awards_ceremony/180/>
select distinct ?film ?award where {
{ ?film a movie:film.
?award a movie:film_awards_ceremony.
} union
{ ?film a dbpedia-owl:Film }
?film rdfs:label ?label .
}
But the result is full movies list.
I found the data I need also here: https://www.freebase.com/m/02pgky2
How to combine (union) these entities in a right way ?
If is not possible - How to get the result from freebase using SPARQL and dbpedia.org?
I want to query the American Physicsts and get the list of physicists. How can I do this?
The SPARQL you need would look like this ....
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT *
WHERE {
?s dcterms:subject category:American_physicists .
}
see results here
If you want the list with some extra predicates you need to join more triple patterns using the variable ?s. For instance, to retrieve the birthdate for each physicist ...
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbpedia: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?s dcterms:subject category:American_physicists .
?s dbpedia:birthDate ?bithdate .
}
results here