def test_unifies_annotated(self): X = pyson.Var() Y = pyson.Var() foo_a = pyson.Literal("foo", (), ("a", )) foo_ab = pyson.Literal("foo", (), ("a", "b")) foo_XY = pyson.Literal("foo", (), (X, Y)) foo_XX = pyson.Literal("foo", (), (X, X)) self.assertTrue(pyson.unifies_annotated(foo_a, foo_ab)) self.assertTrue(pyson.unifies_annotated(foo_a, foo_XY)) self.assertTrue(pyson.unifies_annotated(foo_a, foo_XX)) self.assertTrue(pyson.unifies_annotated(foo_ab, foo_XY)) self.assertTrue(pyson.unifies_annotated(foo_XY, foo_ab)) self.assertTrue(pyson.unifies_annotated(foo_XX, foo_ab)) self.assertTrue(pyson.unifies_annotated(foo_XX, foo_ab)) self.assertFalse(pyson.unifies_annotated(foo_ab, foo_XX)) self.assertFalse(pyson.unifies_annotated(foo_XY, foo_a))
def test_concat_lists(self): env = pyson.runtime.Environment() agent = pyson.runtime.Agent(env, "agent") intention = pyson.runtime.Intention() X = pyson.Var() term = pyson.Literal(".concat", ((1, 2), (3, ), X)) next(pyson.stdlib._concat(agent, term, intention)) self.assertEqual(X.grounded(intention.scope), (1, 2, 3))
def test_concat_strings(self): env = pyson.runtime.Environment() agent = pyson.runtime.Agent(env, "agent") intention = pyson.runtime.Intention() X = pyson.Var() term = pyson.Literal(".concat", ("hello", " ", "world", X)) next(pyson.stdlib._concat(agent, term, intention)) self.assertEqual(X.grounded(intention.scope), "hello world")
def test_unifies(self): self.assertFalse(pyson.unifies(True, 1)) self.assertTrue(pyson.unifies(3, 3.0)) self.assertTrue(pyson.unifies(True, True)) self.assertTrue(pyson.unifies(5, pyson.Wildcard())) self.assertTrue(pyson.unifies((1, 2), (1, pyson.Wildcard()))) self.assertTrue(pyson.unifies(("hello", 2), ("hello", pyson.Var()))) self.assertTrue(pyson.unifies(pyson.Var(), pyson.Literal("beep"))) self.assertTrue(pyson.unifies(pyson.Literal("boop"), pyson.Var())) X = pyson.Var() self.assertTrue( pyson.unifies(pyson.Literal("foo", (X, X)), pyson.Literal("foo", (1, 1)))) self.assertFalse( pyson.unifies(pyson.Literal("bar", (X, X)), pyson.Literal("bar", (1, 2))))
def visit_variable(self, ast_variable): try: return self.variables[ast_variable.name] except KeyError: if ast_variable.name == "_": var = pyson.Wildcard() else: var = pyson.Var() self.variables[ast_variable.name] = var return var
def test_request_action(self): agent = pyson.mapc2017.Agent() with open(os.path.join(os.path.dirname(__file__), "request-action.xml")) as xml: agent.message_received(etree.parse(xml).getroot()) term = pyson.Literal("money", (50000, )) intention = pyson.runtime.Intention() self.assertTrue(agent.test_belief(term, intention)) term = pyson.Literal("shop", ("shop1", 48.8217, 2.33207, 4, pyson.Var())) intention = pyson.runtime.Intention() self.assertTrue(agent.test_belief(term, intention)) agent.dump()