I have a SPARQL query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX person: <http://www.myOntDomain/person#>
PREFIX likedEvent: <http://www.myOntDomain/likedEventRule#>
PREFIX event: <http://www.myOntDomain/event#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX weather: <http://www.myOntDomain/weather#>
PREFIX eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#>
PREFIX freeAtEvent: <http://www.myOntDomain/freeAtEventRule#>
SELECT DISTINCT ?Event ?Person ?Time
WHERE
{ ?Person rdf:type person:Person .
?Event rdf:type event:Event .
?WeatherEvent
rdf:type weather:WeatherEvent .
?WeatherType rdf:type weather:WeatherEventType .
?Person likedEvent:likedEvents ?Event ;
freeAtEvent:freeAtEvent ?Event .
?Event eventHasSuitableWeather:eventHasSuitableWeather true ;
event:eventHasDate ?Time .
?Person person:hasName ?PersonName ;
person:hasAge ?PersonAge .
?Event event:hasEventType ?EventType .
}
which returns the following result set on a specific ontology :
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Event | Person | Time |
=====================================================================================================================================================================================================
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch> | <http://www.myOntDomain/person#Ali> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/event#SerlockHolmesMovie> | <http://www.myOntDomain/person#Ali> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/event#SerlockHolmesMovie> | <http://www.myOntDomain/person#Ayse> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch> | <http://www.myOntDomain/person#Veli> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/weather#AnkaraMuseumVisit> | <http://www.myOntDomain/person#Ali> | "2010-01-19T17:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I want to add a time constraint to select Events that will occur at the time:
2010-01-19T16:00:00Z
so I add a FILTER element to my query that is now :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX person: <http://www.myOntDomain/person#>
PREFIX likedEvent: <http://www.myOntDomain/likedEventRule#>
PREFIX event: <http://www.myOntDomain/event#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX weather: <http://www.myOntDomain/weather#>
PREFIX eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#>
PREFIX freeAtEvent: <http://www.myOntDomain/freeAtEventRule#>
SELECT DISTINCT ?Event ?Person ?Time
WHERE
{ ?Person rdf:type person:Person .
?Event rdf:type event:Event .
?WeatherEvent
rdf:type weather:WeatherEvent .
?WeatherType rdf:type weather:WeatherEventType .
?Person likedEvent:likedEvents ?Event ;
freeAtEvent:freeAtEvent ?Event .
?Event eventHasSuitableWeather:eventHasSuitableWeather true ;
event:eventHasDate ?Time .
?Person person:hasName ?PersonName ;
person:hasAge ?PersonAge .
?Event event:hasEventType ?EventType .
FILTER ( ?Time = "2010-01-19T16:00:00Z"^^xsd:dateTime )
}
However this time query returns empty result list on the same ontology :
-------------------------
| Event | Person | Time |
=========================
-------------------------
Obviously I am missing something about SPARQL or xsd:dateTime comparison but I couldn't figure it out. If you have an idea, please guide me. Thanks.
UPDATE
I use the ARQ implementation of SPARQL which is used in Jena Framework.I think the problem is about implementation not the ontology or query
I examined the implementations of com.hp.hpl.jena.datatypes.xsd.XSDDateTime and com.hp.hpl.jena.datatypes.xsd.AbstractDateTime can be found here : http://grepcode.com/file/repo1.maven.org/maven2/com.hp.hpl.jena/jena/2.6.0/com/hp/hpl/jena/datatypes/xsd
and saw that a dateTime object is represented by 9 values :
protected final static int CY = 0, M = 1, D = 2, h = 3, m = 4, s = 5, ms = 6, utc=7, msscale=8
The value msscale is always 3 when XSDDateTime object is created from a java.util.Calendar object and the XSDDateTime objects parsed from the ontology is always zero. Moreover the compare function checks all these 9 values for equality so they are never equal. For example when I add the FILTER by editing query text, I get the desired result after equality checks. But when I add the FILTER programmatically the serialization of the two FILTERs are the same, however the result is not the same. Here is an example two queries and their result immediately shown after them.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX person: <http://www.myOntDomain/person#>
PREFIX likedEvent: <http://www.myOntDomain/likedEventRule#>
PREFIX event: <http://www.myOntDomain/event#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX weather: <http://www.myOntDomain/weather#>
PREFIX eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#>
PREFIX freeAtEvent: <http://www.myOntDomain/freeAtEventRule#>
SELECT DISTINCT ?Event ?Person ?Time
WHERE
{ ?Person rdf:type person:Person .
?Event rdf:type event:Event .
?WeatherEvent
rdf:type weather:WeatherEvent .
?WeatherType rdf:type weather:WeatherEventType .
?Person likedEvent:likedEvents ?Event ;
freeAtEvent:freeAtEvent ?Event .
?Event eventHasSuitableWeather:eventHasSuitableWeather true ;
event:eventHasDate ?Time .
?Person person:hasName ?PersonName ;
person:hasAge ?PersonAge .
?Event event:hasEventType ?EventType .
FILTER ( ?Time = "2010-01-19T16:00:00Z"^^xsd:dateTime )
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Event | Person | Time |
=====================================================================================================================================================================================================
| <http://www.myOntDomain/event#SerlockHolmesMovie> | <http://www.myOntDomain/person#Ayse> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/event#SerlockHolmesMovie> | <http://www.myOntDomain/person#Ali> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch> | <http://www.myOntDomain/person#Veli> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch> | <http://www.myOntDomain/person#Ali> | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX person: <http://www.myOntDomain/person#>
PREFIX likedEvent: <http://www.myOntDomain/likedEventRule#>
PREFIX event: <http://www.myOntDomain/event#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX weather: <http://www.myOntDomain/weather#>
PREFIX eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#>
PREFIX freeAtEvent: <http://www.myOntDomain/freeAtEventRule#>
SELECT DISTINCT ?Event ?Person ?Time
WHERE
{ ?Person rdf:type person:Person .
?Event rdf:type event:Event .
?WeatherEvent
rdf:type weather:WeatherEvent .
?WeatherType rdf:type weather:WeatherEventType .
?Person likedEvent:likedEvents ?Event ;
freeAtEvent:freeAtEvent ?Event .
?Event eventHasSuitableWeather:eventHasSuitableWeather true ;
event:eventHasDate ?Time .
?Person person:hasName ?PersonName ;
person:hasAge ?PersonAge .
?Event event:hasEventType ?EventType .
FILTER ( ?Time = "2010-01-19T16:00:00Z"^^xsd:dateTime )
FILTER ( ?Time = "2010-01-19T16:00:00Z"^^xsd:dateTime )
}
-------------------------
| Event | Person | Time |
=========================
-------------------------
UPDATE
I asked the same question in jena-dev and learned that there is nothing wrong with query or the code. This is a problem in Jena 2.6.0 however it is already fixed in Jena 2.6.2 .