Skip to content

Commit

Permalink
Update: nalifier added
Browse files Browse the repository at this point in the history
  • Loading branch information
patham9 committed Sep 13, 2023
1 parent 94d0fcb commit 784a14b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions nalifier/input.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(((duck --> ([ yellow ])) (1.0 0.9)) (1))
(((duck --> ([ small ])) (1.0 0.9)) (2))
(((duck --> ([ feathered ])) (1.0 0.9)) (3))
(((duck --> ([ quacks ])) (1.0 0.9)) (4))

(((swan --> ([ white ])) (1.0 0.9)) (5))
(((swan --> ([ small ])) (1.0 0.9)) (6))
(((swan --> ([ feathered ])) (1.0 0.9)) (7))
(((swan --> ([ quacks ])) (1.0 0.9)) (8))

(((({ sam }) --> ([ white ])) (1.0 0.9)) (9))
(((({ sam }) --> ([ small ])) (1.0 0.9)) (10))
(((({ sam }) --> ([ feathered ])) (1.0 0.9)) (11))
(((({ sam }) --> ([ quacks ])) (1.0 0.9)) (12))

!(choiceQuery ((({ sam }) --> duck) (({ sam }) --> swan)))
;expected: [(((({ sam }) --> swan) (1.0 0.7641509433962266)) (7 11 8 12 6 10 5 9))]
38 changes: 38 additions & 0 deletions nalifier/nalifier.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(= (query $Term)
(let ($A $B $f) (match &self (= (|- ($A $T1) ($B $T2)) ($Term ($f $T1 $T2))) ($A $B $f))
(case (match &self (, (($A $T1) $Ev1) (($B $T2) $Ev2))
(If (StampDisjoint $Ev1 $Ev2)
(($Term ($f $T1 $T2)) (TupleConcat $Ev1 $Ev2))))
(((($Term $T) $Ev) (($Term $T) $Ev))))))

;choice between two options of different term
(= (Choice (($Term1 $T1) $ev1) (($Term2 $T2) $ev2))
(If (> (Truth_Expectation $T1) (Truth_Expectation $T2))
(($Term1 $T1) $ev1)
(($Term2 $T2) $ev2)))

;revise if there is no evidential overlap, else use higher-confident candidate
(= (RevisionAndChoice (($Term1 ($f1 $c1)) $ev1) (($Term2 ($f2 $c2)) $ev2))
(let $ConclusionStamp (TupleConcat $ev1 $ev2)
(If (StampDisjoint $ev1 $ev2)
(($Term1 (Truth_Revision ($f1 $c1) ($f2 $c2))) $ConclusionStamp)
(if (> $c1 $c2)
(($Term1 ($f1 $c1)) $ev1)
(($Term2 ($f2 $c2)) $ev2)))))

(= (accumulateOptions $revChoiceOrBoth $option $options)
(if (== $options ())
$option
(let* (($head (car-atom $options))
($rest (cdr-atom $options))
($revi ($revChoiceOrBoth $option $head)))
(accumulateOptions $revChoiceOrBoth $revi $rest))))

(= (EmptyEvent) ((x (1.0 0.0)) ()))

(= (evidenceQuery $Term) (accumulateOptions RevisionAndChoice (EmptyEvent) (collapse (query $Term))))

(= (choiceQuery $Term)
(let $options (collapse (evidenceQuery (superpose $Term)))
(accumulateOptions Choice (EmptyEvent) $options)))

1 change: 1 addition & 0 deletions nalifier/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cat ../src/utils.metta ../src/logic/LOGIC.metta ../minnars/minnars.metta nalifier.metta input.metta > RUN.metta && metta RUN.metta

0 comments on commit 784a14b

Please sign in to comment.