Skip to content

Instantly share code, notes, and snippets.

@giacomociti
Created July 25, 2024 14:11
Show Gist options
  • Save giacomociti/a456e8dc413a678b3e094bd2ab9af7a5 to your computer and use it in GitHub Desktop.
Save giacomociti/a456e8dc413a678b3e094bd2ab9af7a5 to your computer and use it in GitHub Desktop.
N3 rules to derive OWL-Time relations
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix time: <http://www.w3.org/2006/time#> .
@prefix pred: <http://www.w3.org/2007/rif-builtin-predicate#>.
@prefix : <http://www.w3.org/2006/time/aux#> .
# instant comparison
# TODO: should cover many more cases than just dateTime
{
?x :equal ?y .
}
<=
{
?x :dateTime ?xDateTime .
?y :dateTime ?yDateTime .
(?xDateTime ?yDateTime) pred:dateTime-equal true
} .
{
?x :dateTime ?d .
}
<=
{
# xsd:dateTimeStamp is a xsd:dateTime with a timezone (to have total order)
?x time:inXSDDateTimeStamp ?dateTimeStamp .
(?literal xsd:dateTimeStamp) log:dtlit ?dateTimeStamp .
(?literal xsd:dateTime) log:dtlit ?d
} .
{
?x :before ?y
}
<=
{
?x :dateTime ?xDateTime .
?y :dateTime ?yDateTime .
(?xDateTime ?yDateTime) pred:dateTime-less-than true
} .
# time:before
{
?interval time:before ?instant .
}
<=
{
?interval time:hasEnd [ :before ?instant ].
} .
{
?instant time:before ?interval .
}
<=
{
?interval time:hasBeginning ?B .
?instant :before ?B .
} .
{
?T1 time:before ?T2 .
}
<=
{
?T1 time:hasEnd ?E1 .
?T2 time:hasBeginning ?B2 .
?E1 :before ?B2 .
} .
# rules for binary relations on proper intervals
# notice we impement the converse of what stated in the comments from the spec
# If a proper interval T1 is intervalBefore another proper interval T2, then the end of T1 is before the beginning of T2.
{
?T1 time:intervalBefore ?T2 .
}
<=
{
?T1 a time:ProperInterval .
?T2 a time:ProperInterval .
?T1 time:before ?T2 .
} .
# If a proper interval T1 is intervalMeets another proper interval T2, then the end of T1 is coincident with the beginning of T2.
{
?T1 time:intervalMeets ?T2 .
}
<=
{
?T1 a time:ProperInterval ; time:hasEnd ?E1 .
?T2 a time:ProperInterval ; time:hasBeginning ?B2 .
?E1 :equal ?B2 .
} .
# If a proper interval T1 is intervalOverlaps another proper interval T2, then the beginning of T1 is before the beginning of T2, the end of T1 is after the beginning of T2, and the end of T1 is before the end of T2.
{
?T1 time:intervalOverlaps ?T2 .
}
<=
{
?T1 a time:ProperInterval ; time:hasBeginning ?B1 ; time:hasEnd ?E1 .
?T2 a time:ProperInterval ; time:hasBeginning ?B2 ; time:hasEnd ?E2 .
?B1 :before ?B2 .
?B2 :before ?E1 .
?E1 :before ?E2 .
} .
# If a proper interval T1 is intervalStarts another proper interval T2, then the beginning of T1 is coincident with the beginning of T2, and the end of T1 is before the end of T2.
{
?T1 time:intervalStarts ?T2 .
}
<=
{
?T1 a time:ProperInterval ; time:hasBeginning ?B1 ; time:hasEnd ?E1 .
?T2 a time:ProperInterval ; time:hasBeginning ?B2 ; time:hasEnd ?E2 .
?B1 :equal ?B2 .
?E1 :before ?E2 .
} .
# If a proper interval T1 is intervalDuring another proper interval T2, then the beginning of T1 is after the beginning of T2, and the end of T1 is before the end of T2.
{
?T1 time:intervalDuring ?T2 .
}
<=
{
?T1 a time:ProperInterval ; time:hasBeginning ?B1 ; time:hasEnd ?E1 .
?T2 a time:ProperInterval ; time:hasBeginning ?B2 ; time:hasEnd ?E2 .
?B2 :before ?B1 .
?E1 :before ?E2 .
} .
# If a proper interval T1 is intervalFinishes another proper interval T2, then the beginning of T1 is after the beginning of T2, and the end of T1 is coincident with the end of T2.
{
?T1 time:intervalFinishes ?T2 .
}
<=
{
?T1 a time:ProperInterval ; time:hasBeginning ?B1 ; time:hasEnd ?E1 .
?T2 a time:ProperInterval ; time:hasBeginning ?B2 ; time:hasEnd ?E2 .
?B2 :before ?B1 .
?E1 :equal ?E2 .
} .
# If a proper interval T1 is intervalEquals another proper interval T2, then the beginning of T1 is coincident with the beginning of T2, and the end of T1 is coincident with the end of T2.
{
?T1 time:intervalEquals ?T2 .
}
<=
{
?T1 a time:ProperInterval ; time:hasBeginning ?B1 ; time:hasEnd ?E1 .
?T2 a time:ProperInterval ; time:hasBeginning ?B2 ; time:hasEnd ?E2 .
?B1 :equal ?B2 .
?E1 :equal ?E2 .
} .
# If a proper interval T1 is intervalDisjoint another proper interval T2, then the beginning of T1 is after the end of T2, or the end of T1 is before the beginning of T2, i.e. the intervals do not overlap in any way, but their ordering relationship is not known.
{ ?T1 time:intervalDisjoint ?T2 } <= { ?T1 time:intervalBefore ?T2 } .
{ ?T1 time:intervalDisjoint ?T2 } <= { ?T2 time:intervalBefore ?T1 } .
# If a proper interval T1 is intervalIn another proper interval T2, then the beginning of T1 is after the beginning of T2 or is coincident with the beginning of T2, and the end of T1 is before the end of T2, or is coincident with the end of T2, except that end of T1 may not be coincident with the end of T2 if the beginning of T1 is coincident with the beginning of T2.
{ ?T1 time:intervalIn ?T2 } <= { ?T1 time:intervalDuring ?T2 } .
{ ?T1 time:intervalIn ?T2 } <= { ?T1 time:intervalStarts ?T2 } .
{ ?T1 time:intervalIn ?T2 } <= { ?T1 time:intervalFinishes ?T2 } .
# An instant that falls inside the interval. It is not intended to include beginnings and ends of intervals.
{
?interval time:inside ?instant .
}
<=
{
?interval time:hasBeginning ?B ; time:hasEnd ?E .
?B :before ?instant .
?instant :before ?E .
} .
# inverse relations
# inverses may also be derived applying OWL rules
{ ?T1 time:after ?T2 } <= { ?T2 time:before ?T1 } .
{ ?T1 time:intervalAfter ?T2 } <= { ?T2 time:intervalBefore ?T1 } .
{ ?T1 time:intervalMetBy ?T2 } <= { ?T2 time:intervalMeets ?T1 } .
{ ?T1 time:intervalOverlappedBy ?T2 } <= { ?T2 time:intervalOverlaps ?T1 } .
{ ?T1 time:intervalStartedBy ?T2 } <= { ?T2 time:intervalStarts ?T1 } .
{ ?T1 time:intervalContains ?T2 } <= { ?T2 time:intervalDuring ?T1 } .
{ ?T1 time:intervalFinishedBy ?T2 } <= { ?T2 time:intervalFinishes ?T1 } .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment