Some of these methods are unused.
Chris Pressey
6 years ago
63 | 63 |
return False
|
64 | 64 |
return True
|
65 | 65 |
|
66 | |
def contains(self, other):
|
67 | |
if self == other:
|
68 | |
return True
|
69 | |
for st in self.subterms:
|
70 | |
if st.contains(other):
|
71 | |
return True
|
72 | |
return False
|
73 | |
|
74 | |
def replace(self, old, new):
|
75 | |
if self == old:
|
76 | |
return new
|
77 | |
else:
|
78 | |
return Term(self.constructor, subterms=[subterm.replace(old, new) for subterm in self.subterms])
|
79 | |
|
80 | 66 |
def match(self, term, unifier):
|
81 | 67 |
if self.constructor != term.constructor:
|
82 | 68 |
raise ValueError("`%s` != `%s`" % (self.constructor, term.constructor))
|
22 | 22 |
|
23 | 23 |
self.assertEqual(t2, Term('actor', subterms=[Term('alice')]))
|
24 | 24 |
|
25 | |
def test_term_replace(self):
|
|
25 |
def test_term_match_ground(self):
|
|
26 |
t1 = Term('actor', subterms=[Term('alice')])
|
|
27 |
p1 = Term('actor', subterms=[Term('alice')])
|
|
28 |
u = {}
|
|
29 |
p1.match(t1, u)
|
|
30 |
self.assertEqual(u, {})
|
|
31 |
|
|
32 |
def test_term_no_match_ground(self):
|
|
33 |
t1 = Term('actor', subterms=[Term('alice')])
|
|
34 |
p1 = Term('actor', subterms=[Term('bob')])
|
|
35 |
u = {}
|
|
36 |
with self.assertRaises(ValueError):
|
|
37 |
p1.match(t1, u)
|
|
38 |
self.assertEqual(u, {})
|
|
39 |
|
|
40 |
def test_term_match_bind_var(self):
|
|
41 |
t1 = Term('actor', subterms=[Term('alice')])
|
|
42 |
p1 = Term('actor', subterms=[Var('?A')])
|
|
43 |
u = {}
|
|
44 |
p1.match(t1, u)
|
|
45 |
self.assertEqual(u, {u'?A': Term('alice')})
|
|
46 |
|
|
47 |
def test_term_subst(self):
|
26 | 48 |
t = Term('actor', subterms=[Var('?A')])
|
27 | |
r = t.replace(Var('?A'), Term('alice'))
|
|
49 |
r = t.subst({u'?A': Term('alice')})
|
28 | 50 |
self.assertEqual(r, Term('actor', subterms=[Term('alice')]))
|
29 | 51 |
|
30 | 52 |
|