OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-rocks commits / 05eca38

Convert the examples away from the deprecated API
05eca380373aee5b77738033a98089f5459d4687
by Linas Vepstas <linasvepstas@gmail.com> · 2026-01-18T05:58:08.000Z

Changed files (6) +72 -72

examples/fetch-store.scm +5 -5
……@@ -15,7 +15,7 @@
1515(define rsn (RocksStorageNode "rocks:///tmp/foo.rdb"))
1616
1717; Open it for I/O
18(cog-open rsn)
18(cog-set-value! rsn (*-open-*))
1919
2020; --------------
2121; Storing and Loading Atoms
……@@ -28,7 +28,7 @@
2828(cog-keys (Concept "a"))
2929
3030; Save it:
31(store-atom (Concept "a"))
31(cog-set-value! rsn (*-store-atom-*) (Concept "a"))
3232
3333; Delete it from the AtomSpace (but not from RocksDB):
3434(cog-extract! (Concept "a"))
……@@ -39,7 +39,7 @@
3939(cog-get-all-roots)
4040
4141; 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"))
4343
4444; Take a look at it:
4545(cog-keys (Concept "a"))
……@@ -48,7 +48,7 @@
4848(cog-set-value! (Concept "a") (Predicate "blo") (StringValue "a" "b" "c"))
4949
5050; Load all key-value pairs on (Concept "a")
51(fetch-atom (Concept "a"))
51(cog-set-value! rsn (*-fetch-atom-*) (Concept "a"))
5252
5353; Verify that all of the keys arrived. Notice that the "new" Value
5454; on (Predicate "blo") was clobbered by the one fetched from the
……@@ -57,7 +57,7 @@
5757
5858; Optionally close the connection.
5959; Not strictly required; cleanup happens anyway, on exit.
60(cog-close rsn)
60(cog-set-value! rsn (*-close-*))
6161
6262; p.s. "flo blo" is how they say "flow blue" in Texas.
6363; That's all! Thanks for paying attention!
examples/load-dump.scm +12 -12
……@@ -6,12 +6,12 @@
66; everything can be slow, and is generally not needed. Thus, one can
77; load portions of the AtomSpace:
88;
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.
1212;
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.
1515;
1616; -------------------------------
1717; Basic initialization and set-up
……@@ -35,9 +35,9 @@
3535; Open a database, and store the entire AtomSpace.
3636;
3737(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-*))
4141
4242; Remove everything in the AtomSpace ...
4343(cog-atomspace-clear)
……@@ -46,12 +46,12 @@
4646(cog-get-all-roots)
4747
4848; 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`,
5050; above, wiped it out.
5151(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-*))
5555
5656; Verify that everything came back
5757(cog-get-all-roots)
examples/many-spaces.scm +16 -16
……@@ -56,7 +56,7 @@
5656
5757; Store the various AtmoSpaces. Here, they are stored in one big gulp,
5858; 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
6060; strongly recommended to avoid confusion. It effectively tells the
6161; StorageNode to expect multiple AtomSpaces to be stored. Here, it is
6262; optional ONLY because `as-main` was NOT stored first! The StorageNode
……@@ -64,13 +64,13 @@
6464; that the StorageNode is declared in, and thus deduces its will need to
6565; work in a multi-space mode.
6666(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-*))
7474
7575; -------------------------------------------------
7676; Done with the store. Now exist guile completely, and restart. Or,
……@@ -90,7 +90,7 @@
9090
9191; Define the database location, and open it.
9292(define rsn (RocksStorageNode "rocks:///tmp/bundle-demo"))
93(cog-open rsn)
93(cog-set-value! rsn (*-open-*))
9494
9595; Print the current main space. It should be nearly empty, but for the
9696; StorageNode declaration, and ObjectNode messages being sent to it.
……@@ -101,7 +101,7 @@
101101; you think it should.
102102(define as-two (AtomSpace "bar"))
103103(cog-set-atomspace! as-two)
104(load-atomspace as-two)
104(cog-set-value! rsn (*-load-atomspace-*) as-two)
105105(cog-prt-atomspace)
106106
107107; Lets go back to the main space. Make sure there was no leakage.
……@@ -113,7 +113,7 @@
113113; print will happen in the main space, and not the loaded space.
114114(define as-one (AtomSpace "foo"))
115115;;; (cog-set-atomspace! as-one) ; Skip me!
116(load-atomspace as-one)
116(cog-set-value! rsn (*-load-atomspace-*) as-one)
117117(cog-prt-atomspace)
118118
119119; Switch spaces and print. Make sure these are what you expect.
……@@ -128,7 +128,7 @@
128128
129129; Now load the main space. This will have the "indexes" that were
130130; created earlier.
131(load-atomspace as-main)
131(cog-set-value! rsn (*-load-atomspace-*) as-main)
132132(cog-prt-atomspace)
133133
134134; What about the third space? It's currently empty ...
……@@ -136,13 +136,13 @@
136136(cog-set-atomspace! as-three)
137137(cog-prt-atomspace)
138138
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))
142142(cog-prt-atomspace)
143143
144144; Tidy conclusion.
145(cog-close rsn)
145(cog-set-value! rsn (*-close-*))
146146
147147; The End. That's All, Folks!
148148; -------------------------------------------------------------------
examples/multiple-databases.scm +13 -13
……@@ -13,8 +13,8 @@
1313(define foo-store (RocksStorageNode "rocks:///tmp/foo.rdb"))
1414(define bar-store (RocksStorageNode "rocks:///tmp/bar.rdb"))
1515
16(cog-open foo-store)
17(cog-open bar-store)
16(cog-set-value! foo-store (*-open-*))
17(cog-set-value! bar-store (*-open-*))
1818
1919; -------------
2020; Storing Atoms
……@@ -22,13 +22,13 @@
2222(cog-set-value! (Concept "a") (Predicate "a-key") (FloatValue 1 2 3))
2323(cog-set-value! (Concept "b") (Predicate "b-key") (FloatValue 4 5 6))
2424
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"))
2828
2929; 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-*))
3232
3333; -------------
3434; Erase everything in the AtomSpace. Do this to avoid confusion in
……@@ -40,23 +40,23 @@
4040;
4141; The previous AtomSpace clear wiped out everything. Start all over.
4242(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))
4545
4646; Verify that only (ConceptNode "a") is in the AtomSpace.
4747(cog-get-all-roots)
4848
4949; Now open the second database
5050(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))
5353
5454; Verify that both (Concept "a") and (Concept "b") are present.
5555(cog-get-all-roots)
5656
5757; 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-*))
6060
6161; That's all! Thanks for paying attention!
6262; -------------
examples/query-storage.scm +15 -15
……@@ -44,9 +44,9 @@
4444; -----------------------
4545; Push the entire atomspace out to disk.
4646(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-*))
5050
5151; Clear the local AtomSpace (the Atoms remain on disk, just not in RAM).
5252(cog-atomspace-clear)
……@@ -56,7 +56,7 @@
5656
5757; The `clear` above wipes everything out. Redeclare and reopen.
5858(set! rsn (RocksStorageNode "rocks:///tmp/foo.rdb"))
59(cog-open rsn)
59(cog-set-value! rsn (*-open-*))
6060; -------------------------
6161; Querying with Meet links.
6262;
……@@ -71,7 +71,7 @@
7171(define results-key (Predicate "results"))
7272
7373; 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)
7575
7676; Take a look at what was found.
7777(cog-value get-tail results-key)
……@@ -94,14 +94,14 @@
9494;
9595; Add some more data, push it out to the server, and delete it locally.
9696(List (Concept "A") (Concept "F"))
97(store-atomspace)
97(cog-set-value! rsn (*-store-atomspace-*) (cog-atomspace))
9898(cog-extract-recursive! (Concept "F"))
9999
100100; Verify that (Concept "F") is gone
101101(cog-get-all-roots)
102102
103103; Re-run the query
104(fetch-query get-tail results-key)
104(cog-set-value! rsn (*-fetch-query-*) get-tail results-key)
105105
106106; Take a look at what was found. ... oh no, its the old cached result!
107107(cog-value get-tail results-key)
……@@ -111,10 +111,10 @@
111111(cog-set-value! get-tail results-key #f)
112112
113113; 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)
115115
116116; ... 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)
118118(cog-value get-tail results-key)
119119
120120; --------------
……@@ -135,22 +135,22 @@
135135;
136136; Let's repeat some of the above.
137137(List (Concept "A") (Concept "G"))
138(store-atomspace)
138(cog-set-value! rsn (*-store-atomspace-*) (cog-atomspace))
139139(cog-extract-recursive! (Concept "G"))
140140
141141; 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)
143143(cog-value get-tail results-key)
144144
145145; We want meta-data, and we want a fresh re-computation.
146146(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)))
148148
149149; Yay! it worked!
150150(cog-value get-tail results-key)
151151
152152; Tell us more!
153(fetch-value get-tail metadata)
153(cog-set-value! rsn (*-fetch-value-*) get-tail metadata)
154154(cog-value get-tail metadata)
155155
156156; Currently, the above returns seconds since January 1, 1970
……@@ -173,7 +173,7 @@
173173(define b-holders (MaximalJoin (Concept "B")))
174174
175175; Just like before...
176(fetch-query b-holders results-key)
176(cog-set-value! rsn (*-fetch-query-*) b-holders results-key)
177177(cog-value b-holders results-key)
178178
179179; Verify that everything landed in the AtomSpace.
……@@ -194,7 +194,7 @@
194194 (OrderedLink (Variable "tail") (Concept "by") (Variable "tail"))
195195))
196196
197(fetch-query tail-by-tail results-key)
197(cog-set-value! rsn (*-fetch-query-*) tail-by-tail results-key)
198198(cog-value tail-by-tail results-key)
199199
200200; That's all! Thanks for paying attention!
examples/space-frames.scm +11 -11
……@@ -66,31 +66,31 @@
6666 ; Save the entire stack of spaces. This only stores the spaces and
6767 ; their relationship to one-anothr; it does NOT store the contents,
6868 (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)
7171
7272 ; Splatter some atoms into the various spaces. Place some values on
7373 ; each, so that later one, we can verify the the restored spaces.
7474 (cog-set-atomspace! base-space)
7575 (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"))
7777
7878 (cog-set-atomspace! mid1-space)
7979 (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"))
8181
8282 (cog-set-atomspace! mid2-space)
8383 (cog-set-value! (ListLink (Concept "foo") (Concept "bar"))
8484 (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")))
8686
8787 ; Change the ctv on `foo`. This will hade the earlier value.
8888 (cog-set-atomspace! mid3-space)
8989 (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"))
9191
9292 ; Close storage
93 (cog-close storage)
93 (cog-set-value! storage (*-close-*))
9494
9595 ; Clear out the spaces, start with a clean slate. This is NOT really
9696 ; needed, as the AtomSpace will disappear, go "poof", once the last
……@@ -114,17 +114,17 @@
114114
115115; Load everything; the spaces, the atoms, everything.
116116(define storage (RocksStorageNode "rocks:///tmp/frame-demo"))
117(cog-open storage)
117(cog-set-value! storage (*-open-*))
118118
119119; Calling `load-frames` will return a list of all of the AtomSpaces
120120; at the top of the DAG of frames. In this cae, we had a simple stack,
121121; 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))
123123
124124; Change to this top, and load it's contents, and everything below it.
125125(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-*))
128128
129129; Print out the full top-most atomspace. This will print a long,
130130; perhaps confusing string: it is a list of the AtomSpaces names,