| … | … | @@ -135,7 +135,7 @@ |
| 135 | 135 | |
| 136 | 136 | (define demo-filter |
| 137 | 137 | (Filter |
| 138 | | (Glob "$x") |
| 138 | (Variable "$x") |
| 139 | 139 | (LgParseBonds (Phrase "this is a test") (LgDict "any") (Number 1)))) |
| 140 | 140 | |
| 141 | 141 | ; Run it. |
| … | … | @@ -145,76 +145,51 @@ |
| 145 | 145 | (define demo-filter |
| 146 | 146 | (Filter |
| 147 | 147 | (Rule |
| 148 | | (Glob "$x") ; Input |
| 149 | | (Glob "$x")) ; Output |
| 148 | (Variable "$x") ; Input |
| 149 | (Variable "$x")) ; Output |
| 150 | 150 | (LgParseBonds (Phrase "this is a test") (LgDict "any") (Number 1)))) |
| 151 | 151 | |
| 152 | 152 | ; Run it. |
| 153 | 153 | (cog-execute! demo-filter) |
| 154 | 154 | |
| 155 | 155 | ; Same as above, but now start matching stuff inside the stream. |
| 156 | | ; This is still an almost trivial no-op; but it does unwrap one |
| 157 | | ; layer of LinkValue. |
| 156 | ; Each item in the stream is a pair: a list of words, followed |
| 157 | ; by a list of edges. Match these two, and keep the words. |
| 158 | 158 | (define demo-filter |
| 159 | 159 | (Filter |
| 160 | 160 | (Rule |
| 161 | 161 | ; Match clause - one per parse. |
| 162 | 162 | (LinkSignature |
| 163 | 163 | (Type 'LinkValue) |
| 164 | | (Glob "$stuff")) |
| 164 | (Variable "$words") |
| 165 | (Variable "$edges")) |
| 165 | 166 | |
| 166 | 167 | ; Output |
| 167 | | (Glob "$stuff")) |
| 168 | (Variable "$words")) |
| 168 | 169 | |
| 169 | 170 | (LgParseBonds (Phrase "this is a test") (LgDict "any") (Number 1)))) |
| 170 | 171 | |
| 171 | 172 | ; Run it. |
| 172 | 173 | (cog-execute! demo-filter) |
| 173 | 174 | |
| 174 | | ; Extracting the desired components is easier if a printer is used for |
| 175 | | ; debugging. This allows the innards of the match clause to be viewed |
| 176 | | ; directly. |
| 177 | | (define demo-word-filter |
| 178 | | (Filter |
| 179 | | (Rule |
| 180 | | ; Match clause - one per parse. |
| 181 | | ; The LinkValue wraps two more: one holding the words |
| 182 | | ; in the sentence, and another holding the word-pairs. |
| 183 | | (LinkSignature |
| 184 | | (Type 'LinkValue) |
| 185 | | (LinkSignature |
| 186 | | (Type 'LinkValue) ; This matches the word-list |
| 187 | | (Glob "$words")) |
| 188 | | (Type 'LinkValue)) ; This matches the edge-list |
| 189 | | |
| 190 | | ; Output clause |
| 191 | | (debug-prt (Glob "$words"))) |
| 192 | | |
| 193 | | (LgParseBonds (Phrase "this is a test") (LgDict "any") (Number 1)))) |
| 194 | | |
| 195 | | ; Run it. |
| 196 | | (cog-execute! demo-word-filter) |
| 197 | | |
| 198 | 175 | ; Same as above, but this time, ignore the words, and get the edges. |
| 199 | | ; Also, replace the printer function with a generic function FUNKY. |
| 200 | | ; This is a handy place to wire in further processing. |
| 176 | ; Also, apply the function FUNKY to the edge-list. This will be a handy |
| 177 | ; place to wire in further processing. |
| 201 | 178 | (define (edge-filter FUNKY) |
| 202 | 179 | (Filter |
| 203 | 180 | (Rule |
| 204 | 181 | ; Match clause - one per parse. |
| 205 | 182 | (LinkSignature |
| 206 | | (Type 'LinkValue) ; type of (vertex,edge) pair |
| 207 | | (Type 'LinkValue) ; the word-list |
| 208 | | (LinkSignature ; the edge-list |
| 209 | | (Type 'LinkValue) ; edge-list wrapper |
| 210 | | (Glob "$edge-list"))) ; all of the edges |
| 183 | (Type 'LinkValue) |
| 184 | (Variable "$words") |
| 185 | (Variable "$edge-list")) |
| 186 | |
| 211 | 187 | ; Apply the functin FUNKY to the edge-list |
| 212 | | (FUNKY (Glob "$edge-list")) |
| 188 | (FUNKY (Variable "$edge-list")) |
| 213 | 189 | ) |
| 214 | 190 | (LgParseBonds (Phrase "this is a test") (LgDict "any") (Number 1)))) |
| 215 | 191 | |
| 216 | | ; Try it! |
| 217 | | |
| 192 | ; Try it! Use the debug printer as the function to call. |
| 218 | 193 | (cog-execute! (edge-filter debug-prt)) |
| 219 | 194 | |
| 220 | 195 | ; -------------------------------------------------------------- |
| … | … | @@ -239,18 +214,21 @@ |
| 239 | 214 | (cog-execute! (ValueOf (Concept "foobar") (Predicate "count"))) |
| 240 | 215 | |
| 241 | 216 | ; Wire it into the earlier pipelines |
| 242 | | (define edge-counter |
| 217 | (define (edge-counter ITEM) |
| 243 | 218 | (Filter |
| 244 | 219 | (Rule |
| 245 | 220 | ; (TypedVariable (Variable "$edge") (Type 'Edge)) |
| 246 | 221 | (LinkSignature |
| 247 | | (TypeNode 'LinkValue) |
| 248 | | (Glob "$edge")) |
| 249 | | (debug-prt (Glob "$edge"))) |
| 222 | (Type 'LinkValue) |
| 223 | (Variable "$edge") |
| 224 | ) |
| 225 | (debug-prt (Variable "$edge"))) |
| 226 | ITEM)) |
| 227 | |
| 250 | 228 | ; (incr-cnt (Variable "$edge"))) |
| 251 | | edge-filter)) |
| 229 | (cog-execute! (edge-filter edge-counter)) |
| 230 | (cog-execute! (edge-filter debug-prt)) |
| 252 | 231 | |
| 253 | | (cog-execute! edge-counter) |
| 254 | 232 | |
| 255 | 233 | ; -------------------------------------------------------------- |
| 256 | 234 | ; -------------------------------------------------------------- |