OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-agents commits / c084406

Update the count agent into proper form
c08440633505cd0e3442f4922908278647850c15
by Linas Vepštas <linasvepstas@gmail.com> · 2024-05-03T13:45:37.000Z

Changed files (1) +28 -36

scm/pair-agent/count-agent.scm +28 -36
……@@ -1,19 +1,13 @@
11;
22; count-agent.scm -- Agent that performs word-pair counting.
33;
4; Prototype hand-built agent capable of counting things observed
5; in the external environment.
6;
7; Demos counting of word-pairs observed by looking at a text file.
8; The Sensory API allows easy generalization to other text sources,
9; so working with files is OK for now.
4; Prototype hand-built agent capable of counting things observed in
5; the external environment. Based on the `pair-count.scm` demo in the
6; examples directory.
107;
118; The dataflow pipeline is hand-crafted. (The sensory API is supposed
129; to eventually auto-build these pipelines, but that code is not working
13; yet.) You'll notice that the pipeline below is ... complicated.
14;
15; Most of the demo is in the `examples/pair-count.scm` file. The below
16; is a condensation of that demo into it's working core.
10; yet.)
1711;
1812; The "rest of the demo", where we do something with the word pairs,
1913; is in "generate.scm".
……@@ -63,44 +57,41 @@
6357 (define (incr-cnt edge)
6458 (SetValue edge (Predicate "count")
6559 (Plus (Number 0 0 1)
66 (FloatValueOf edge (Predicate "count") (FloatValueOf (Number 0 0 0))))))
60 (FloatValueOf edge (Predicate "count")
61 (FloatValueOf (Number 0 0 0))))))
6762
6863 ; Given a list (an Atomese LinkValue list) of parse results,
6964 ; extract the edges and increment the count on them.
70 (define (count-edges parsed-stuff)
65 (define (edge-counter EDGE-LIST)
7166 (Filter
7267 (Rule
73 ; (Variable "$edge")
7468 (TypedVariable (Variable "$edge") (Type 'Edge))
7569 (Variable "$edge")
7670 (incr-cnt (Variable "$edge")))
77 parsed-stuff))
78
79 ; Parse text in a private space.
80 (define (parseli phrali)
81 (PureExecLink (LgParseBonds phrali DICT NUML)))
71 EDGE-LIST))
8272
83 ; Given an Atom `phrali` holding text to be parsed, get that text,
84 ; parse it, and increment the counts on the edges.
85 (define (filty phrali)
73 ; Given PASRC holding a stream of parses, filter out the edges,
74 ; and then applu function FUNKY to each edge.
75 (define (edge-filter PASRC FUNKY)
8676 (Filter
8777 (Rule
88 ; Type decl
89 (Glob "$x")
90 ; Match clause - one per parse.
9178 (LinkSignature
92 (Type 'LinkValue) ; the wrapper for the pair
93 (Type 'LinkValue) ; the word-list
94 (LinkSignature ; the edge-list
95 (Type 'LinkValue) ; edge-list wrapper
96 (Glob "$edge-list"))) ; all of the edges
97 ; Pipeline to apply to the resulting match.
98 (count-edges (Glob "$edge-list"))
99 )
100 (parseli phrali)))
79 (Type 'LinkValue)
80 (Variable "$words")
81 (Variable "$edge-list"))
82 ; Apply the function FUNKY to the edge-list
83 (FUNKY (Variable "$edge-list")))
84 PASRC))
85
86 ; Parse text in a private space.
87 (define (priv-parse TXT-SRC)
88 (PureExecLink (LgParseBonds TXT-SRC DICT NUML)))
89
90 ; I dunno. Is private parsing needed?
91 (define (regular-parse TXT-SRC) (LgParseBonds TXT-SRC DICT NUML))
10192
10293 ; Return the parser.
103 (filty txt-stream)
94 (edge-filter edge-counter (regular-parse txt-stream))
10495)
10596
10697; --------------------------------------------------------------
……@@ -108,14 +99,15 @@
10899(define (obs-file FILE-NAME)
109100
110101 ; We don't need to create this over and over; once is enough.
111 (define txt-stream (ValueOf (Concept "foo") (Predicate "some place")))
102 (define txt-stream
103 (ValueOf (Anchor "parse pipe") (Predicate "text src")))
112104 (define parser (make-parser txt-stream))
113105
114106 (define phrali (Open (Type 'TextFileStream)
115107 (Sensory (string-append "file://" FILE-NAME))))
116108
117109 (cog-execute!
118 (SetValue (Concept "foo") (Predicate "some place") phrali))
110 (SetValue (Anchor "parse pipe") (Predicate "text src") phrali))
119111
120112 ; Parse only first line of file:
121113 ; (cog-execute! parser)