Sparql in combination with DBpedia - sparql

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.
}

Related

SPARQL DBpedia get properties of a person knowing their name

new to SPARQL. Trying to figure out why I get different results on these two queries. It's based on this other question, where I'm trying to match properties to a name of a person. For example, I'm curious to know the birthday of J.K. Rowling, without knowing her URI directly. Here's the code from the link above:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "Car"#en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
compared to the query I'd like with J.K.:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE
{
?item rdfs:label ?itemLabel .
FILTER ( ?itemLabel = "J.K. Rowling"#en ) .
?item dbo:abstract ?itemDescription .
FILTER (lang(?itemDescription) = 'en')
}
ORDER BY ?itemLabel
The first one works fine, however, when I replace "Car" with "J.K. Rowling" as in the second, nothing is returned (her URI is return if I remove the dbo:abstract line and the filter line for it). J.K. Rowling does have a dbo:abstract in English. I'm not sure why it works for one and not the other. The only thing I can see that that 'Car' is a 'Thing', while J.K. is a 'person'

Simple SPARQL Query

I am working from this example, and I want to archieve the same, however with a different topic - Climate change
All i need to output is the abstract from this page: http://dbpedia.org/page/Climate_change
PREFIX dbp-res: <http://dbpedia.org/resource/>
PREFIX dbp-ont: <http://dbpedia.org/ontology/>
PREFIX dbp-prop: <http://dbpedia.org/property/>
SELECT *
WHERE
{
?Resource a dbp-ont:Agent .
?Resource dbp-ont:abstract ?Description .
?Resource rdfs:label ?Label .
FILTER( STR(?Label) = 'Climate_change' )
FILTER (langMatches(lang(?Description),'en'))
FILTER (langMatches(lang(?Label),'en'))
}
The problem seems to be the Agent, but I have no clue, as to what to replace it with.
My query

Why is this sparql query not returning any rows on dbpedia?

This is my query below, querying the country names with a certain minimum population, executing on http://dbpedia.org/sparql.
even though i change the population variable to a tiny amount. there are no rows being returned. why?
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE {
?country a type:LandlockedCountries ;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 15000000 && langMatches(lang(?country_name), "en")) .
} ORDER BY DESC(?population)
Because there is no class http://dbpedia.org/class/yago/LandlockedCountries in DBpedia - I don't know why you think that there is such a class?
There is a Wikipedia category Landlocked_countries, thus, the URI would be http://dbpedia.org/resource/Category:Landlocked_countries and the property that relates resources to a category is http://purl.org/dc/terms/subject:
PREFIX prop: <http://dbpedia.org/property/>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT *
WHERE {
?country dct:subject dbc:Landlocked_countries ;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 15000000 && langMatches(lang(?country_name), "en")) .
} ORDER BY DESC(?population)
In general, "debugging" a SPARQL query can be done by starting with just a single triple pattern and checking if this returns the expected resp. any result.

Retrieve information about all european countries

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?).

SPARQL query does not give all the results that are on dbpedia

I'm executing this query in http://dbpedia.org/snorql/:
Query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE {
?country a type:LandlockedCountries ;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
}
The query looks for all land looked countries.
I don't understand why in the results there are not some countries which are classified on
"/dbpedia.org/class/yago/LandlockedCountries". For example, Paraguay (/dbpedia.org/page/ParaguAy) is classified but does not appear in the query result set. Can somebody explain me why?
Unfortunately, there are a small number of landlocked countries that do not have values for at least one of the country_name and populationEstimate properties. This is why they will not be returned in your query. If you run the following query, those countries will come up (those two attributes are set as OPTIONAL).
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country ?country_name ?population
WHERE {
?country a type:LandlockedCountries .
OPTIONAL {?country rdfs:label ?country_name Filter(lang(?country_name) = 'en')} .
OPTIONAL {?country prop:populationEstimate ?population} .
}
run query
For (slightly) better results, since some countries seem to be duplicated with erroneous capitalization (e.g. ParaguAy and Paraguay), the following query uses ?country dcterms:subject category:Landlocked_countries instead of the yago class.
run query