OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-agents commits / ce31dc3

Rework demo to show stream abilities
ce31dc3f790592b93ab2f35ff4dfec8db59f987c
by Linas Vepštas <linasvepstas@gmail.com> · 2024-04-16T23:00:23.000Z

Changed files (1) +50 -19

scm/pair-agent/count-agent.scm +50 -19
……@@ -25,26 +25,32 @@
2525
2626
2727(define text-blob "this is just a bunch of words you know")
28(define NUML (Number 4))
29(define DICT (LgDict "any"))
3028
3129
32; From inside to out:
33; LGParseBonds tokenizes a sentence, and then parses it.
34; The PureExecLink makes sure that the parsing is done in a sub-AtomSpace
35; so that the main AtomSpace is not garbaged up.
36;
37; The result of parsing is a list of pairs. First item in a pair is
38; the list of words in the sentence; the second is a list of the edges.
39; Thus, each pair has the form
40; (LinkValue
41; (LinkValue (Word "this") (Word "is") (Word "a") (Word "test"))
42; (LinkValue (Edge ...) (Edge ...) ...))
43;
44; The Filter matches this, so that (Variable "$x") is equated with the
45; list of Edges.
46;
47(define (obs-txt PLAIN-TEXT)
30; Return a text parser that counts edges on a stream. The
31; `txt-stream` must be an Atom that can serve as a source of text.
32; Typically, `txt-stream` will be
33; (ValueOf (Concept "some atom") (Predicate "some key"))
34; and the Value there will be a LinkStream from some file or
35; other text source.
36(define (make-parser txt-stream)
37 ; From inside to out:
38 ; LGParseBonds tokenizes a sentence, and then parses it.
39 ; The PureExecLink makes sure that the parsing is done in a sub-AtomSpace
40 ; so that the main AtomSpace is not garbaged up.
41 ;
42 ; The result of parsing is a list of pairs. First item in a pair is
43 ; the list of words in the sentence; the second is a list of the edges.
44 ; Thus, each pair has the form
45 ; (LinkValue
46 ; (LinkValue (Word "this") (Word "is") (Word "a") (Word "test"))
47 ; (LinkValue (Edge ...) (Edge ...) ...))
48 ;
49 ; The Filter matches this, so that (Variable "$x") is equated with the
50 ; list of Edges.
51 ;
52 (define NUML (Number 4))
53 (define DICT (LgDict "any"))
4854
4955 ; Increment the count on one edge.
5056 (define (incr-cnt edge)
……@@ -86,13 +92,36 @@
8692 )
8793 (parseli phrali)))
8894
95 ; Return the parser.
96 (filty txt-stream)
97)
98
99; Parse a string.
100(define (obs-txt PLAIN-TEXT)
101 (define txt-stream (ValueOf (Concept "foo") (Predicate "some place")))
102 (define parser (make-parser txt-stream))
103
89104 (define phrali (Phrase PLAIN-TEXT))
90 (cog-execute! (filty phrali))
105 (cog-set-value! (Concept "foo") (Predicate "some place") phrali)
106
107 (cog-execute! parser)
91108
92109 ; Remove the phrase-link, return the list of edges.
93110 (cog-extract-recursive! phrali)
94111)
95112
113(define (obs-file FILE-NAME)
114 (define txt-stream (ValueOf (Concept "foo") (Predicate "some place")))
115 (define parser (make-parser txt-stream))
116
117 (define phrali (FileRead (string-append "file://" FILE-NAME)))
118 (cog-set-value! (Concept "foo") (Predicate "some place") phrali)
119
120 (cog-execute! parser)
121)
122
123; --------------------------
124; Issues.
96125; Parses arrive as LinkValues. We want to apply a function to each.
97126; How? Need:
98127; 4) IncrementLink just like cog-inc-value!
……@@ -124,3 +153,5 @@
124153
125154; (load "count-agent.scm")
126155; (obs-txt text-blob)
156; (cog-report-counts)
157; (cog-get-atoms 'WordNode)