views:

167

answers:

1

I have a SPARQL query:

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX  person: <http://www.myOntDomain/person#&gt;
PREFIX  likedEvent: <http://www.myOntDomain/likedEventRule#&gt;
PREFIX  event: <http://www.myOntDomain/event#&gt;
PREFIX  owl:  <http://www.w3.org/2002/07/owl#&gt;
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#&gt;
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX  weather: <http://www.myOntDomain/weather#&gt;
PREFIX  eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#&gt;
PREFIX  freeAtEvent: <http://www.myOntDomain/freeAtEventRule#&gt;

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&gt; | <http://www.myOntDomain/person#Ali&gt;  | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/event#SerlockHolmesMovie&gt;          | <http://www.myOntDomain/person#Ali&gt;  | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/event#SerlockHolmesMovie&gt;          | <http://www.myOntDomain/person#Ayse&gt; | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch&gt; | <http://www.myOntDomain/person#Veli&gt; | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/weather#AnkaraMuseumVisit&gt;         | <http://www.myOntDomain/person#Ali&gt;  | "2010-01-19T17:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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#&gt;
PREFIX  person: <http://www.myOntDomain/person#&gt;
PREFIX  likedEvent: <http://www.myOntDomain/likedEventRule#&gt;
PREFIX  event: <http://www.myOntDomain/event#&gt;
PREFIX  owl:  <http://www.w3.org/2002/07/owl#&gt;
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#&gt;
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX  weather: <http://www.myOntDomain/weather#&gt;
PREFIX  eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#&gt;
PREFIX  freeAtEvent: <http://www.myOntDomain/freeAtEventRule#&gt;

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#&gt;
PREFIX  person: <http://www.myOntDomain/person#&gt;
PREFIX  likedEvent: <http://www.myOntDomain/likedEventRule#&gt;
PREFIX  event: <http://www.myOntDomain/event#&gt;
PREFIX  owl:  <http://www.w3.org/2002/07/owl#&gt;
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#&gt;
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX  weather: <http://www.myOntDomain/weather#&gt;
PREFIX  eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#&gt;
PREFIX  freeAtEvent: <http://www.myOntDomain/freeAtEventRule#&gt;

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&gt;          | <http://www.myOntDomain/person#Ayse&gt; | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/event#SerlockHolmesMovie&gt;          | <http://www.myOntDomain/person#Ali&gt;  | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch&gt; | <http://www.myOntDomain/person#Veli&gt; | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
| <http://www.myOntDomain/event#SyntheticPitchFootballMatch&gt; | <http://www.myOntDomain/person#Ali&gt;  | "2010-01-19T16:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime&gt; |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX  person: <http://www.myOntDomain/person#&gt;
PREFIX  likedEvent: <http://www.myOntDomain/likedEventRule#&gt;
PREFIX  event: <http://www.myOntDomain/event#&gt;
PREFIX  owl:  <http://www.w3.org/2002/07/owl#&gt;
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#&gt;
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX  weather: <http://www.myOntDomain/weather#&gt;
PREFIX  eventHasSuitableWeather: <http://www.myOntDomain/eventHasSuitableWeather#&gt;
PREFIX  freeAtEvent: <http://www.myOntDomain/freeAtEventRule#&gt;

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 .

+1  A: 

There is nothing obviously wrong with your query, this may be an issue with how the SPARQL engine you are using implements the = operator. Which SPARQL engine are you using?

The = operator should do value equality so your filter should as you expect still return most of the same results when the query is evaluated against your ontology.

Even if the = operator is only doing RDF term equality in the SPARQL engine you are using you should still get results since the Literals will still match exactly.

If you post which SPARQL engine you're are using and copies of your actual ontology I may be able to give you a better answer than "it should work"

Update

I suspect but can't say for certain that this may be some strange issue in xsd:dateTime serialization/deserialization. I would send an email to the Jena developer mailing list detailing your problem and see if the developers and the community can give you an answer on this one:

http://tech.groups.yahoo.com/group/jena-dev/

RobV
From the subsequent discussion on the Jena mailing list this was a bug which was due to using an older version of Jena than the current one - the latest versions had the bug fixed
RobV