Exemple #1
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)
            ]))
Exemple #2
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)
Exemple #3
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)
            ]))
Exemple #4
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())
Exemple #5
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)
            ]))
Exemple #6
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)
            ]))
Exemple #7
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)
            ]))
Exemple #8
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)
            ]))