SPARQL クエリがあります。
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 .
}
特定のオントロジーで次の結果セットを返します。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 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> |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
その時間に発生するイベントを選択する時間制約を追加したい:
2010-01-19T16:00:00Z
そのため、現在のクエリに FILTER 要素を追加します。
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 |
=========================
-------------------------
明らかに、SPARQL または xsd:dateTime の比較について何かが欠けていますが、それを理解できませんでした。アイデアがあれば、私を導いてください。ありがとう。
アップデート
Jena Framework で使用されている SPARQL の ARQ 実装を使用しています。問題はオントロジーやクエリではなく、実装に関するものだと思います
com.hp.hpl.jena.datatypes.xsd.XSDDateTime と com.hp.hpl.jena.datatypes.xsd.AbstractDateTime の実装を調べました。http://grepcode.com/file/repo1.maven .org/maven2/com.hp.hpl.jena/jena/2.6.0/com/hp/hpl/jena/datatypes/xsd
そして、dateTime オブジェクトが 9 つの値で表されていることがわかりました。
protected final static int CY = 0, M = 1, D = 2, h = 3, m = 4, s = 5, ms = 6, utc=7, msscale=8
XSDDateTime オブジェクトが java.util.Calendar オブジェクトから作成され、オントロジーから解析された XSDDateTime オブジェクトが常にゼロの場合、値 msscale は常に 3 です。さらに、比較機能はこれら 9 つの値すべてが等しいかどうかをチェックするため、決して等しくありません。たとえば、クエリ テキストを編集して FILTER を追加すると、等値チェック後に目的の結果が得られます。しかし、プログラムで FILTER を追加すると、2 つの FILTER のシリアル化は同じですが、結果は同じではありません。以下は、2 つのクエリの例で、その直後に結果が表示されます。
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 |
=========================
-------------------------
アップデート
jena-dev で同じ質問をしたところ、クエリやコードに問題がないことがわかりました。これは Jena 2.6.0 の問題ですが、Jena 2.6.2 ではすでに修正されています。