def testIMeets(self): model = Model([ ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ]) result = inference( model, Tense([iMeets], stub_model.Close("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), OP) ])) result = inference( model, Tense([meets], stub_model.Close("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), CL) ]))
def findSpanningIntervals(self, situation): result = [] for start, end in self.findRanges(situation): result.append( SpanningInterval(CL, Interval(CL, start, end, CL), Interval(CL, start, end, CL), OP)) return SpanningIntervalSet(result)
def testGt(self): model = Model([ ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ]) result = inference( model, AndR(Not(overlaps(stub_model.Close("figure", "landmark"))), [equals], Tense([greaterThan], stub_model.Close("figure", "landmark")))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, CL), OP), SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, CL), OP), SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, OP), CL) ]))
def testInferenceBase(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 0, 0, CL), Interval(CL, 1, 1, CL), CL)) ]) result = inference(model, stub_model.Visible("figure", "landmark")) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 0, 0, CL), Interval(CL, 1, 1, CL), CL) ])) result = inference(model, stub_model.Close("figure", "landmark")) self.assertEqual(result, emptySpanningIntervalSet) result = inference(model, Not(stub_model.Close("figure", "landmark"))) self.assertEqual(result, allIntervals) result = inference(model, overlaps(stub_model.Close("figure", "landmark"))) self.assertEqual(result, emptySpanningIntervalSet) result = inference( model, Not(overlaps(stub_model.Close("figure", "landmark")))) self.assertEqual(result, allIntervals)
def testEmptyInterval(self): self.assertEqual( emptySpanningInterval.containsInterval(Interval(CL, 0.5, 2.5, CL)), False) self.assertEqual( emptySpanningInterval.containsInterval(Interval(OP, 0.5, 2.5, OP)), False)
def testContains(self): si = SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL) self.assertEqual(si.contains(0), True) self.assertEqual(si.contains(1.5), True) self.assertEqual(si.contains(3.1), False)
def testNormalizeC2(self): ns1 = SpanningInterval(CL, Interval(CL, NINF, 1, CL), Interval(CL, 2, 3, CL), CL).normalized() self.assertEqual(ns1.i1.alpha, OP) self.assertEqual(ns1.i1.beta, CL) print "failing" ns1 = SpanningInterval(CL, Interval(CL, 1, PINF, CL), Interval(CL, 2, 3, CL), CL).normalized() self.assertEqual(ns1.j, 3) self.assertEqual(ns1.gamma, CL) self.assertEqual(ns1.delta, CL)
def testIntersect(self): s1 = SpanningInterval(CL, Interval(CL, NINF, 1, CL), Interval(CL, 2, 3, CL), CL).normalized() s2 = SpanningInterval(CL, Interval(CL, NINF, 1, CL), Interval(CL, 2.1, 2.9, CL), CL).normalized() self.assertEqual( SpanningInterval.intersection(s1, emptySpanningInterval), emptySpanningInterval) self.assertEqual(SpanningInterval.intersection(s1, s1), s1) self.assertEqual(SpanningInterval.intersection(s1, s2), s2)
def testInferenceAnd(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 2, 3, CL), Interval(CL, 2, 3, CL), CL)), ModelEntry( Following("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)) ]) result = inference( model, AndR(stub_model.Visible("figure", "landmark"), [allenRelations.finishes], stub_model.Close("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 2.0, 3.0, CL), Interval(CL, 2.0, 3.0, CL), CL) ])) result = inference( model, AndR(stub_model.Close("figure", "landmark"), [allenRelations.finishes], stub_model.Visible("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 2.0, 3.0, CL), CL) ]))
def testNormalizeOp(self): si = SpanningInterval(OP, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, 3.0, CL), OP) self.assertEqual( si.normalized(), SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP)) si2 = SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, 3.0, CL), CL) self.assertEqual( si2.normalized(), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, 3.0, CL), CL))
def testCenter(self): self.assertEqual( SpanningInterval(CL, Interval(OP, 0, 3.0, CL), Interval(CL, 4, 7, OP), CL).averageLength, 4.0) self.assertEqual( SpanningInterval(CL, Interval(OP, 0, 3.0, CL), Interval(CL, 3, 7, OP), CL).averageLength, 3.5) self.assertEqual( SpanningInterval(CL, Interval(OP, 0, 3.0, CL), Interval(CL, 1.5, 3, OP), CL).averageLength, 0.75)
def testIntersect2(self): s1 = SpanningInterval(CL, Interval(CL, 1, 2, CL), Interval(CL, 2, 3, CL), CL) s2 = SpanningInterval(CL, Interval(CL, 1.5, 2.5, CL), Interval(CL, 2.1, 2.9, CL), CL) self.assertEqual( SpanningInterval.intersection(s1, s2), SpanningInterval(CL, Interval(CL, 1.5, 2, CL), Interval(CL, 2.1, 2.9, CL), CL))
def testNormalizeC1(self): self.assertEqual( SpanningInterval(CL, Interval(CL, 0, NINF, CL), Interval(CL, 2, 3, CL), CL).normalized(), emptySpanningInterval) self.assertEqual( SpanningInterval(CL, Interval(CL, PINF, 1, CL), Interval(CL, 2, 3, CL), CL).normalized(), emptySpanningInterval) self.assertEqual( SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, NINF, CL), CL).normalized(), emptySpanningInterval) self.assertEqual( SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, PINF, 3, CL), CL).normalized(), emptySpanningInterval)
def testNoApproach(self): model = Model([ ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 0, 3, CL), Interval(CL, 0, 3, CL), CL)), ]) result = inference( model, AndR(Not(overlaps(stub_model.Close("figure", "landmark"))), [equals], Tense([iMeets], stub_model.Close("figure", "landmark")))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(OP, NINF, 0, OP), Interval(CL, 0, 0, CL), OP), SpanningInterval(OP, Interval(OP, NINF, 0, OP), Interval(CL, 0, 0, CL), OP) ])) self.assertEqual(result.snappedToMin(0), emptySpanningIntervalSet)
def testInferenceOr(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 2, 3, CL), Interval(CL, 2, 3, CL), CL)), ModelEntry( Following("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)) ]) result = inference(model, stub_model.Visible("figure", "landmark")) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(True, Interval(True, 1.0, 3.0, True), Interval(True, 1.0, 3.0, True), True) ])) result = inference( model, Or(stub_model.Visible("figure", "landmark"), stub_model.Following("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(True, Interval(True, 1.0, 3.0, True), Interval(True, 1.0, 3.0, True), True) ])) result = inference( model, Or(stub_model.Close("figure", "landmark"), stub_model.Following("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, 3.0, CL), CL) ]))
def testSpan(self): self.assertEqual( SpanningInterval.span( SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 1, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 1, CL), CL)), SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 1, CL), CL) ])) self.assertEqual( SpanningInterval.span( SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 1, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 2, CL), CL)).condensed(), SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 2, CL), CL) ])) self.assertEqual( SpanningInterval.span( SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 0, 1, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, -1, 2, CL), CL)).condensed(), SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, -1, 2, CL), CL) ])) self.assertEqual( SpanningInterval.span( SpanningInterval(CL, Interval(CL, 0, 1, OP), Interval(CL, 0, 1, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, -1, 2, CL), CL)).condensed(), SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, -1, 2, CL), CL) ]))
def testOverlaps(self): model = Model([ ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ]) result = inference( model, Not(overlaps(stub_model.Visible("figure", "landmark")))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), CL) ])) result = inference(model, overlaps(stub_model.Close("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ])) result = inference( model, Not(overlaps(stub_model.Close("figure", "landmark")))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, CL), OP), SpanningInterval(OP, Interval(CL, 3.0, PINF, OP), Interval(OP, 3.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, CL), OP), SpanningInterval(CL, Interval(OP, 3.0, PINF, OP), Interval(OP, 3.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, OP), CL), SpanningInterval(OP, Interval(CL, 3.0, PINF, OP), Interval(OP, 3.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, 1.0, OP), CL), SpanningInterval(CL, Interval(OP, 3.0, PINF, OP), Interval(OP, 3.0, PINF, OP), CL) ]))
def testContainsInterval(self): si = SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL) self.assertEqual(si.containsInterval(Interval(CL, 0.5, 2.5, CL)), True)
def testUnion1(self): si1 = SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), CL) si2 = SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL) self.containment(si1, si2, isProperSubset=False, isSuperset=False) self.assertEqual(si1.containsInterval(Interval(CL, 1, 1, CL)), False) self.assertEqual(si2.containsInterval(Interval(CL, 1, 1, CL)), True) csi1 = si1.complement() interval = csi1.intersectInterval(si2) self.assertEqual( SpanningInterval.union(si1, si2), SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ])) self.assertEqual( SpanningInterval.union( SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL)), SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL) ]))
def testInferenceNot(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 2, 3, CL), Interval(CL, 2, 3, CL), CL)), ModelEntry( Following("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)) ]) result = inference(model, Not(stub_model.Visible("figure", "landmark"))) print "result", result self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP) ]))
def testTenseAndStarts(self): model = Model([ ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ]) result = inference( model, Tense([starts], stub_model.Close("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), CL) ])) result = inference( model, Tense([iStarts], stub_model.Close("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL) ])) result = inference( model, Tense([starts, iStarts], stub_model.Close("figure", "landmark"))) self.assertEqual( result.condensed(), SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ]))
def testInferenceNotEmpty(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)) ]) result = inference(model, stub_model.Visible("figure", "landmark")) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL) ])) complement = result[0].complement() self.assertEqual( complement, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, NINF, PINF, CL), Interval(CL, NINF, 1.0, OP), CL), SpanningInterval(CL, Interval(CL, NINF, PINF, CL), Interval(OP, 3.0, PINF, CL), CL), SpanningInterval(CL, Interval(CL, NINF, 1.0, OP), Interval(CL, NINF, PINF, CL), CL), SpanningInterval(CL, Interval(OP, 3.0, PINF, CL), Interval(CL, NINF, PINF, CL), CL), SpanningInterval(OP, Interval(CL, NINF, PINF, CL), Interval(CL, NINF, PINF, CL), CL), SpanningInterval(CL, Interval(CL, NINF, PINF, CL), Interval(CL, NINF, PINF, CL), OP), SpanningInterval(OP, Interval(CL, NINF, PINF, CL), Interval(CL, NINF, PINF, CL), OP) ])) result = inference(model, Not(stub_model.Visible("figure", "landmark"))) self.assertEqual(result, SpanningIntervalSet(complement).condensed())
def testSnapToZero(self): self.assertEqual( Interval(CL, NINF, 1, OP).snappedToMin(value=0), Interval(CL, 0, 1, OP))
def testNormalizeNoop(self): si = SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL) nsi = si.normalized() self.assertEqual(si, nsi)
def testCondense(self): setFromInference = SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL) ]) self.assertEqual( setFromInference.condensed(), SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ])) self.assertEqual( SpanningIntervalSet([ SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP) ]).condensed(), SpanningIntervalSet([ SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, NINF, PINF, OP), OP) ])) sis = SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 1, OP), Interval(OP, NINF, 1, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 1, OP), Interval(OP, NINF, 1, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 1, OP), Interval(OP, NINF, 1, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 1, OP), Interval(OP, NINF, 1, OP), CL), SpanningInterval(OP, Interval(OP, 3, PINF, OP), Interval(OP, 3, PINF, OP), OP), SpanningInterval(OP, Interval(OP, 3, PINF, OP), Interval(OP, 3, PINF, OP), CL), SpanningInterval(CL, Interval(OP, 3, PINF, OP), Interval(OP, 3, PINF, OP), OP), SpanningInterval(CL, Interval(OP, 3, PINF, OP), Interval(OP, 3, PINF, OP), CL) ]) self.assertEqual(sis.condensed(), sis) sis = SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL) ]) self.assertEqual( sis.condensed(), SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ])) self.assertEqual( SpanningIntervalSet([ SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL), SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), CL), SpanningInterval(CL, Interval(OP, 1.0, 3.0, CL), Interval(OP, 1.0, 3.0, CL), CL), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(OP, Interval(OP, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, OP), CL), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL) ]).condensed(), SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ]))
def testEqual(self): self.assertEqual( SpanningInterval(CL, Interval(CL, 0, NINF, CL), Interval(CL, 2, 3, CL), CL), SpanningInterval(CL, Interval(CL, 0, NINF, CL), Interval(CL, 2, 3, CL), CL))
def testContainsSubset(self): self.containment(SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL), isProperSubset=False, isSuperset=False) self.containment(SpanningInterval(CL, Interval(OP, 0, 1, CL), Interval(CL, 2, 3, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL), isProperSubset=True, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 0, 1, OP), Interval(CL, 2, 3, CL), CL), SpanningInterval(CL, Interval(OP, 0, 1, OP), Interval(CL, 2, 3, CL), CL), isProperSubset=False, isSuperset=True) self.containment(SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(OP, 2, 3, CL), CL), SpanningInterval(CL, Interval(OP, 0, 1, OP), Interval(CL, 2, 3, CL), CL), isProperSubset=False, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(OP, 2, 3, CL), CL), SpanningInterval(CL, Interval(OP, 10, 11, OP), Interval(CL, 12, 13, CL), CL), isProperSubset=False, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(OP, 2, 3, CL), CL), SpanningInterval(OP, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL), isProperSubset=False, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(OP, 2, 3, CL), CL), SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), OP), isProperSubset=False, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 0.0, 1.0, CL), Interval(CL, 0.0, 1.0, CL), CL), SpanningInterval(CL, Interval(CL, 0.0, 1.0, CL), Interval(CL, 0.0, 2.0, CL), CL), isProperSubset=True, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), isProperSubset=True, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 1.0, 1.0, CL), Interval(CL, 1.0, 1.0, CL), CL), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL), isProperSubset=True, isSuperset=False) self.containment(SpanningInterval(CL, Interval(CL, 1.0, 1.0, CL), Interval(CL, 1.0, 1.0, CL), CL), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(CL, 1.0, 3.0, OP), CL), isProperSubset=True, isSuperset=False)
def testInferenceTense(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ModelEntry( Close("figure", "landmark"), SpanningInterval(CL, Interval(CL, 2, 3, CL), Interval(CL, 2, 3, CL), CL)), ModelEntry( Following("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)) ]) result = inference( model, Tense([allenRelations.finishes], stub_model.Visible("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, 3.0, CL), CL) ])) result = inference( model, Tense([allenRelations.overlaps], stub_model.Visible("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, 1.0, 3.0, CL), Interval(OP, 1.0, PINF, OP), CL) ])) result = inference(model, overlaps(stub_model.Visible("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(OP, 1.0, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, 3.0, CL), Interval(CL, 1.0, PINF, OP), CL) ]))
def testRelations(self): self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 1, CL), Interval(CL, 1, 2, CL)), allenRelations.overlaps) self.assertEqual(allenRelations.findRelation(Interval(CL, 1, 2, CL), Interval(CL, 0, 1, CL)), allenRelations.iOverlaps) self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 1.5, CL), Interval(CL, 1, 2, CL)), allenRelations.overlaps) self.assertEqual(allenRelations.findRelation(Interval(CL, 1, 2, CL), Interval(CL, 0, 1.5, CL)), allenRelations.iOverlaps) self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 1.5, CL), Interval(CL, 0, 0.1, CL)), allenRelations.iStarts) self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 0.1, CL), Interval(CL, 0, 1.5, CL)), allenRelations.starts) self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 0.1, CL), Interval(CL, 0.5, 1.5, CL)), allenRelations.lessThan) self.assertEqual(allenRelations.findRelation(Interval(CL, 0.5, 1.5, CL), Interval(CL, 0, 0.1, CL)), allenRelations.greaterThan) self.assertEqual(allenRelations.findRelation(Interval(CL, 0.5, 1, CL), Interval(CL, 0, 1, CL)), allenRelations.finishes) self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 1, CL), Interval(CL, 0.5, 1, CL)), allenRelations.iFinishes) self.assertEqual(allenRelations.findRelation(Interval(CL, 0.5, 0.75, CL), Interval(CL, 0, 1, CL)), allenRelations.during) self.assertEqual(allenRelations.findRelation(Interval(CL, 0, 1, CL), Interval(CL, 0.5, 0.75, CL)), allenRelations.iDuring)
def testInferenceNotEmpty1(self): model = Model([ ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ModelEntry( Visible("figure", "landmark"), SpanningInterval(OP, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), OP)), ModelEntry( Visible("figure", "landmark"), SpanningInterval(CL, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), OP)), ModelEntry( Visible("figure", "landmark"), SpanningInterval(OP, Interval(CL, 1, 3, CL), Interval(CL, 1, 3, CL), CL)), ]) result = inference(model, stub_model.Visible("figure", "landmark")) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1.0, 3.0, CL), Interval(CL, 1.0, 3.0, CL), CL), SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(CL, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), OP), SpanningInterval(OP, Interval(CL, 1.0, 3.0, OP), Interval(OP, 1.0, 3.0, CL), CL) ])) result = inference(model, Not(stub_model.Visible("figure", "landmark"))) self.assertEqual( result, SpanningIntervalSet([ SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), CL), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), CL), SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(CL, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(OP, NINF, PINF, OP), OP), SpanningInterval(OP, Interval(OP, NINF, PINF, OP), Interval(OP, 3.0, PINF, OP), OP) ]))