Doesnt outputs some cities - sparql

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.

Related

Retrieve country code from RDF source recieved via Sparql query

I have the following query on this endpoint https://data.bnf.fr/sparql/ :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdagroup2elements: <http://rdvocab.info/ElementsGr2/>
PREFIX bio: <http://vocab.org/bio/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT distinct ?name ?nationality
WHERE {
?oeuvre dcterms:creator ?author.
?author foaf:name ?name.
?author rdagroup2elements:countryAssociatedWithThePerson ?nationality.
}
ORDER BY DESC (?mort) LIMIT 100
Which returns a list of authors with a nationality field that is itself another RDF source :
So, for the first author Jean Martin, I get this link to another RDF source, in the case for the country France : http://id.loc.gov/vocabulary/countries/fr
How could I modify the query to receive the country code (or country name, if not possible) instead of this link, in this case FR (or France)?
An alternative to extracting the country code from the URI, using "the Linked Data way":
The default graph of the endpoint https://data.bnf.fr/sparql/ doesn’t provide any data about the entities under the namespace http://id.loc.gov/vocabulary/countries/, but it provides entities under the namespace http://data.bnf.fr/vocabulary/countrycodes/, which have an owl:sameAs link to them.
For example:
<http://data.bnf.fr/vocabulary/countrycodes/fr> <http://www.w3.org/2002/07/owl#sameAs> <http://id.loc.gov/vocabulary/countries/fr> .
And these http://data.bnf.fr/vocabulary/countrycodes/ entities refer to the country code with skos:notation, and to the country name with skos:prefLabel (language-tagged).
For these cases, getting the country code would be possible with this property path:
?author rdagroup2elements:countryAssociatedWithThePerson/^owl:sameAs/skos:notation ?countryCode .
Unfortunately, only some rdagroup2elements:countryAssociatedWithThePerson values are under the http://id.loc.gov/vocabulary/countries/ namespace, while other values are under the http://data.bnf.fr/vocabulary/countrycodes/ namespace directly.
To find both cases, you could use UNION:
{ ?author rdagroup2elements:countryAssociatedWithThePerson/^owl:sameAs/skos:notation ?countryCode . }
UNION
{ ?author rdagroup2elements:countryAssociatedWithThePerson/skos:notation ?countryCode . }
The full query:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdagroup2elements: <http://rdvocab.info/ElementsGr2/>
PREFIX bio: <http://vocab.org/bio/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?name ?countryCode
WHERE {
?oeuvre dcterms:creator ?author.
?author foaf:name ?name.
{ ?author rdagroup2elements:countryAssociatedWithThePerson/^owl:sameAs/skos:notation ?countryCode . }
UNION
{ ?author rdagroup2elements:countryAssociatedWithThePerson/skos:notation ?countryCode . }
}
LIMIT 100
(In case you didn’t intend it: Your query treats different persons with the same name and country as one entry. To prevent this, you could output the person’s URI.)
You can use SPARQL replace function:
SELECT ... (REPLACE(STR(?nationality), "http://id.loc.gov/vocabulary/countries/", "") AS ?nationalityShort)
WHERE ...
to extract the code from the url.
But you can as well link to this resource and retrieve additional fields from it like sos:notation in your case:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdagroup2elements: <http://rdvocab.info/ElementsGr2/>
PREFIX bio: <http://vocab.org/bio/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT distinct ?name ?nationalityCode
WHERE {
?oeuvre dcterms:creator ?author.
?author foaf:name ?name.
?author rdagroup2elements:countryAssociatedWithThePerson ?nationality.
?nationality skos:notation ?nationalityCode
}
ORDER BY DESC (?mort) LIMIT 100

Sparql dbpedia search article by containing word

I've created sparql query for searching person and article
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?name ?person ?description
WHERE {
?person rdf:type dbo:Person.
?person foaf:name ?name .
?person rdfs:comment ?description .
FILTER (regex(?description, 'morgan freeman' ,'i')) .
FILTER (lang(?description) = 'in')
}
ORDER BY ?name
and its working when searching morgan freeman
but not working when searching article God Created All Things or Birth of Jesus
how to search acticle on dbpedia with sparql query?

Try to look for all space missions in the solar system which have become a satellite of their target

The DBPedia SPARQL endpoint doesn't give any results.
What is wrong?
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
SELECT distinct ?s ?o
FROM <http://dbpedia.org/>
WHERE{
?s dcterms:subject/skos:broader*
dbc:Discovery_and_exploration_of_the_Solar_System ;
dbp:satelliteOf ?o .
}

How to find the nobel prize winners

I'm trying to find the nobel prize winners (http://data.nobelprize.org/snorql) born in the 20 th century and their field of study from dbpedia.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX nobel: <http://data.nobelprize.org/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT (?x as ?Label) (count(?NAME) as ?Count)
WHERE {
?Name a nobel:Laureate;
dbpprop:dateOfBirth ?Date;
rdfs:label ?NAME.
FILTER ( ?Date >= "1900-01-01"^^xsd:date )
FILTER (?Date < "2000-01-01"^^xsd:date) .
?Name owl:sameAs ?n
Service <http://dbpedia.org/sparql>
{?n dbo:field ?x} }
GROUP BY ?x
ORDER BY desc(count(?Name))
The results shows me error 400 because of dbo:field. Where is the fault?

SPARQL: Federated query gives no result when using local file, while same query on dbpedia does

the local file uploaded on stardog:
#prefix dbo: <http://dbpedia.org/ontology/> .
#prefix dbr: <http://dbpedia.org/resource/> .
dbr:United_States dbo:leader dbr:John_Roberts ,
dbr:Joe_Biden ,
dbr:Barack_Obama ,
dbr:Paul_Ryan .
1.query using the local file:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX db: <http://dbpedia.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?person ?o
FROM <http://example.com/leaders.ttl>
WHERE{
dbr:United_States dbo:leader ?person .
SERVICE <http://dbpedia.org/sparql> { ?person dbo:abstract ?o .}
}
2.Same query using only dbpedia will give results:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX db: <http://dbpedia.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?person ?o
FROM <http://example.com/leaders.ttl>
WHERE{
#dbr:United_States dbo:leader ?person .
SERVICE <http://dbpedia.org/sparql> { dbr:United_States dbo:leader ?person. ?person dbo:abstract ?o.}
}
Using the second query will result in a colum with the leaders and a column of abstract of the leaders in all languages available from dbpedia. Why does the first query where I use the local rdf file not work? The select query on the local file with dbr:United_States dbo:leader ?person . returns exactly the same column with the same leaders as running it directly on the dbpedia endpoint: dbpedia:John_Roberts, dbpedia:Joe_Biden, dbpedia:Barack_Obama, dbpedia:Paul_Ryan.
Why does the first query give no results?