diff --git a/python/sandbox/bhv_binding/01_example_majority.metta b/python/sandbox/bhv_binding/01_example_majority.metta new file mode 100644 index 000000000..1949ac883 --- /dev/null +++ b/python/sandbox/bhv_binding/01_example_majority.metta @@ -0,0 +1,12 @@ +!(extend-py! bhv_binding) + +!(bind! &a (bhv-new)) +!(bind! &b (bhv-new)) +!(bind! &c (bhv-new)) + +!(bind! &abc (bhv-majority &a &b &c )) + +!(bhv-std-apart-relative &a &abc) +!(bhv-is-related &a &abc) + + diff --git a/python/sandbox/bhv_binding/02_example_perm.metta b/python/sandbox/bhv_binding/02_example_perm.metta new file mode 100644 index 000000000..4e1a172b6 --- /dev/null +++ b/python/sandbox/bhv_binding/02_example_perm.metta @@ -0,0 +1,21 @@ +!(extend-py! bhv_binding) + +!(bind! &a (bhv-new)) +!(bind! &b (bhv-new)) + +!(bind! &perm1 (bhv-new-perm)) +(= (perm1 $x) (bhv-apply-perm &perm1 $x)) + +!(bind! ab (bhv-majority &a &b )) + +; Should return False since a is permuted but ab is not permuted +!(bhv-is-related (perm1 &a) ab) + +;Should return True +!(bhv-is-related (perm1 &a) (perm1 ab)) + + + + + + diff --git a/python/sandbox/bhv_binding/03_example_dict.metta b/python/sandbox/bhv_binding/03_example_dict.metta new file mode 100644 index 000000000..4d9f85367 --- /dev/null +++ b/python/sandbox/bhv_binding/03_example_dict.metta @@ -0,0 +1,17 @@ +!(extend-py! bhv_binding) + +!(bind! &v1 (bhv-new)) +!(bind! &v2 (bhv-new)) +!(bind! &v3 (bhv-new)) +!(bind! &k1 (bhv-new)) +!(bind! &k2 (bhv-new)) +!(bind! &k3 (bhv-new)) + + +!(bind! dict (bhv-majority (bhv-bind &v1 &k1) (bhv-bind &v2 &k2) (bhv-bind &v3 &k3) )) +!(bind! v1_retrived (bhv-bind &k1 dict)) + +!(bhv-std-apart-relative v1_retrived &v1) +!(bhv-is-related v1_retrived &v1) + + diff --git a/python/sandbox/bhv_binding/04_example_dollar_of_mexico.metta b/python/sandbox/bhv_binding/04_example_dollar_of_mexico.metta new file mode 100644 index 000000000..2c2474300 --- /dev/null +++ b/python/sandbox/bhv_binding/04_example_dollar_of_mexico.metta @@ -0,0 +1,32 @@ +!(extend-py! bhv_binding) + +!(bind! &name (bhv-new)) +!(bind! &capital_city (bhv-new)) +!(bind! &money (bhv-new)) +!(bind! &united_states (bhv-new)) +!(bind! &washington_dc (bhv-new)) +!(bind! &dollar (bhv-new)) +!(bind! &mexico (bhv-new)) +!(bind! &mexico_city (bhv-new)) +!(bind! &peso (bhv-new)) + + +!(bind! USA (bhv-majority (bhv-bind &name &united_states) (bhv-bind &capital_city &washington_dc) (bhv-bind &money &dollar) )) +!(bind! MEX (bhv-majority (bhv-bind &name &mexico) (bhv-bind &capital_city &mexico_city) (bhv-bind &money &peso) )) + +!(bind! Pair (bhv-bind USA MEX)) + +; should return True here +!(bhv-is-related (bhv-bind USA &money) &dollar) + + +!(bind! dollar_of_mexico (bhv-bind &dollar Pair)) + +; should return True here. "Dollar of mexico" is peso +!(bhv-is-related dollar_of_mexico &peso) + + + + + + diff --git a/python/sandbox/bhv_binding/bhv_binding.py b/python/sandbox/bhv_binding/bhv_binding.py new file mode 100644 index 000000000..0edbb3b9f --- /dev/null +++ b/python/sandbox/bhv_binding/bhv_binding.py @@ -0,0 +1,16 @@ +from hyperon.atoms import OperationAtom +from hyperon.ext import register_atoms +from bhv.np import NumPyBoolBHV as BHV, NumPyBoolPermutation as Perm + + +@register_atoms +def my_atoms(): + return { + 'bhv-new': OperationAtom('bhv-new', BHV.rand), + 'bhv-majority': OperationAtom('bhv-majority', lambda *args: BHV.majority(list(args))), + 'bhv-bind': OperationAtom('bhv-bind', lambda a,b: a^b), + 'bhv-std-apart-relative': OperationAtom('bhv-std-apart-relative', lambda a,b: a.std_apart(b, relative = True)), + 'bhv-is-related': OperationAtom('bhv-is-related', lambda a,b: a.related(b)), + 'bhv-new-perm': OperationAtom('bhv-perm', Perm.random), + 'bhv-apply-perm': OperationAtom('bhv-apply-perm', lambda a, b: a(b)) + }