OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-agents commits / e047db6

Count words as well as edges
e047db6c5fa45ce8b2186b3668eb9961772926dc
by Linas Vepštas <linasvepstas@gmail.com> · 2024-05-03T14:34:49.000Z

Changed files (1) +19 -10

scm/pair-agent/count-agent.scm +19 -10
……@@ -65,21 +65,25 @@
6565 (define (atom-counter ATOM-LIST)
6666 (Filter
6767 (Rule
68 (Variable "$edge")
69 (Variable "$edge")
70 (incr-cnt (Variable "$edge")))
68 ; We could type for safety, but seems like no need...
69 ; (TypedVariable (Variable "$atom")
70 ; (TypeChoice (Type 'Edge) (Type 'Word)))
71 (Variable "$atom") ; vardecl
72 (Variable "$atom") ; body to match
73 (incr-cnt (Variable "$atom")))
7174 ATOM-LIST))
7275
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)
76 ; Given PASRC holding a stream of parses, split it into a list of
77 ; words, and a list of edges, and apply FUNKY to both lists.
78 (define (stream-splitter PASRC FUNKY)
7679 (Filter
7780 (Rule
7881 (LinkSignature
7982 (Type 'LinkValue)
80 (Variable "$words")
83 (Variable "$word-list")
8184 (Variable "$edge-list"))
8285 ; Apply the function FUNKY to the edge-list
86 (FUNKY (Variable "$word-list"))
8387 (FUNKY (Variable "$edge-list")))
8488 PASRC))
8589
……@@ -88,8 +92,10 @@
8892 ; Is there any benefit to private parsing?
8993 ; (edge-filter (PureExecLink parser) edge-counter)
9094
91 ; Return the parser.
92 (edge-filter parser atom-counter)
95 ; Return the assembled counting pipeline.
96 ; All that the user needs to do is to call `cog-execute!` on it,
97 ; until end of file is reached.
98 (stream-splitter parser atom-counter)
9399)
94100
95101; --------------------------------------------------------------
……@@ -113,7 +119,7 @@
113119 ; Loop over all lines.
114120 (define (looper) (cog-execute! parser) (looper))
115121
116 ; At end of file, exception will be thrown. Catch it.
122 ; At end of file, exception will be thrown. Catch it. Print it.
117123 (catch #t looper
118124 (lambda (key . args) (format #t "The end ~A\n" key)))
119125
……@@ -127,6 +133,9 @@
127133; Look at results
128134; (cog-report-counts)
129135; (cog-execute! (ValueOf (Word "is") (Predicate "count")))
136; (cog-execute! (ValueOf
137; (Edge (Bond "ANY") (List (Word "is") (Word "a")))
138; (Predicate "count")))
130139;
131140; Erase all words, so we can try again.
132141; (extract-type 'WordNode)