forked from trueagi-io/hyperon-experimental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pln_tv.py
47 lines (42 loc) · 1.76 KB
/
test_pln_tv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import unittest
from hyperon import *
from test_common import HyperonTestCase
class PLNTVTest(HyperonTestCase):
def test_fuzzy_conjunction_fn(self):
metta = MeTTa(env_builder=Environment.test_env())
# `stv` as a mix of function and constructor
# working through ordinary equalities
metta.run('''
(= (min $a $b) (if (< $a $b) $a $b))
(= (s-tv (stv $s $c)) $s)
(= (c-tv (stv $s $c)) $c)
(= (stv (And $a $b))
(stv (min (s-tv (stv $a)) (s-tv (stv $b)))
(min (c-tv (stv $a)) (c-tv (stv $b)))))
(= (stv (P A)) (stv 0.5 0.8))
(= (stv (P B)) (stv 0.3 0.9))
''')
# JIC, if somebody wants "type annotations"
metta.run('''
(: A Concept)
(: B Concept)
(: P Predicate)
''')
self.assertEqualMettaRunnerResults(
metta.run('!(stv (And (P A) (P B)))'),
[metta.parse_all('(stv 0.3 0.8)')])
metta.run('''
(= (pln $expr) ($expr (stv $expr)))
''')
# Here, we successfully retrieve $x. It doesn't work for "declarative" .tv
# in c3_pln_stv.metta (e.g. `(pln (green $x))` will not substitute $x in the result`),
# but "functional" stv cannot process implications without `match` (see also b2_backchain.metta)`
# (would actually count (stv (P A)) twice for probabilistic version)
self.assertEqualMettaRunnerResults(
metta.run('!(pln (And (P A) (P $x)))'),
[metta.parse_all('''
((And (P A) (P A)) (stv 0.5 0.8))
((And (P A) (P B)) (stv 0.3 0.8))
''')])
if __name__ == "__main__":
unittest.main()