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 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 testFollow(self): map_fn = "%s/data/directions/direction_floor_3/direction_floor_3_small_filled.cmf" % TKLIB_HOME cluster_fn = "%s/data/directions/direction_floor_3/skels/direction_floor_3_skel.pck" % TKLIB_HOME gtruth_tag_fn = "%s/data/directions/direction_floor_3/tags/df3_small_tags.tag" % TKLIB_HOME assignment_fn = "%s/nlp/data/aaai_2010_smv/stefie10/assignment1.1.yaml" % TKLIB_HOME tagFile = tag_util.tag_file(gtruth_tag_fn, map_fn) tagFile.get_map() tagFile.get_tag_names() skeleton = carmen_map_skeletonizer.load(cluster_fn, map_fn) assignment = Assignment.load(assignment_fn, tagFile, skeleton) slowEntry = assignment.entries[0] model = modelForSituation(slowEntry.situation) print "model", model results = inference(model, following("figure", "landmark")) self.assertEqual( results, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 1100.0, 5700.0, OP), Interval(OP, 1100.0, 5700.0, CL), OP), SpanningInterval(CL, Interval(CL, 6200.0, 15900.0, OP), Interval(OP, 6200.0, 15900.0, CL), OP), SpanningInterval(CL, Interval(CL, 16000.0, 21000.0, OP), Interval(OP, 16000.0, 21000.0, CL), OP) ]))
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 inference(model, expression): """ Perform inference, finding the set of intervals where expression is true in model """ if isinstance(expression, Primitive): results = [] for entry in model.entries: if entry.primitive == expression: results.append(entry.spanningInterval) elif isinstance(expression, Or): results = [] results.extend(inference(model, expression.e1)) results.extend(inference(model, expression.e2)) elif isinstance(expression, Not): results = [] iprimes = [ i.complement().condensed() for i in inference(model, expression.e) ] indices = [0 for x in iprimes] if len(iprimes) == 0: return allIntervals cnt = 0 while indices[0] < len(iprimes[0]): #print "indices", indices currentArgs = [] for i, j in enumerate(indices): currentArgs.append(iprimes[i][j]) result = currentArgs[0] for interval in currentArgs[1:]: result = SpanningInterval.intersection(result, interval) #print "result", result results.append(result) for i, idx in reversed(list(enumerate(indices))): newIdx = idx + 1 indices[i] = idx + 1 if indices[i] >= len(iprimes[i]) and i != 0: indices[i] = 0 else: break elif isinstance(expression, AndR): results = [] for i in inference(model, expression.e1): for j in inference(model, expression.e2): for r in expression.allenRelations: results.extend(SpanningInterval.I(i, r, j)) elif isinstance(expression, Tense): results = [] for i in inference(model, expression.e): for relation in expression.allenRelations: results.extend(i.D(relation)) else: raise ValueError("Unexpected type for " + ` expression `) return SpanningIntervalSet(results).condensed()
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 run(): results = inference(model, approach("figure", "landmark")) print "results", results self.assertEqual( results, SpanningIntervalSet([ SpanningInterval(CL, Interval(CL, 0.0, 3600.0, CL), Interval(CL, 3600.0, 6300.0, CL), OP), SpanningInterval(CL, Interval(CL, 6300.0, 24800.0, CL), Interval(CL, 24800.0, 31800.0, CL), OP) ]))
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 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 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 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 testEqual(self): sis = SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL) ]) self.assertEqual(sis, sis, True)
def destIntersect(self): """ erased intersect because it's hard to implement correctly """ sis = SpanningIntervalSet([ SpanningInterval(OP, Interval(OP, NINF, 3.0, OP), Interval(CL, 1.0, PINF, OP), CL) ]) self.assertEqual(sis, sis.intersect(sis))
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 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 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 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 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 testSomething(self): si1 = SpanningInterval(CL, Interval(OP, NINF, 1.0, OP), Interval(CL, 1.0, 1.0, CL), OP) si2 = SpanningInterval(OP, Interval(OP, NINF, 1.0, OP), Interval(CL, 1.0, 1.0, CL), OP) self.assertEquals(si1.containsInterval(Interval(CL, 0, 1, OP)), True) self.assertNotEqual(si1, emptySpanningInterval) self.assertNotEqual(si1.normalized(), emptySpanningInterval) print "si1", si1.normalized() sis = SpanningIntervalSet([si1, si2])
def containment(self, i1, i2, isProperSubset, isSuperset): try: self.assertEqual(i1.properSubset(i2), isProperSubset) if i1.properSubset(i2): self.assertEqual(i1.subset(i2), True) if i2.properSubset(i1): self.assertEqual(i2.subset(i1), True) if i1 == i2: self.assertEqual(isProperSubset, False) self.assertEqual(isSuperset, False) self.assertEqual(i1.subset(i2), True) self.assertEqual(i2.subset(i1), True) self.assertEqual(i1.properSubset(i2), False) self.assertEqual(i1.superset(i2), False) self.assertEqual(SpanningInterval.intersection(i1, i2), i1) self.assertEqual(SpanningInterval.intersection(i1, i2), i2) else: if isProperSubset or isSuperset: self.assertEqual(i1.properSubset(i2), isProperSubset) self.assertEqual(i2.properSubset(i1), not isProperSubset) self.assertEqual(i1.superset(i2), not isProperSubset) self.assertEqual(i1.superset(i2), isSuperset) self.assertEqual(i2.superset(i1), isProperSubset) if isProperSubset: self.assertEqual(SpanningInterval.intersection(i1, i2), i1) self.assertEqual(SpanningInterval.intersection(i2, i1), i1) if isSuperset: self.assertEqual(SpanningInterval.intersection(i1, i2), i2) self.assertEqual(SpanningInterval.intersection(i2, i1), i2) else: self.assertEqual(i1.properSubset(i2), False) self.assertEqual(i2.properSubset(i1), False) self.assertEqual(i1.superset(i2), False) self.assertEqual(i2.superset(i1), False) except: print "i1", i1 print "i2", i2 print "isProperSubset", isProperSubset print "isSuperset", isSuperset raise
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 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 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 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 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 testNormalizeNoop(self): si = SpanningInterval(CL, Interval(CL, 0, 1, CL), Interval(CL, 2, 3, CL), CL) nsi = si.normalized() self.assertEqual(si, nsi)
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 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 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)