2010-11-05 17:57:01 +00:00
|
|
|
from math import floor, ceil
|
|
|
|
|
|
|
|
def inv_op_str(op_name_string):
|
|
|
|
inverse = {
|
|
|
|
'LT' : 'GT',
|
|
|
|
'GT' : 'LT',
|
|
|
|
'm' : 'mi',
|
|
|
|
'mi' : 'm',
|
|
|
|
'o' : 'oi',
|
|
|
|
'oi' : 'o',
|
|
|
|
's' : 'si',
|
|
|
|
'si' : 's',
|
|
|
|
'd' : 'di',
|
|
|
|
'di' : 'd',
|
|
|
|
'f' : 'fi',
|
|
|
|
'fi' : 'f',
|
|
|
|
'=' : '='
|
|
|
|
}
|
|
|
|
return inverse[op_name_string]
|
|
|
|
|
|
|
|
class AllenOpIndex(object):
|
|
|
|
def __init__(self, index):
|
|
|
|
self.index
|
|
|
|
|
|
|
|
def LT(self, x, delta):
|
|
|
|
"""
|
|
|
|
X < Y
|
|
|
|
x before y
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last, x.Last + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def GT(self, x, delta):
|
|
|
|
"""
|
|
|
|
X > Y
|
|
|
|
x after y
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First - delta, x.stime
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def m(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X m Y
|
|
|
|
x meets y (x starts before y)
|
|
|
|
y should occur at end of x
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last, x.Last + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def mi(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X mi Y
|
|
|
|
inverse x meets y (x starts after y)
|
|
|
|
y should occur at the beginning of x
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First - delta, x.stime
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def o(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X o Y
|
|
|
|
x overlaps y (x starts before y)
|
|
|
|
y should occur at the end of x
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last-delta, x.Last+delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def oi(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X oi Y
|
|
|
|
inverse x overlaps y (x starts after y)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First, x.stime
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def d(self, x, delta=0):
|
|
|
|
"""
|
|
|
|
X d Y
|
|
|
|
x during y
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First, x.stime
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def di(self, x, delta=0):
|
|
|
|
"""
|
|
|
|
X di Y
|
|
|
|
inverse x during y (y during x)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First, x.Last
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def f(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X f Y
|
|
|
|
x finishes y (x starts after y, x and y end together)
|
|
|
|
"""
|
|
|
|
# delta disregarded here
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last - delta, x.Last + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def fi(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X fi Y
|
|
|
|
inverse x finishes y (x is finished by y)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last - delta, x.Last + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def s(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X s Y
|
|
|
|
x starts y (x ends before y, x and y starts together)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First - delta, x.stime + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def si(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X si Y
|
|
|
|
inverse x starts y (x is started by y)
|
|
|
|
"""
|
|
|
|
# delta disregarded here
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First - delta, x.stime + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def EQ(self, x, delta=1):
|
|
|
|
"""
|
|
|
|
X = Y
|
|
|
|
X lasts the same time as Y
|
|
|
|
"""
|
|
|
|
# delta disregarded here
|
2014-06-26 06:47:04 +00:00
|
|
|
return int((x.First + x.Last)/2) - delta, int((x.stime +
|
|
|
|
x.Last)/2) + delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def composite_intervals(self, op_x_delta_tuples):
|
|
|
|
intervals = set()
|
|
|
|
for op_x_delta in op_x_delta_tuples:
|
|
|
|
op = op_x_delta[0]
|
|
|
|
args = op_x_delta[1:]
|
|
|
|
intervals.update(getattr(self, op)(*args))
|
|
|
|
|
|
|
|
res = list(intervals)
|
|
|
|
res.sort()
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def LT(x, y, delta=0):
|
|
|
|
"""
|
|
|
|
X < Y
|
|
|
|
x before y
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last < y.First
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def GT(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X > Y
|
|
|
|
x after y
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First > y.Last
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def m(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X m Y
|
|
|
|
x meets y (x starts before y)
|
|
|
|
y should occur at end of x
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return abs(x.Last - y.First) < delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def mi(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X mi Y
|
|
|
|
inverse x meets y (x starts after y)
|
|
|
|
y should occur at the beginning of x
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return abs(x.First - y.Last) < delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def o(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X o Y
|
|
|
|
x overlaps y (x starts before y)
|
|
|
|
y should occur at the end of x
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return y.First < x.Last < y.Last
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def oi(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X oi Y
|
|
|
|
inverse x overlaps y (x starts after y)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return y.First < x.stime < y.Last
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def d(x, y, delta=0):
|
|
|
|
"""
|
|
|
|
X d Y
|
|
|
|
x during y
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return y.First < x.stime and x.Last < y.Last
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def di(x, y, delta=0):
|
|
|
|
"""
|
|
|
|
X di Y
|
|
|
|
inverse x during y (y during x)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return y.First > x.stime and x.Last > y.Last
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def f(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X f Y
|
|
|
|
x finishes y (x starts after y, x and y end together)
|
|
|
|
"""
|
|
|
|
# delta disregarded here
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First > y.Last and abs(x.Last - y.Last) < delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def fi(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X fi Y
|
|
|
|
inverse x finishes y (x is finished by y)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.First < y.Last and abs(x.Last - y.Last) < delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def s(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X s Y
|
|
|
|
x starts y (x ends before y, x and y start together)
|
|
|
|
"""
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last < y.Last and abs(x.First - y.stime) < delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def si(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X si Y
|
|
|
|
inverse x starts y (x is started by y)
|
|
|
|
"""
|
|
|
|
# delta disregarded here
|
2014-06-26 06:47:04 +00:00
|
|
|
return x.Last > y.Last and abs(x.First - y.stime) < delta
|
2010-11-05 17:57:01 +00:00
|
|
|
|
|
|
|
def EQ(x, y, delta=1):
|
|
|
|
"""
|
|
|
|
X fi Y
|
|
|
|
inverse x finishes y (x is finished by y)
|
|
|
|
"""
|
|
|
|
# delta disregarded here
|
2014-06-26 06:47:04 +00:00
|
|
|
return abs(x.First - y.stime) < delta and abs(x.Last - y.Last) < delta
|