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

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.

Related

Sparql in combination with DBpedia

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

My SPARQL query doesn't work at all

I am currently trying to run my query but I keep getting the error that in line 0 the parentheses are not balanced at '}'
I have checked my whole code multiple times, but I don't seem to get it fixed. I am currently using the dbpedia endpoint.
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/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?country ?government ?population
WHERE{ ?country dct:subject <http://dbpedia.org/resource>/Category:Countries_in_Europe> ;
rdfs:label ?country;
dbo:government ?government.
?government rdfs:label ?government.
?population rdfs:subClassOf* dbo:PopulatedPlace
rdf:type dbpedia-owl:Country;
rdfs:label ?country ;
prop:populationEstimate ?population .
FILTER (?population < 3000000) .
FILTER ( lang(?country) AND (lang(?(government = 'en')
}
Three rows in the graph should be shown, First with the country as a title, second with the governmenttypes of the countries as a title and the 3rd should be a row with the population descending from the total of 3000000.
Thanks alot in advance for helping me out!
You have multiple errors in this query.
Several things that pop out at me.
Thing 1 --
?government rdfs:label ?government.
You've got several similar ?subject ?predicate ?subject constructions.
Thing 2 --
?population rdfs:subClassOf* dbo:PopulatedPlace
rdf:type dbpedia-owl:Country;
I think you need a semicolon after dbo:PopulatedPlace
Thing 3 --
FILTER ( lang(?country) AND (lang(?(government = 'en')
That FILTER breaks syntax several ways. I think this will do what you intend --
FILTER ( lang(?country) = 'en') .
FILTER ( lang(?government) = 'en') .
Thing 4 --
<http://dbpedia.org/resource>/Category:Countries_in_Europe>
You've got an extra > in mid-string.
Thing 5 --
dbpedia-owl:Country
I think that should be dbo:Country
Thing 6 --
prop:populationEstimate
I think that should be dbp:populationEstimate
There are MANY more issues... I am not sure you're really trying.

How to get dct:subjects for all entities using SPARQL

I am using the following query
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?subject WHERE {
?concept rdfs:label 'Exoskeleton'#en ;
^dct:subject ?subject .
}
ORDER BY ?subject
This doesn't give me any results. However, the rdfs:label exists. (See http://dbpedia.org/page/Exoskeleton.)
On querying with a different label, it works :
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?subject WHERE {
?concept rdfs:label 'Machine learning'#en ;
^dct:subject ?subject .
}
ORDER BY ?subject
The above query works and gives me the results. (See http://dbpedia.org/page/Machine_learning.)
What do I change, such that the first query works too?
The dct:subject predicate is used between a page and a category it belongs to. So, your second query is giving you results that are in Category:Machine learning. But since there is no Category:Exoskeleton, your first query gives you no results. This also means the two pages you liked to are irrelevant to your queries.
I don't know how to change the first query so that it works, because I don't understand what would "working" entail.
Devil is in the details:
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?concept WHERE {
?concept rdfs:label 'Machine learning'#en.
}
ORDER BY ?concept
Returns two results:
http://dbpedia.org/resource/Category:Machine_learning
http://dbpedia.org/resource/Machine_learning
While Exoskeleton has no corresponding concept:
http://dbpedia.org/resource/Exoskeleton
Thus your inverse property path finds resources under a http://dbpedia.org/resource/Category:Machine_learning concept but not under a http://dbpedia.org/resource/Machine_learning or http://dbpedia.org/resource/Exoskeleton pages.
If you drop the inverse modifier,
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?subject WHERE {
?concept rdfs:label 'Exoskeleton'#en ;
dct:subject ?subject .
}
ORDER BY ?subject
Will return the categories (subject) for the concepts under a given label.

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

How to properly use SPARQL OPTIONAL to retrieve attributes for a resource that may exist?

I'm trying to use a SPARQL query to retrieve information about a DBpedia resource (a Person). I'd like to use the same query to retrieve data about any Person by parameterizing the resource URI. Since some attributes may not exist for a particular resource, I'm making use of the OPTIONAL statement. Here is my query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?label ?abstract ?placeOfBirth
?birthPlace ?birthDate ?deathDate ?page ?thumbnail
WHERE {
<http://dbpedia.org/resource/Neil_Simon> rdfs:label ?label ;
dbo:abstract ?abstract ;
foaf:page ?page .
OPTIONAL {
<http://dbpedia.org/resource/Neil_Simon> dbpprop:placeOfBirth ?placeOfBirth ;
dbpprop:birthPlace ?birthPlace ;
dbo:birthDate ?birthDate ;
dbo:deathdate ?deathDate ;
dbo:thumbnail ?thumbnail .
}
FILTER (LANG(?label) = 'en')
FILTER (LANG(?abstract) = 'en')
}
LIMIT 1
I've left everything except label, abstract and page in OPTIONAL, since if I use the same query for another person, they may not have those properties. The problem is, none of those optional attributes are showing up in the results. In Neil Simon's case, you can see that there are values for birthDate, birthPlace and thumbnail: http://dbpedia.org/resource/Neil_Simon. However, those values don't show up when I run the query: DBpedia SPARQL query. What am I doing wrong, and how can I optionally retrieve those properties?
Although you have used an OPTIONAL construct the map pattern itself needs all the attributes within to match. So only if you have birthPlace, birthDate, deathDate and thumbnail the inner optional construct is satisfied
I would suggest breaking the OPTIONAL construct up into multiple OPTIONAL constructs.