Writing Query result to .ttl file format - sparql

Any ideas on how to save the results of this SPARQL query into a TURTLE format?
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
select distinct ?city ?labelEn{
?city a dbo:City.
?city rdfs:label ?labelEn.
filter(lang(?labelEn) = 'en').
}
LIMIT 10

One way is to just ask the DBpedia endpoint to do so. Of course, you may not be expecting the reification that results there.
Later comments suggest what you really want is rather different from your original question... More like --
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
CONSTRUCT
{ ?city a dbo:City .
?city rdfs:label ?labelEn .
}
WHERE
{ ?city a dbo:City .
?city rdfs:label ?labelEn .
FILTER(lang(?labelEn) = 'en')
}
-- which again you can ask the endpoint to serialize as Turtle.

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

How to apply global language filter across several fields in Sparql

I'm learning semantic web and using dbpedia to learn sparql. Below is an example to get all the schools in IL, USA. If you look at the filters, I'm filtering 2 fields (name and city) for the English language only.
Question - instead of 2 filter expressions or 'n' number of filter expressions per field, is it possible to set a global filter condition that can be applied to set of fields?
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select ?link ?name ?city ?website where {
SERVICE <https://dbpedia.org/sparql> {
?link rdf:type dbo:School .
?link rdfs:label ?name .
?link dbo:country dbr:United_States .
?link dbo:state dbr:Illinois .
?link dbo:city ?city_link .
?city_link rdfs:label ?city .
OPTIONAL {
?link dbp:website ?website .
}
}
FILTER (lang(?name)="en") .
FILTER (lang(?city)="en") .
}

Doesnt outputs some cities

Well. Can someone explain to noob why is my code for example working with some cities like Odessa, London, Barcelona, Berlin. But does not work with Perm, Moscow, Athens and some a lot of another cities?
Changing names in quotes
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/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT *
WHERE {
?s rdfs:label "Moscow"#en .
?s dbo:populationTotal ?numberOfInhabitants .
?s dbo:country ?country .
?s dbo:leaderTitle ?cityHead
}
Wanna have query that will work with whatever city would be in the quotes.

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

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