Example #1
0
class ConceptualExpressionRules(unittest.TestCase):
    def setUp(self):
        n = basic_learner.FiniteSymbolTable()
        n.add("john", "john")
        n.add("catches", {"CAUSE", "GO", "TO"})
        n.add("the", set())
        n.add("ball", "ball")

        p = basic_learner.FiniteSymbolTable()
        p.add("john", "john")
        p.add("catches", {"CAUSE", "GO", "TO"})
        p.add("the", set())
        p.add("ball", "ball")

        self.learner = basic_learner.NPSymbolLearner(necessary=n, possible=p)
        self.hypothesis = Hypothesis(["CAUSE", "john", ["GO", "ball", ["TO", "john"]]])

    def testEmptyTerms(self):
        utm_pair = training.pairs.UtteranceMeaningPair("the", {self.hypothesis})
        self.learner._rule5(utm_pair)
        self.assertEqual(self.learner.expressions["the"], {BottomExpression()})

    def testVariableTerms(self):
        utm_pair = training.pairs.UtteranceMeaningPair("john", {self.hypothesis})
        self.assertTrue(self.learner.expressions["john"])
        self.learner._rule5(utm_pair)
        self.assertIn("john", self.learner.expressions["john"])
        self.assertNotIn("ball", self.learner.expressions["john"])

        utm_pair2 = training.pairs.UtteranceMeaningPair("ball", {self.hypothesis})
        self.learner._rule5(utm_pair2)
        self.assertIn("ball", self.learner.expressions["ball"])
        self.assertNotIn("john", self.learner.expressions["ball"])

    def testConstantTerms(self):
        subexpressions = self.hypothesis.subexpressions_for_constants({"GO", "TO"})

        for expression in subexpressions:
           self.assertIn("GO", expression)
           self.assertIn("TO", expression)
           self.assertNotIn("CAUSE", expression)

    def testRule5(self):
        self.assertIn("john", self.learner.expressions["catches"] ) # arbitrary membership; universal
        utm_pair = training.pairs.UtteranceMeaningPair("catches", {self.hypothesis})

        self.learner._rule5(utm_pair)

        for expression in self.learner.expressions["catches"]:
            self.assertIn("GO", expression)
            self.assertIn("TO", expression)
            self.assertIn("CAUSE", expression)

    def testGeneralConstantTerms(self):
        general = self.hypothesis.bound_expression.general_form()
        self.assertEqual(general,
                         training.hypothesis.Hypothesis(["CAUSE", "x", "x"]).bound_expression)
        print general
Example #2
0
    def setUp(self):
        n = basic_learner.FiniteSymbolTable()
        n.add("john", "john")
        n.add("catches", {"CAUSE", "GO", "TO"})
        n.add("the", set())
        n.add("ball", "ball")

        p = basic_learner.FiniteSymbolTable()
        p.add("john", "john")
        p.add("catches", {"CAUSE", "GO", "TO"})
        p.add("the", set())
        p.add("ball", "ball")

        self.learner = basic_learner.NPSymbolLearner(necessary=n, possible=p)
        self.hypothesis = Hypothesis(["CAUSE", "john", ["GO", "ball", ["TO", "john"]]])