I'm trying to extract the date of birth of a number of people from dbpedia.org. However some queries fail because the data is in a different attribute. For example:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
select ?birthDate where {
dbr:Alan_Turing dbo:birthDate ?birthDate
}
returns 1912-06-23 as it should but:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
select ?birthDate where {
dbr:Grace_Hopper dbo:birthDate ?birthDate
}
returns an empty result.
EDIT TO ADD:
The original problem was confused by the disparity between the live.dbpedia.org and dbpedia.org, meaning despite the non-live version having dbo:birthDate in both this wasn't the same on live.dbpedia.org. If you compare Alan Turing with Grace Hopper you see they have their birthDates in two different ontologies. So the problem is now how to handle those gracefully.
The answer is to use the UNION operator to find an answer from whichever ontology has it:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
select ?birthDate where {
{ dbr:Alan_Turing dbo:birthDate ?birthDate }
UNION
{ dbr:Alan_Turing dbp:birthDate ?birthDate }
}
Gives us two results, both the same. And for Grace Hopper:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
select ?birthDate where {
{ dbr:Grace_Hopper dbo:birthDate ?birthDate }
UNION
{ dbr:Grace_Hopper dbp:birthDate ?birthDate }
}
We only get one result
As live.dbpedia.org already has a bunch of namespace prefixes defined and as suggested by #AKSW we can simplify the call even further. The distinct keyword means identical results from different taxonomies are merged together:
select distinct ?birthDate {
dbr:Grace_Hopper dbo:birthDate|dbp:birthDate ?birthDate
}
Giving this result.
Related
I can fetch several metadata fields for a particular person using the following query at https://dbpedia.org/sparql:
prefix dbpedia: <http://dbpedia.org/resource/>
prefix dbpedia-owl: <http://dbpedia.org/ontology/>
select * {
<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:birthName ?name.
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:birthDate ?birth_date}
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:deathDate ?death_date}
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:thumbnail ?thumbnail}
OPTIONAL{<http://dbpedia.org/resource/Mahatma_Gandhi> dbpedia-owl:abstract ?abstract FILTER (lang(?abstract) = 'en')}
}
I've also seen query syntax that shows how to get metadata fields on many people at once:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?resource ?name
WHERE {
?resource rdf:type dbo:Person;
dbp:name ?name.
FILTER (lang(?name) = 'en')
}
ORDER BY ASC(?name)
LIMIT 10000 OFFSET 10000
How can I combine these two so that I can fetch the birth_date, death_date, thumbnail, and abstract (in English) for all people in DBPedia? Any pointers others can offer would be hugely helpful!
My query is
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?craft where
{
?craft <http://dbpedia.org/property/title> ?v.
}
Now this returning lot of results,
but nothing related to Steve Jobs or Tim Cook, even though in their page there is a property named title.
dbp:title dbr:List_of_Apple_Computer_CEOs
http://dbpedia.org/page/Steve_Jobs
The query:
PREFIX dbp: <http://dbpedia.org/property/>
SELECT (COUNT(*) AS ?nb_result)
WHERE {
?craft dbp:title ?v .
}
returns:
nb_result
---------
1566113
The public query endpoint for DBpedia limits the number of results to 10,000, among other restrictions. So your chances of retrieving any specific statement there are very small. If you worry that the data at the query endpoint is different than at the front end, you can check that the data is there with the query:
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?prop ?value
WHERE {
dbr:Steve_Jobs ?prop ?value .
}
and compare with what's displayed at http://dbpedia.org/page/Steve_Jobs.
Hello I'm trying to retrieve from DBpedia persons that are born in Lyon after 1900 ("1900"^^xsd:gYear)
Here is my piece of code :
prefix dbo: <http://dbpedia.org/ontology/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbr: <http://dbpedia.org/resource/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select $n $birthDate
{
$p a dbo:Person.
$p dbo:birthPlace dbr:Lyon.
$p foaf:name $n.
$p dbo:birthDate $birthDate.
filter($birthDate > "1980"^^xsd:gYear).
}
And I'm getting the following results :
query results
From my understanding, the problem is in the data: many dates do not have valid xsd:date literals, thus, the comparison fails. It also fails for filter($birthDate > "1980-01-01"^^xsd:date). According to XML Schema, xsd:date must provide the literal in form "YYYY-MM-DD". And that's unfortunately not the case for many dates in DBpedia. For valid dates, the comparison works perfectly.
Workaround:
prefix dbo: <http://dbpedia.org/ontology/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbr: <http://dbpedia.org/resource/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select $n $birthDate ?year
{
$p a dbo:Person.
$p dbo:birthPlace dbr:Lyon.
$p foaf:name $n.
$p dbo:birthDate $birthDate.
filter($birthDate > "1980-01-01"^^xsd:date).
bind(replace(str($birthDate),"(\\d+)-\\d*-\\d*", "$1") as ?year)
filter(xsd:integer(?year) > 1980)
}
Note, it might fail for other kinds of ill-formed dates. I didn't check all corner cases.
Somebody should report this to the DBpedia community. It should be fixed.
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?).
I want to get all pages which have a specified category and a specified key. My query:
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://dublincore.org/2010/10/11/dcterms.rdf#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX grs: <http://www.georss.org/georss/point>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?page ?cat ?key ?value (lang(?value) as ?language) WHERE {
?page dcterms:subject ?cat .
?page ?key ?value .
FILTER(
regex(?cat, "category:Amusement_parks_in_the_Netherlands") &&
?key = foaf:depiction
)
}
But it return zero results. See here: SNORQL query
It should at least return this page: http://dbpedia.org/page/Duinrell (because it matches the criteria).
Any ideas?
There's a couple of things wrong with your query. First of all, don't use a regex when comparing URIs. Instead of:
regex(?cat, "category:Amusement_parks_in_the_Netherlands")
use:
?cat = <http://dbpedia.org/resource/category:Amusement_parks_in_the_Netherlands>
Second: your namespace prefix for dublin core seems wrong. You are querying the property dcterms:subject, and in your query, the prefix dcterms is mapped to the namespace http://dublincore.org/2010/10/11/dcterms.rdf#. However, the actual property in DBPedia is http://purl.org/dc/terms/subject, so your namespace prefix should map to http://purl.org/dc/terms/ instead.