stsquad
stsquad

Reputation: 6032

How to gracefully handle dbpedia queries of birthDate in different ontologies

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.

Upvotes: 1

Views: 550

Answers (1)

stsquad
stsquad

Reputation: 6032

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.

Upvotes: 1

Related Questions