English 中文(简体)
SPARQL xsd:dateTime equality
原标题:

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 .

最佳回答

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/

问题回答

暂无回答




相关问题
Weird Time Issue in Python

Problem with using times in Python. Terminal > Python >>> calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 This time indicates GMT: Tue, 17 Nov 2009 09:16:20 GMT Eclipse ...

How does a .NET process get the culture information?

I have a Windows service running (C#, .NET 2.0) on Windows Server 2003 R2. In one server the System.Threading.Thread.CurrentThread.CurrentCulture is {en-AU} and in the other {en-US}. This has caused a ...

Best way to get maximum Date value in java?

I m writing a bit of logic that requires treating null dates as meaning forever in the future (the date in question is an expiration date, which may or may not exist). Instead of putting in special ...

Date format in SQL Server

Short Question: What s the best date format to use in SQL Server? Long Explanation: We re converting our database from mysql to SQL Server. In mysql we always used int(11) to avoid the daylight ...

Converting asp.net/sql web app to be ime zone savy

Our current app stores all dates via the server s datetime. I m thinking we need to update all datetime values in the database over to UTC time. Now for displaying these dates back to the user, I ...

Check if string is of SortableDateTimePattern format

Is there any way I can easily check if a string conforms to the SortableDateTimePattern ("s"), or do I need to write a regular expression? I ve got a form where users can input a copyright date (as a ...

DateTime in PropertyGrid in .Net

I m currently working on some DateTime properties in a PropertyGrid in c#.Net. Im using the default drop-down datetime picker. My question: Is there any way to show the full date with the time? By ...

热门标签