| … | … | @@ -15,7 +15,7 @@ |
| 15 | 15 | (define rsn (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 16 | 16 | |
| 17 | 17 | ; Open it for I/O |
| 18 | (cog-open rsn) | |
| 18 | (cog-set-value! rsn (*-open-*)) | |
| 19 | 19 | |
| 20 | 20 | ; -------------- |
| 21 | 21 | ; Storing and Loading Atoms |
| … | … | @@ -28,7 +28,7 @@ |
| 28 | 28 | (cog-keys (Concept "a")) |
| 29 | 29 | |
| 30 | 30 | ; Save it: |
| 31 | (store-atom (Concept "a")) | |
| 31 | (cog-set-value! rsn (*-store-atom-*) (Concept "a")) | |
| 32 | 32 | |
| 33 | 33 | ; Delete it from the AtomSpace (but not from RocksDB): |
| 34 | 34 | (cog-extract! (Concept "a")) |
| … | … | @@ -39,7 +39,7 @@ |
| 39 | 39 | (cog-get-all-roots) |
| 40 | 40 | |
| 41 | 41 | ; Fetch one of the Values, but not the other: |
| 42 | (fetch-value (Concept "a") (Predicate "blo")) | |
| 42 | (cog-set-value! rsn (*-fetch-value-*) (Concept "a") (Predicate "blo")) | |
| 43 | 43 | |
| 44 | 44 | ; Take a look at it: |
| 45 | 45 | (cog-keys (Concept "a")) |
| … | … | @@ -48,7 +48,7 @@ |
| 48 | 48 | (cog-set-value! (Concept "a") (Predicate "blo") (StringValue "a" "b" "c")) |
| 49 | 49 | |
| 50 | 50 | ; Load all key-value pairs on (Concept "a") |
| 51 | (fetch-atom (Concept "a")) | |
| 51 | (cog-set-value! rsn (*-fetch-atom-*) (Concept "a")) | |
| 52 | 52 | |
| 53 | 53 | ; Verify that all of the keys arrived. Notice that the "new" Value |
| 54 | 54 | ; on (Predicate "blo") was clobbered by the one fetched from the |
| … | … | @@ -57,7 +57,7 @@ |
| 57 | 57 | |
| 58 | 58 | ; Optionally close the connection. |
| 59 | 59 | ; Not strictly required; cleanup happens anyway, on exit. |
| 60 | (cog-close rsn) | |
| 60 | (cog-set-value! rsn (*-close-*)) | |
| 61 | 61 | |
| 62 | 62 | ; p.s. "flo blo" is how they say "flow blue" in Texas. |
| 63 | 63 | ; That's all! Thanks for paying attention! |
| … | … | @@ -6,12 +6,12 @@ |
| 6 | 6 | ; everything can be slow, and is generally not needed. Thus, one can |
| 7 | 7 | ; load portions of the AtomSpace: |
| 8 | 8 | ; |
| 9 | ; load-referers ATOM -- to load only those graphs containing ATOM | |
| 10 | ; load-atoms-of-type TYPE -- to load only atoms of type TYPE | |
| 11 | ; load-atomspace -- load everything. | |
| 9 | ; (*-fetch-incoming-set-*) ATOM -- to load only those graphs containing ATOM | |
| 10 | ; (*-load-atoms-of-type-*) TYPE -- to load only atoms of type TYPE | |
| 11 | ; (*-load-atomspace-*) -- load everything. | |
| 12 | 12 | ; |
| 13 | ; store-referers ATOM -- store all graphs that contain ATOM | |
| 14 | ; store-atomspace -- store everything. | |
| 13 | ; (*-store-incoming-set-*) ATOM -- store all graphs that contain ATOM | |
| 14 | ; (*-store-atomspace-*) -- store everything. | |
| 15 | 15 | ; |
| 16 | 16 | ; ------------------------------- |
| 17 | 17 | ; Basic initialization and set-up |
| … | … | @@ -35,9 +35,9 @@ |
| 35 | 35 | ; Open a database, and store the entire AtomSpace. |
| 36 | 36 | ; |
| 37 | 37 | (define rsn (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 38 | (cog-open rsn) | |
| 39 | (store-atomspace) | |
| 40 | (cog-close rsn) | |
| 38 | (cog-set-value! rsn (*-open-*)) | |
| 39 | (cog-set-value! rsn (*-store-atomspace-*) (cog-atomspace)) | |
| 40 | (cog-set-value! rsn (*-close-*)) | |
| 41 | 41 | |
| 42 | 42 | ; Remove everything in the AtomSpace ... |
| 43 | 43 | (cog-atomspace-clear) |
| … | … | @@ -46,12 +46,12 @@ |
| 46 | 46 | (cog-get-all-roots) |
| 47 | 47 | |
| 48 | 48 | ; Reconnect to the database, and fetch everything in it. |
| 49 | ; The StorageNode needs to be re-declaredm since the `clear`, | |
| 49 | ; The StorageNode needs to be re-declared since the `clear`, | |
| 50 | 50 | ; above, wiped it out. |
| 51 | 51 | (set! rsn (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 52 | (cog-open rsn) | |
| 53 | (load-atomspace) | |
| 54 | (cog-close rsn) | |
| 52 | (cog-set-value! rsn (*-open-*)) | |
| 53 | (cog-set-value! rsn (*-load-atomspace-*) (cog-atomspace)) | |
| 54 | (cog-set-value! rsn (*-close-*)) | |
| 55 | 55 | |
| 56 | 56 | ; Verify that everything came back |
| 57 | 57 | (cog-get-all-roots) |
| … | … | @@ -56,7 +56,7 @@ |
| 56 | 56 | |
| 57 | 57 | ; Store the various AtmoSpaces. Here, they are stored in one big gulp, |
| 58 | 58 | ; but it doesn't have to be done this way: they can be dribbled in. |
| 59 | ; An initial call to `store-frames` can someties be optional, but is | |
| 59 | ; An initial call to `(*-store-frames-*)` can sometimes be optional, but is | |
| 60 | 60 | ; strongly recommended to avoid confusion. It effectively tells the |
| 61 | 61 | ; StorageNode to expect multiple AtomSpaces to be stored. Here, it is |
| 62 | 62 | ; optional ONLY because `as-main` was NOT stored first! The StorageNode |
| … | … | @@ -64,13 +64,13 @@ |
| 64 | 64 | ; that the StorageNode is declared in, and thus deduces its will need to |
| 65 | 65 | ; work in a multi-space mode. |
| 66 | 66 | (define rsn (RocksStorageNode "rocks:///tmp/bundle-demo")) |
| 67 | (cog-open rsn) | |
| 68 | ; (store-frames as-main) | |
| 69 | (store-atomspace as-one) | |
| 70 | (store-atomspace as-two) | |
| 71 | (store-atomspace as-three) | |
| 72 | (store-atomspace as-main) | |
| 73 | (cog-close rsn) | |
| 67 | (cog-set-value! rsn (*-open-*)) | |
| 68 | ; (cog-set-value! rsn (*-store-frames-*) as-main) | |
| 69 | (cog-set-value! rsn (*-store-atomspace-*) as-one) | |
| 70 | (cog-set-value! rsn (*-store-atomspace-*) as-two) | |
| 71 | (cog-set-value! rsn (*-store-atomspace-*) as-three) | |
| 72 | (cog-set-value! rsn (*-store-atomspace-*) as-main) | |
| 73 | (cog-set-value! rsn (*-close-*)) | |
| 74 | 74 | |
| 75 | 75 | ; ------------------------------------------------- |
| 76 | 76 | ; Done with the store. Now exist guile completely, and restart. Or, |
| … | … | @@ -90,7 +90,7 @@ |
| 90 | 90 | |
| 91 | 91 | ; Define the database location, and open it. |
| 92 | 92 | (define rsn (RocksStorageNode "rocks:///tmp/bundle-demo")) |
| 93 | (cog-open rsn) | |
| 93 | (cog-set-value! rsn (*-open-*)) | |
| 94 | 94 | |
| 95 | 95 | ; Print the current main space. It should be nearly empty, but for the |
| 96 | 96 | ; StorageNode declaration, and ObjectNode messages being sent to it. |
| … | … | @@ -101,7 +101,7 @@ |
| 101 | 101 | ; you think it should. |
| 102 | 102 | (define as-two (AtomSpace "bar")) |
| 103 | 103 | (cog-set-atomspace! as-two) |
| 104 | (load-atomspace as-two) | |
| 104 | (cog-set-value! rsn (*-load-atomspace-*) as-two) | |
| 105 | 105 | (cog-prt-atomspace) |
| 106 | 106 | |
| 107 | 107 | ; Lets go back to the main space. Make sure there was no leakage. |
| … | … | @@ -113,7 +113,7 @@ |
| 113 | 113 | ; print will happen in the main space, and not the loaded space. |
| 114 | 114 | (define as-one (AtomSpace "foo")) |
| 115 | 115 | ;;; (cog-set-atomspace! as-one) ; Skip me! |
| 116 | (load-atomspace as-one) | |
| 116 | (cog-set-value! rsn (*-load-atomspace-*) as-one) | |
| 117 | 117 | (cog-prt-atomspace) |
| 118 | 118 | |
| 119 | 119 | ; Switch spaces and print. Make sure these are what you expect. |
| … | … | @@ -128,7 +128,7 @@ |
| 128 | 128 | |
| 129 | 129 | ; Now load the main space. This will have the "indexes" that were |
| 130 | 130 | ; created earlier. |
| 131 | (load-atomspace as-main) | |
| 131 | (cog-set-value! rsn (*-load-atomspace-*) as-main) | |
| 132 | 132 | (cog-prt-atomspace) |
| 133 | 133 | |
| 134 | 134 | ; What about the third space? It's currently empty ... |
| … | … | @@ -136,13 +136,13 @@ |
| 136 | 136 | (cog-set-atomspace! as-three) |
| 137 | 137 | (cog-prt-atomspace) |
| 138 | 138 | |
| 139 | ; Load it, and see. When `load-stomspace` is called without an | |
| 140 | ; argument, the current AtomSpace is assumed. | |
| 141 | (load-atomspace) | |
| 139 | ; Load it, and see. When `(*-load-atomspace-*)` is used, the atomspace | |
| 140 | ; to load must be specified. | |
| 141 | (cog-set-value! rsn (*-load-atomspace-*) (cog-atomspace)) | |
| 142 | 142 | (cog-prt-atomspace) |
| 143 | 143 | |
| 144 | 144 | ; Tidy conclusion. |
| 145 | (cog-close rsn) | |
| 145 | (cog-set-value! rsn (*-close-*)) | |
| 146 | 146 | |
| 147 | 147 | ; The End. That's All, Folks! |
| 148 | 148 | ; ------------------------------------------------------------------- |
| … | … | @@ -13,8 +13,8 @@ |
| 13 | 13 | (define foo-store (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 14 | 14 | (define bar-store (RocksStorageNode "rocks:///tmp/bar.rdb")) |
| 15 | 15 | |
| 16 | (cog-open foo-store) | |
| 17 | (cog-open bar-store) | |
| 16 | (cog-set-value! foo-store (*-open-*)) | |
| 17 | (cog-set-value! bar-store (*-open-*)) | |
| 18 | 18 | |
| 19 | 19 | ; ------------- |
| 20 | 20 | ; Storing Atoms |
| … | … | @@ -22,13 +22,13 @@ |
| 22 | 22 | (cog-set-value! (Concept "a") (Predicate "a-key") (FloatValue 1 2 3)) |
| 23 | 23 | (cog-set-value! (Concept "b") (Predicate "b-key") (FloatValue 4 5 6)) |
| 24 | 24 | |
| 25 | ; Save each atom in a distinct AtomSpace | |
| 26 | (store-atom (Concept "a") foo-store) | |
| 27 | (store-atom (Concept "b") bar-store) | |
| 25 | ; Save each atom in a distinct database | |
| 26 | (cog-set-value! foo-store (*-store-atom-*) (Concept "a")) | |
| 27 | (cog-set-value! bar-store (*-store-atom-*) (Concept "b")) | |
| 28 | 28 | |
| 29 | 29 | ; Close the connections to each. |
| 30 | (cog-close foo-store) | |
| 31 | (cog-close bar-store) | |
| 30 | (cog-set-value! foo-store (*-close-*)) | |
| 31 | (cog-set-value! bar-store (*-close-*)) | |
| 32 | 32 | |
| 33 | 33 | ; ------------- |
| 34 | 34 | ; Erase everything in the AtomSpace. Do this to avoid confusion in |
| … | … | @@ -40,23 +40,23 @@ |
| 40 | 40 | ; |
| 41 | 41 | ; The previous AtomSpace clear wiped out everything. Start all over. |
| 42 | 42 | (define foo-store (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 43 | (cog-open foo-store) | |
| 44 | (load-atomspace foo-store) | |
| 43 | (cog-set-value! foo-store (*-open-*)) | |
| 44 | (cog-set-value! foo-store (*-load-atomspace-*) (cog-atomspace)) | |
| 45 | 45 | |
| 46 | 46 | ; Verify that only (ConceptNode "a") is in the AtomSpace. |
| 47 | 47 | (cog-get-all-roots) |
| 48 | 48 | |
| 49 | 49 | ; Now open the second database |
| 50 | 50 | (define bar-store (RocksStorageNode "rocks:///tmp/bar.rdb")) |
| 51 | (cog-open bar-store) | |
| 52 | (load-atomspace bar-store) | |
| 51 | (cog-set-value! bar-store (*-open-*)) | |
| 52 | (cog-set-value! bar-store (*-load-atomspace-*) (cog-atomspace)) | |
| 53 | 53 | |
| 54 | 54 | ; Verify that both (Concept "a") and (Concept "b") are present. |
| 55 | 55 | (cog-get-all-roots) |
| 56 | 56 | |
| 57 | 57 | ; We're done. |
| 58 | (cog-close foo-store) | |
| 59 | (cog-close bar-store) | |
| 58 | (cog-set-value! foo-store (*-close-*)) | |
| 59 | (cog-set-value! bar-store (*-close-*)) | |
| 60 | 60 | |
| 61 | 61 | ; That's all! Thanks for paying attention! |
| 62 | 62 | ; ------------- |
| … | … | @@ -44,9 +44,9 @@ |
| 44 | 44 | ; ----------------------- |
| 45 | 45 | ; Push the entire atomspace out to disk. |
| 46 | 46 | (define rsn (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 47 | (cog-open rsn) | |
| 48 | (store-atomspace) | |
| 49 | (cog-close rsn) | |
| 47 | (cog-set-value! rsn (*-open-*)) | |
| 48 | (cog-set-value! rsn (*-store-atomspace-*) (cog-atomspace)) | |
| 49 | (cog-set-value! rsn (*-close-*)) | |
| 50 | 50 | |
| 51 | 51 | ; Clear the local AtomSpace (the Atoms remain on disk, just not in RAM). |
| 52 | 52 | (cog-atomspace-clear) |
| … | … | @@ -56,7 +56,7 @@ |
| 56 | 56 | |
| 57 | 57 | ; The `clear` above wipes everything out. Redeclare and reopen. |
| 58 | 58 | (set! rsn (RocksStorageNode "rocks:///tmp/foo.rdb")) |
| 59 | (cog-open rsn) | |
| 59 | (cog-set-value! rsn (*-open-*)) | |
| 60 | 60 | ; ------------------------- |
| 61 | 61 | ; Querying with Meet links. |
| 62 | 62 | ; |
| … | … | @@ -71,7 +71,7 @@ |
| 71 | 71 | (define results-key (Predicate "results")) |
| 72 | 72 | |
| 73 | 73 | ; Find and fetch all tails at the remote server. |
| 74 | (fetch-query get-tail results-key) | |
| 74 | (cog-set-value! rsn (*-fetch-query-*) get-tail results-key) | |
| 75 | 75 | |
| 76 | 76 | ; Take a look at what was found. |
| 77 | 77 | (cog-value get-tail results-key) |
| … | … | @@ -94,14 +94,14 @@ |
| 94 | 94 | ; |
| 95 | 95 | ; Add some more data, push it out to the server, and delete it locally. |
| 96 | 96 | (List (Concept "A") (Concept "F")) |
| 97 | (store-atomspace) | |
| 97 | (cog-set-value! rsn (*-store-atomspace-*) (cog-atomspace)) | |
| 98 | 98 | (cog-extract-recursive! (Concept "F")) |
| 99 | 99 | |
| 100 | 100 | ; Verify that (Concept "F") is gone |
| 101 | 101 | (cog-get-all-roots) |
| 102 | 102 | |
| 103 | 103 | ; Re-run the query |
| 104 | (fetch-query get-tail results-key) | |
| 104 | (cog-set-value! rsn (*-fetch-query-*) get-tail results-key) | |
| 105 | 105 | |
| 106 | 106 | ; Take a look at what was found. ... oh no, its the old cached result! |
| 107 | 107 | (cog-value get-tail results-key) |
| … | … | @@ -111,10 +111,10 @@ |
| 111 | 111 | (cog-set-value! get-tail results-key #f) |
| 112 | 112 | |
| 113 | 113 | ; Now brute-force kill it in the server: |
| 114 | (store-value get-tail results-key) | |
| 114 | (cog-set-value! rsn (*-store-value-*) get-tail results-key) | |
| 115 | 115 | |
| 116 | 116 | ; ... and rerun the query. This time, we expect all the results. |
| 117 | (fetch-query get-tail results-key) | |
| 117 | (cog-set-value! rsn (*-fetch-query-*) get-tail results-key) | |
| 118 | 118 | (cog-value get-tail results-key) |
| 119 | 119 | |
| 120 | 120 | ; -------------- |
| … | … | @@ -135,22 +135,22 @@ |
| 135 | 135 | ; |
| 136 | 136 | ; Let's repeat some of the above. |
| 137 | 137 | (List (Concept "A") (Concept "G")) |
| 138 | (store-atomspace) | |
| 138 | (cog-set-value! rsn (*-store-atomspace-*) (cog-atomspace)) | |
| 139 | 139 | (cog-extract-recursive! (Concept "G")) |
| 140 | 140 | |
| 141 | 141 | ; Oh no! The cache is stale! Missing (Concept "G")! |
| 142 | (fetch-query get-tail results-key) | |
| 142 | (cog-set-value! rsn (*-fetch-query-*) get-tail results-key) | |
| 143 | 143 | (cog-value get-tail results-key) |
| 144 | 144 | |
| 145 | 145 | ; We want meta-data, and we want a fresh re-computation. |
| 146 | 146 | (define metadata (Predicate "my metadata")) |
| 147 | (fetch-query get-tail results-key metadata #t) | |
| 147 | (cog-set-value! rsn (*-fetch-query-*) (LinkValue (cog-atomspace) get-tail results-key metadata (BoolValue #t))) | |
| 148 | 148 | |
| 149 | 149 | ; Yay! it worked! |
| 150 | 150 | (cog-value get-tail results-key) |
| 151 | 151 | |
| 152 | 152 | ; Tell us more! |
| 153 | (fetch-value get-tail metadata) | |
| 153 | (cog-set-value! rsn (*-fetch-value-*) get-tail metadata) | |
| 154 | 154 | (cog-value get-tail metadata) |
| 155 | 155 | |
| 156 | 156 | ; Currently, the above returns seconds since January 1, 1970 |
| … | … | @@ -173,7 +173,7 @@ |
| 173 | 173 | (define b-holders (MaximalJoin (Concept "B"))) |
| 174 | 174 | |
| 175 | 175 | ; Just like before... |
| 176 | (fetch-query b-holders results-key) | |
| 176 | (cog-set-value! rsn (*-fetch-query-*) b-holders results-key) | |
| 177 | 177 | (cog-value b-holders results-key) |
| 178 | 178 | |
| 179 | 179 | ; Verify that everything landed in the AtomSpace. |
| … | … | @@ -194,7 +194,7 @@ |
| 194 | 194 | (OrderedLink (Variable "tail") (Concept "by") (Variable "tail")) |
| 195 | 195 | )) |
| 196 | 196 | |
| 197 | (fetch-query tail-by-tail results-key) | |
| 197 | (cog-set-value! rsn (*-fetch-query-*) tail-by-tail results-key) | |
| 198 | 198 | (cog-value tail-by-tail results-key) |
| 199 | 199 | |
| 200 | 200 | ; That's all! Thanks for paying attention! |
| … | … | @@ -66,31 +66,31 @@ |
| 66 | 66 | ; Save the entire stack of spaces. This only stores the spaces and |
| 67 | 67 | ; their relationship to one-anothr; it does NOT store the contents, |
| 68 | 68 | (define storage (RocksStorageNode "rocks:///tmp/frame-demo")) |
| 69 | (cog-open storage) | |
| 70 | (store-frames surface-space) | |
| 69 | (cog-set-value! storage (*-open-*)) | |
| 70 | (cog-set-value! storage (*-store-frames-*) surface-space) | |
| 71 | 71 | |
| 72 | 72 | ; Splatter some atoms into the various spaces. Place some values on |
| 73 | 73 | ; each, so that later one, we can verify the the restored spaces. |
| 74 | 74 | (cog-set-atomspace! base-space) |
| 75 | 75 | (cog-set-value! (Concept "foo") (Predicate "key") (FloatValue 1 0 3)) |
| 76 | (store-atom (Concept "foo")) | |
| 76 | (cog-set-value! storage (*-store-atom-*) (Concept "foo")) | |
| 77 | 77 | |
| 78 | 78 | (cog-set-atomspace! mid1-space) |
| 79 | 79 | (cog-set-value! (Concept "bar") (Predicate "key") (FloatValue 1 0 4)) |
| 80 | (store-atom (Concept "bar")) | |
| 80 | (cog-set-value! storage (*-store-atom-*) (Concept "bar")) | |
| 81 | 81 | |
| 82 | 82 | (cog-set-atomspace! mid2-space) |
| 83 | 83 | (cog-set-value! (ListLink (Concept "foo") (Concept "bar")) |
| 84 | 84 | (Predicate "key") (FloatValue 1 0 5)) |
| 85 | (store-atom (ListLink (Concept "foo") (Concept "bar"))) | |
| 85 | (cog-set-value! storage (*-store-atom-*) (ListLink (Concept "foo") (Concept "bar"))) | |
| 86 | 86 | |
| 87 | 87 | ; Change the ctv on `foo`. This will hade the earlier value. |
| 88 | 88 | (cog-set-atomspace! mid3-space) |
| 89 | 89 | (cog-set-value! (Concept "foo") (Predicate "key") (FloatValue 6 22 42)) |
| 90 | (store-atom (Concept "foo")) | |
| 90 | (cog-set-value! storage (*-store-atom-*) (Concept "foo")) | |
| 91 | 91 | |
| 92 | 92 | ; Close storage |
| 93 | (cog-close storage) | |
| 93 | (cog-set-value! storage (*-close-*)) | |
| 94 | 94 | |
| 95 | 95 | ; Clear out the spaces, start with a clean slate. This is NOT really |
| 96 | 96 | ; needed, as the AtomSpace will disappear, go "poof", once the last |
| … | … | @@ -114,17 +114,17 @@ |
| 114 | 114 | |
| 115 | 115 | ; Load everything; the spaces, the atoms, everything. |
| 116 | 116 | (define storage (RocksStorageNode "rocks:///tmp/frame-demo")) |
| 117 | (cog-open storage) | |
| 117 | (cog-set-value! storage (*-open-*)) | |
| 118 | 118 | |
| 119 | 119 | ; Calling `load-frames` will return a list of all of the AtomSpaces |
| 120 | 120 | ; at the top of the DAG of frames. In this cae, we had a simple stack, |
| 121 | 121 | ; so there is only one single frame at the top, the top-space. |
| 122 | (define top-space (car (load-frames))) | |
| 122 | (define top-space (cog-value-ref (cog-value storage (*-load-frames-*)) 0)) | |
| 123 | 123 | |
| 124 | 124 | ; Change to this top, and load it's contents, and everything below it. |
| 125 | 125 | (cog-set-atomspace! top-space) |
| 126 | (load-atomspace) | |
| 127 | (cog-close storage) | |
| 126 | (cog-set-value! storage (*-load-atomspace-*) (cog-atomspace)) | |
| 127 | (cog-set-value! storage (*-close-*)) | |
| 128 | 128 | |
| 129 | 129 | ; Print out the full top-most atomspace. This will print a long, |
| 130 | 130 | ; perhaps confusing string: it is a list of the AtomSpaces names, |