OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-agents commits / bb69312

Work a little bit on backwards-compat
bb69312c43f84d8c2385f3ae72d70a2570d2d5af
by Linas Vepštas <linasvepstas@gmail.com> · 2024-05-03T17:53:00.000Z

Changed files (2) +47 -6

scm/pair-agent/README.md +14 -0
……@@ -49,6 +49,20 @@ Here's the design we want for the pair-counting agent:
4949 - There aren't any push demos.
5050 - Attention control is easier with Pull.
5151
52### Storage and Matrix API ???
53The batch system uses the matrix API to define pipelines: this includes
54* Which parser to use, e.g. `(make-any-link-api)`
55* How to increment counts, e.g. `(add-count-api ala)`
56* How to store updated counts, e.g. `(add-storage-count alc)`
57
58This is a pipeline framework, it is not in Atomese. Its large,
59extensive, lots of bells and whistles; many years of fully debugged
60code. Its a good/great API, capable of carrying the load.
61
62It seems to be slow, presumably due to the huge number of scheme/C++
63transitions. To validate this, need to run a pair-count-hacked
64experiment, and actually measure.
65
5266### TODO/Open issues
5367Some unresolved issues.
5468* Parser wants strings as `Node`s; it would be nice to be able to work
scm/pair-agent/count-agent.scm +33 -6
……@@ -18,9 +18,9 @@
1818(use-modules (srfi srfi-1))
1919
2020; --------------------------------------------------------------
21; Return a text parser that counts edges on a stream. The
22; `txt-stream` must be an Atom that can serve as a source of text.
23; Typically, `txt-stream` will be
21; Return a text parser that counts words and word-pairs obtained from
22; parsing text on a stream. The `txt-stream` must be an Atom that can
23; serve as a source of text. Typically, `txt-stream` will be
2424; (ValueOf (Concept "some atom") (Predicate "some key"))
2525; and the Value there will be a LinkStream from some file or
2626; other text source.
……@@ -28,6 +28,8 @@
2828; These sets up a processing pipeline in Atomese, and returns that
2929; pipeline. The actual parsing all happens in C++ code, not in scheme
3030; code. The scheme here is just to glue the pipeline together.
31;
32; This is attempting to be backwards-compat with old pair-counting code.
3133(define (make-parser txt-stream)
3234 ;
3335 ; Pipeline steps, from inside to out:
……@@ -50,8 +52,9 @@
5052 ;
5153 ; The counter is a non-atomic pipe of (SetValue (Plus 1 (GetValue)))
5254 ;
53 (define NUML (Number 4))
55 (define NUML (Number 6))
5456 (define DICT (LgDict "any"))
57 (define any-parse (ParseNode "ANY"))
5558
5659 ; Increment the count on one atom.
5760 (define (incr-cnt atom)
……@@ -82,9 +85,11 @@
8285 (Type 'LinkValue)
8386 (Variable "$word-list")
8487 (Variable "$edge-list"))
85 ; Apply the function FUNKY to the edge-list
88 ; Apply the function FUNKY to the word and edge lists.
8689 (FUNKY (Variable "$word-list"))
87 (FUNKY (Variable "$edge-list")))
90 (FUNKY (Variable "$edge-list"))
91 ; Increment by one for each parse
92 (incr-cnt any-parse))
8893 PASRC))
8994
9095 (define parser (LgParseBonds txt-stream DICT NUML))
……@@ -98,6 +103,28 @@
98103 (stream-splitter parser atom-counter)
99104)
100105
106; --------------------------------------------------------------
107; Demo wrapper: Parse a single text string.
108(define (obs-texty TXT-STRING)
109
110 ; We don't need to create this over and over; once is enough.
111 (define txt-stream
112 (ValueOf (Anchor "parse pipe") (Predicate "text src")))
113 (define parser (make-parser txt-stream))
114
115 (define phrali (Item TXT-STRING))
116 (cog-execute!
117 (SetValue (Anchor "parse pipe") (Predicate "text src") phrali))
118
119 ; Run parser once.
120 (cog-execute! parser)
121 (cog-extract-recursive! phrali)
122)
123
124; Example:
125; (obs-texty "this is a test")
126; (cog-execute! (ValueOf (ParseNode "ANY") (Predicate "count"))
127
101128; --------------------------------------------------------------
102129; Demo wrapper: Parse contents of a file.
103130(define (obs-file FILE-NAME)