Пример #1
0
    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)
            ]))
Пример #2
0
    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)
            ]))
Пример #3
0
 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))
Пример #4
0
    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)
            ]))
Пример #5
0
    def testEq(self):
        print "eq empty"
        self.assertEqual(emptySpanningIntervalSet, emptySpanningIntervalSet)
        print "neq empty"
        self.assertEqual(emptySpanningIntervalSet != emptySpanningIntervalSet,
                         False)

        print "eq con"
        self.assertEqual(emptySpanningIntervalSet, SpanningIntervalSet([]))
        print "neq con"
        self.assertEqual(emptySpanningIntervalSet != SpanningIntervalSet([]),
                         False)
Пример #6
0
    def testNormal(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[27]

        model = modelForSituation(slowEntry.situation)
        print "model", model

        results = inference(model, Inverted(IsClose("figure", "landmark")))
        self.assertEqual(
            results,
            SpanningIntervalSet([
                SpanningInterval(CL, Interval(CL, 0.0, 23500.0, OP),
                                 Interval(OP, 0.0, 23500.0, CL), OP)
            ]) != SpanningIntervalSet([
                SpanningInterval(CL, Interval(CL, 0.0, 23600.0, OP),
                                 Interval(OP, 0.0, 23600.0, CL), OP)
            ]))

        results = inference(model, IsClose("figure", "landmark"))
        self.assertEqual(
            results,
            SpanningIntervalSet([
                SpanningInterval(CL, Interval(CL, 23600.0, 28500.0, CL),
                                 Interval(CL, 23600.0, 28500.0, CL), OP)
            ]))

        results = inference(model, approach("figure", "landmark"))
        print "results", results
        self.assertEqual(
            results,
            SpanningIntervalSet([
                SpanningInterval(CL, Interval(CL, 0.0, 23600.0, CL),
                                 Interval(CL, 23600.0, 28500.0, CL), OP)
            ]))

        results = inference(model, following("figure", "landmark"))
        print "results", results
        self.assertEqual(results, emptySpanningIntervalSet)
Пример #7
0
    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)
            ]))
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
 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)
Пример #11
0
    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)
            ]))
Пример #12
0
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()
Пример #13
0
    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)
            ]))
Пример #14
0
    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())
Пример #15
0
    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)
            ]))
Пример #16
0
 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)
         ]))
Пример #17
0
    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)
            ]))
Пример #18
0
    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])
Пример #19
0
    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)
Пример #20
0
    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)
            ]))
Пример #21
0
    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)
            ]))
Пример #22
0
    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)
            ]))
Пример #23
0
    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)
            ]))