How to find the nobel prize winners - sparql

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?

Related

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?

SPARQL Query filter values from another resource

I have a query made like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sw: <http://www.semanticweb.org/lorep/ontologies/2021/7/untitled-ontology-3#>
SELECT ?Name ?Surname ?Birth ?y
WHERE {
?x sw:is_in ?y ;
sw:Name ?Name;
sw:Surname ?Cognome;
sw:Birth ?Birth;
}
Is there any way to filter from a specific value of the resource y?
I'm quite new to query so any help would be appreciated

SPARQL query all persons who lived through the 20th century in DBPedia

I want to query all persons who lived through the entire 20th century in DBPedia.
Im using https://dbpedia.org/sparql/ to process my query. I have limited the output to 20.
The query I've tried is the following:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?personName ?birthDate ?deathDate
WHERE {
FILTER (?birthDate < "1900-01-01"^^xsd:date AND ?deathDate > "1999-12-31"^^xsd:date).
?p rdf:type dbo:Person.
?p dbp:name ?personName.
?p dbp:birthDate ?birthDate.
?p dbp:deathDate ?deathDate.
}
LIMIT 20.
In the output all person died after 1999-12-31 but they weren't born before 1900-01-01.
Why is my query wrong? How can I fix it?
Thanks in advance for you time.
This issue is due to integer values being included in the query results, and can be resolved using the DATATYPE() function in the same or a new FILTER() section.
For example:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?personName ?birthDate ?deathDate
WHERE
{
?person rdf:type dbo:Person;
dbp:name ?personName;
dbp:birthDate ?birthDate;
dbp:deathDate ?deathDate.
#This FILTER ensures that only xsd:date values are returned
FILTER(DATATYPE(?birthDate) = xsd:date && DATATYPE(?deathDate) = xsd:date).
FILTER (?birthDate < "1900-01-01"^^xsd:date && ?deathDate > "1999-12-31"^^xsd:date).
}
LIMIT 20
Live Query Definition
Live Query Result
DATATYPE() Documentation

SPARQL Syntax correction

It's my first time using SPARQL.
Using DBpedia, I want to list the band names of all Rock bands from 1992
The code I've already developed runs correctly but gives 0 results. Am I filtering the date incorrectly?
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?bandname where {
?band dbo:genre dbp:Rock_music .
?band foaf:name ?bandname .
FILTER (dbo:activeYearsStartYear >= xsd:date("1992-01-01") && dbo:activeYearsStartYear <= xsd:date("1992-12-31"))
}
I expect only the band names in a column.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?bandname ?date where {
?band dbo:genre dbp:Rock_music .
?band foaf:name ?bandname .
?band dbo:activeYearsStartYear ?date .
FILTER (?date >= "1992-01-01"^^xsd:dateTime && ?date <= "1992-12-31"^^xsd:dateTime)
}
This does the trick but note that dbo:activeYearsStartYear produces the year only, so FILTER is not using day/month.

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.