2.5) List the people and their names who are born in Jönköping before 1900.
2.6) Are there musical artists who were born in Jönköping? (use an ASK query).
2.7) Find 10 people (URI and place of death) who were born in Jönköping, but died elsewhere.
I am using dbpedia to run queries and fetch data
SELECT DISTINCT * WHERE {?x ?y "Jönköping"#en }
This is the URI Which is retrived
DESCRIBE http://dbpedia.org/resource/Jönköping
You can solve as following;
2.5) List the people and their names who are born in Jönköping before 1900
PREFIX db: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?name ?birth
WHERE
{
?person dbo:birthPlace db:Jönköping .
?person dbo:birthDate ?birth .
?person foaf:name ?name .
FILTER (?birth < "1900-01-01"^^xsd:date) .
}
ORDER BY ?birth
2.6) Are there musical artists who were born in Jönköping? (use an ASK query)
PREFIX db: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
ASK WHERE{SELECT ?person WHERE{
?person a dbo:MusicalArtist .
?person dbo:birthPlace db:Jönköping .
}}
2.7)Find 10 people (URI and place of death) who were born in Jönköping, but died elsewhere
PREFIX db: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?name ?person
WHERE
{
?person dbo:birthPlace db:Jönköping .
?person dbo:deathPlace ?deathPlace.
?person foaf:name ?name .
FILTER (?deathPlace != db:Jönköping) .
} ORDER BY ?name LIMIT 10
Related
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?
I have the following code to retrieve all people that was born in Barcelona
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?person ?birthPlace
WHERE {
?person rdfs:label ?label.
?person rdf:type dbo:Person.
?person <http://dbpedia.org/property/birthPlace>
<http://dbpedia.org/resource/Barcelona>.
}
However, I do not know how to get the birthPlace. I want a variable that says next to each name that Barcelona is the place of birth. Any ideas?
How about this:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?person ?birthPlace
WHERE {
?person rdfs:label ?label.
?person rdf:type dbo:Person.
?person <http://dbpedia.org/property/birthPlace> ?birthPlace.
FILTER (?birthPlace = <http://dbpedia.org/resource/Barcelona>)
}
Note that your query has a pattern to match labels, but the labels are not returned. That leads to duplicate results because some people have multiple labels (in different languages). Remove the pattern, or add ?label to the SELECT clause.
You can abbreviate <http://dbpedia.org/property/birthPlace> to dbp:birthPlace.
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?
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?
Assume that I uses the FOAF ontology. I want to return the name and the mbox for each person. I use the following query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?name ?email
WHERE {
?person foaf:name ?name.
?person foaf:mbox ?email.
}
The result of the join is a set of rows: ?person, ?name, ?email. This query is returning the ?name and ?email. Note that in some of the ?person may have multiple mailboxes, so in the returned set, a ?name row may appear multiple times, once for each mailbox.
Is there a solution to make a GROUP BY person ?name?
You can group by person but then you need an aggregation for ?name and ?email
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT (sample(?name) AS ?name2) (sample(?email) as ?email2)
WHERE {
?person foaf:name ?name.
?person foaf:mbox ?email.
} GROUP BY ?person
SAMPLE picks one possible from the group for each ?person.
or maybe
SELECT (group_concat(?name) AS ?names)
(except that's a string).
It may be easier work with
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?email
WHERE {
?person foaf:name ?name.
?person foaf:mbox ?email.
}
ORDER BY ?person ?name ?email
and process the results in your application where you know the incoming results have all the entries for one person is a single section of the results.