Skip to content

SPARQL xsd:date weirdness

May 19, 2011

I wanted to look at George Bush’s start dates in office through my SPARQL endpoint running Virtuoso 6.1.0 and loaded with DBpedia. So, first thing I did:

PREFIX dbpedia: 
PREFIX dbpedia-owl: 
SELECT ?date {
    dbpedia:George_W._Bush dbpedia-owl:activeYearsStartDate ?date .
}

Getting the response:

date
“1995-01-17″^^xsd:date
“2001-01-20″^^xsd:date

My first thought on how to query it:

PREFIX dbpedia-owl: 
SELECT ?person {
  ?person dbpedia-owl:activeYearsStartDate '1995-01-17'^^xsd:date .
}

Nothing.

Well… could also try to coerce the variable to xsd:date:

PREFIX dbpedia-owl: 
SELECT ?person {
  ?person dbpedia-owl:activeYearsStartDate ?date .
  FILTER(xsd:date(?date) = '1995-01-17'^^xsd:date) .
}

Nothing.

How did I get it to work? Following Richard’s or Mat’s tricks. Richard showed that “stringifying” the date worked for equality, while Mat showed that applying xsd:dateTime coercion worked for “greater/less then” comparisons.

1)

PREFIX dbpedia-owl: 
SELECT ?person {
  ?person dbpedia-owl:activeYearsStartDate ?date .
  FILTER(str(?date) = '1995-01-17') .
}

2)

PREFIX dbpedia-owl: 
SELECT ?person {
  ?person dbpedia-owl:activeYearsStartDate ?date .
 FILTER(xsd:dateTime(?date) >= '1995-01-16T00:00:00Z'^^xsd:dateTime &&
        xsd:dateTime(?date) <= '1995-01-18T23:59:59Z'^^xsd:dateTime) .
}

Quite unfortunate that this didn’t just work the easy way.

[1] Advice from Richard and Mat taken from this thread http://answers.semanticweb.com/questions/947/dbpedia-sparql-endpoint-xsddate-comparison-weirdness

Advertisements

From → tech-tips

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: