-
Notifications
You must be signed in to change notification settings - Fork 5
/
add-remove-match-float.metta
executable file
·65 lines (57 loc) · 2.13 KB
/
add-remove-match-float.metta
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;;;;;;;;;;;;;;;;;;;;;
; Adding Atoms to the Knowledge Base
;;;;;;;;;;;;;;;;;;;;;;
!(bind! &kb0 (new-space))
!(add-atom &kb0 1.0)
!(add-atom &kb0 2.0)
;MeTTaLog Only: !(assertEqual (atom-count &kb0) 2)
!(assertEqualToResult (get-atoms &kb0) (1.0 2.0))
;;;;;;;;;;;;;;;;;;;;;;
; Removing Atoms from the Knowledge Base
;;;;;;;;;;;;;;;;;;;;;;
!(bind! &kb1.0 (new-space))
!(add-atom &kb1.0 1.0)
!(add-atom &kb1.0 2.0)
!(add-atom &kb1.0 3.0)
;; Remove an atom and test for success
!(assertTrue (remove-atom &kb1.0 2.0)) ; "remove_atom on a present atom should return true"
;; Attempt to remove a non-existent atom and test for failure
!(assertFalse (remove-atom &kb1.0 "bogus")) ; "remove_atom on a missing atom should return false"
;; Verify the current state of the knowledge base
!(assertEqualToResult (get-atoms &kb1.0) (1.0 3.0))
;;;;;;;;;;;;;;;;;;;;;;
; Replacing Atoms in the Knowledge Base
;;;;;;;;;;;;;;;;;;;;;;
!(bind! &kb2.0 (new-space))
(= (replace-atom $space $before $after) (if (remove-atom $space $before) (add-atom $space $after) False))
!(add-atom &kb2.0 1.0)
!(add-atom &kb2.0 2.0)
!(add-atom &kb2.0 3.0)
;; Replace an atom and verify the operation was successful
!(assertTrue (replace-atom &kb2.0 2.0 4.0))
;; Check the new set of atoms in the knowledge base
!(assertEqualToResult (get-atoms &kb2.0) (1.0 4.0 3.0))
;;;;;;;;;;;;;;;;;;;;;;
; Querying Atoms in the Knowledge Base
;;;;;;;;;;;;;;;;;;;;;;
!(bind! &kb3.0 (new-space))
!(add-atom &kb3.0 ( -1.0 -2.0))
!(add-atom &kb3.0 ( -3.0 -4.0))
;; Adding a duplicate pattern for testing multiple matches
!(add-atom &kb3.0 ( -1.0 -5.0))
;; Verify that the query returns the expected matches
!(assertEqualToResult (match &kb3.0 ( -1.0 $XX) $XX) (-2.0 -5.0))
;;;;;;;;;;;;;;;;;;;;;;
; Comprehensive Test with Add, Remove, Query
;;;;;;;;;;;;;;;;;;;;;;
!(bind! &kb4.0 (new-space))
!(add-atom &kb4.0 6.0)
;; Perform a sequence of operations
!(add-atom &kb4.0 6.0)
!(remove-atom &kb4.0 6.0)
!(add-atom &kb4.0 7.0)
;; Final state should have 6.0 and 7.0 only
!(assertEqualToResult (get-atoms &kb4.0) (6.0 7.0))
;; Query to test the presence of 6.0 and 7.0
!(assertTrue (query &kb4.0 6.0))
!(assertTrue (query &kb4.0 7.0))