| … | … | @@ -173,8 +173,15 @@ |
| 173 | 173 | (cog-execute! demo-filter) |
| 174 | 174 | |
| 175 | 175 | ; Same as above, but this time, ignore the words, and get the edges. |
| 176 | | ; Also, apply the function FUNKY to the edge-list. This will be a handy |
| 177 | | ; place to wire in further processing. |
| 176 | ; Also, apply the function FUNKY to the edge-list. |
| 177 | ; This function is meant to be a handy place to wire in more processing, |
| 178 | ; |
| 179 | ; Note that the result of parsing appears to be double-wrapped in |
| 180 | ; LinkValue. The reason becomes more apparent if one asks for more |
| 181 | ; than just one parse: the outer LinkValue groups all of the parses, |
| 182 | ; while the inner one groups the edges in one parse. Thus, the |
| 183 | ; function FUNKY will be called once per parse, and its argument |
| 184 | ; will be the list of words in that parse. |
| 178 | 185 | (define (edge-filter FUNKY) |
| 179 | 186 | (Filter |
| 180 | 187 | (Rule |
| … | … | @@ -201,7 +208,9 @@ |
| 201 | 208 | (define (incr-cnt edge) |
| 202 | 209 | (SetValue edge (Predicate "count") |
| 203 | 210 | (Plus (Number 0 0 1) |
| 204 | | (FloatValueOf edge (Predicate "count") (FloatValueOf (Number 0 0 0)))))) |
| 211 | (FloatValueOf edge (Predicate "count") |
| 212 | ; The all-zeros provides an initial value, if not set. |
| 213 | (FloatValueOf (Number 0 0 0)))))) |
| 205 | 214 | |
| 206 | 215 | ; Try it: |
| 207 | 216 | (cog-execute! (incr-cnt (Concept "foobar"))) |
| … | … | @@ -213,21 +222,18 @@ |
| 213 | 222 | ; ... or, equivalently, in Atomese: |
| 214 | 223 | (cog-execute! (ValueOf (Concept "foobar") (Predicate "count"))) |
| 215 | 224 | |
| 216 | | ; Wire it into the earlier pipelines |
| 217 | | (define (edge-counter ITEM) |
| 225 | ; Use the previous utility function to wire the counter into |
| 226 | ; the parsing pipeline. |
| 227 | (define (edge-counter EDGE-LIST) |
| 218 | 228 | (Filter |
| 219 | 229 | (Rule |
| 220 | | ; (TypedVariable (Variable "$edge") (Type 'Edge)) |
| 221 | | (LinkSignature |
| 222 | | (Type 'LinkValue) |
| 230 | (TypedVariable (Variable "$edge") (Type 'Edge)) |
| 223 | 231 | (Variable "$edge") |
| 224 | | ) |
| 225 | | (debug-prt (Variable "$edge"))) |
| 226 | | ITEM)) |
| 232 | (incr-cnt (Variable "$edge"))) |
| 233 | EDGE-LIST)) |
| 227 | 234 | |
| 228 | | ; (incr-cnt (Variable "$edge"))) |
| 235 | ; Run it. Watch the counts increment |
| 229 | 236 | (cog-execute! (edge-filter edge-counter)) |
| 230 | | (cog-execute! (edge-filter debug-prt)) |
| 231 | 237 | |
| 232 | 238 | |
| 233 | 239 | ; -------------------------------------------------------------- |