Simple SPARQL Query - sparql

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

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

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'

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.

Number of incoming link fo each DBpedia resource

I have the SPARQL DBpedia Query below:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vrank:<http://purl.org/voc/vrank#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT distinct ?Nom ?resource ?url (count( (?o) as ?nb))
WHERE{
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
?resource dbpedia-owl:wikiPageWikiLink ?o
?Nom <bif:contains> "Apple".
FILTER ( langMatches( lang(?Nom), "EN" )).
MINUS {?resource dbo:wikiPageRedirects|dbo:wikiPageDisambiguates ?dis}
}
Group By ?Nom ?resource ?url
I want to get the number of incoming links of each entitie within wikipedia. How can I proceed?
Thanks
First of all syntax:
you are missing a dot after ?o,
also it should be bif:contains, not <bif:contains>.
Next:
i ran this simpler query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vrank:<http://purl.org/voc/vrank#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT distinct ?Nom ?resource
WHERE{
?resource rdfs:label ?Nom.
?Nom bif:contains "Apple".
}
which produced a lot of results....
now i added this triple:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vrank:<http://purl.org/voc/vrank#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT distinct ?Nom ?resource
WHERE{
?resource rdfs:label ?Nom.
?resource dbpedia-owl:wikiPageWikiLink ?o.
?Nom bif:contains "Apple".
}
which returned no results.
this means there is no triple containing apple in its object literal, where the subject has a wikiPageWikiLink in the whole endpoint.
If this property does exist, its instances are not included in the official endpoint since there is no triple containing this property (I checked). This is probably due to the fact, that the official endpoint does not hold every dbpedia dataset, or it might be deprecated.

SPARQL: extract the dbo class for each result

I have a DBpedia request that give me a label, a Dpedia URI and the corresponding wikipedia link. I want to add a column to get the dbo class of each line. Can any one help me please?
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select distinct ?Nom ?resource ?url ?p
where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
?resource rdf:type ?p
FILTER(regex(?p,"http://dbpedia.org/ontology/"))
FILTER ( langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
}
Firstly, if you have the solution, then you should post it as an answer and then mark it as accepted so that it is easier for others looking for the solution.
Secondly, I feel that the solution you came up would work but is not the right way to do it. For getting dbo: types, one should query for types that are owl:Class types.
This is how I would do it
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
select distinct ?Nom ?resource ?url ?p
where {
?resource rdfs:label ?Nom ;
foaf:isPrimaryTopicOf ?url ;
a ?p .
?p a owl:Class .
FILTER ( langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
} limit 100
Not sure what do you mean by:
get the dbo class of each line.
But if you mean to get all predicates related to each row, the following query may help. I limited them to English ones to see the results better.
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/>
select distinct ?Nom ?resource ?url ?p
where {
?resource rdfs:label ?Nom.
?resource ?p ?dbo.
?resource foaf:isPrimaryTopicOf ?url.
FILTER ( langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
FILTER langMatches( lang(?Nom), "en" )
}
limit 100