Пример #1
0
 def test_unify_terms3(self):
     t1 = ('term', 'teacher', [('term', 'sokrates', []),
                               ('term', 'plato', [])])
     t2 = ('term', 'teacher', [('var', 'X'), ('var', 'Y')])
     exp = {'X': ('term', 'sokrates', []), 'Y': ('term', 'plato', [])}
     act = unify(t1, t2, {})
     self.assertEqual(act, exp)
Пример #2
0
 def test_unifyc_rhea(self):
     t1 = ('term', 'parent', [('var', 'Y'), ('var', 'Z')])
     t2 = ('term', 'parent', [('term', 'zeus', []), ('term', 'rhea', [])])
     mgu = {
         # 'X': ('term', 'zeus', []),
         'Y': ('term', 'chronos', [])
     }
     exp = None
     act = unify(t1, t2, mgu)
     self.assertEqual(act, exp)
Пример #3
0
def _solve(db, qry, mgu, indent):
    for hd, tl in db:
        # Copy original MGU. For each fact or rule in the DB start with
        # the same MGU.
        mguc = deepcopy(mgu)
        # Unify the head. If it is a fact, we are done at this point.
        mguc = unify(hd, qry, mguc)
        # If unification failed, continue with the next fact or rule.
        if mguc is None:
            # print(' ' * indent, 'FAIL ', prettify_rule(hd, tl))
            continue
        yield from _solve_conjuction(db, tl, mguc, indent + 2)
Пример #4
0
 def test_unify_fail_terms1(self):
     t1 = ('term', 'sokrates', [])
     t2 = ('term', 'plato', [])
     exp = None
     act = unify(t1, t2, {})
     self.assertEqual(act, exp)
Пример #5
0
 def test_unify_same_vars(self):
     t1 = ('var', 'X')
     t2 = ('var', 'X')
     exp = {}
     act = unify(t1, t2, {})
     self.assertEqual(act, exp)
Пример #6
0
 def test_unify_terms2(self):
     t1 = ('term', 'human', [('term', 'sokrates', [])])
     t2 = ('term', 'human', [('var', 'X')])
     exp = {'X': ('term', 'sokrates', [])}
     act = unify(t1, t2, {})
     self.assertEqual(act, exp)
Пример #7
0
 def test_unify_terms0(self):
     t1 = ('term', 'sokrates', [])
     t2 = ('term', 'sokrates', [])
     exp = {}
     act = unify(t1, t2, {})
     self.assertEqual(act, exp)
Пример #8
0
 def test_unify_different_vars2(self):
     t1 = ('var', 'Y')
     t2 = ('var', 'X')
     exp = {'X': ('var', 'Y')}
     act = unify(t1, t2, {})
     self.assertEqual(act, exp)