| … | … | @@ -44,35 +44,32 @@ |
| 44 | 44 | ; The Filter matches this, so that (Variable "$x") is equated with the |
| 45 | 45 | ; list of Edges. |
| 46 | 46 | ; |
| 47 | | ; XXX Major design flaw, still needs work: the PhraseLink is placed in |
| 48 | | ; the main AtomSpace. Thus, it accumulates there, plus also all of the |
| 49 | | ; other Links that wrap it, including LgParseBinds, Rule, Filter etc. |
| 50 | | ; Nuking the PhraseLink also nukes those, so lots of churn. Alternative |
| 51 | | ; is to pass PhraseLink as a value, but then have threading issues... |
| 52 | | ; ugh. let me think a moment. |
| 53 | | ; |
| 54 | 47 | (define (obs-txt PLAIN-TEXT) |
| 55 | 48 | |
| 49 | ; Increment the count on one edge. |
| 56 | 50 | (define (incr-cnt edge) |
| 57 | 51 | (SetValue edge (Predicate "count") |
| 58 | 52 | (Plus (Number 0 0 1) |
| 59 | 53 | (FloatValueOf edge (Predicate "count") (FloatValueOf (Number 0 0 0)))))) |
| 60 | 54 | |
| 61 | | (define (extract stuff) |
| 55 | ; Given a list (an Atomese LinkValue list) of parse results, |
| 56 | ; extract the edges and increment the count on them. |
| 57 | (define (count-edges parsed-stuff) |
| 62 | 58 | (Filter |
| 63 | 59 | (Rule |
| 64 | | (Variable "$edge") |
| 65 | | ; (TypedVariable (Variable "$edge") (Type 'Edge)) |
| 60 | ; (Variable "$edge") |
| 61 | (TypedVariable (Variable "$edge") (Type 'Edge)) |
| 66 | 62 | (Variable "$edge") |
| 67 | 63 | (incr-cnt (Variable "$edge"))) |
| 68 | | stuff)) |
| 64 | parsed-stuff)) |
| 69 | 65 | |
| 66 | ; Parse text in a private space. |
| 70 | 67 | (define (parseli phrali) |
| 71 | 68 | (PureExecLink (LgParseBonds phrali DICT NUML))) |
| 72 | 69 | |
| 73 | | (define phrali (Phrase PLAIN-TEXT)) |
| 74 | | |
| 75 | | (define filty |
| 70 | ; Given an Atom `phrali` hold text to be parsed, get that text, |
| 71 | ; parse it, and increment the counts on the edges. |
| 72 | (define (filty phrali) |
| 76 | 73 | (Filter |
| 77 | 74 | (Rule |
| 78 | 75 | ; Type decl |
| … | … | @@ -85,15 +82,15 @@ |
| 85 | 82 | (Type 'LinkValue) ; edge-list wrapper |
| 86 | 83 | (Glob "$x"))) ; all of the edges |
| 87 | 84 | ; Rewrite |
| 88 | | (extract (Glob "$x")) |
| 85 | (count-edges (Glob "$x")) |
| 89 | 86 | ) |
| 90 | | (parseli (phrali)))) |
| 87 | (parseli phrali))) |
| 91 | 88 | |
| 92 | | (define parses (cog-execute! filty)) |
| 89 | (define phrali (Phrase PLAIN-TEXT)) |
| 90 | (cog-execute! (filty phrali)) |
| 93 | 91 | |
| 94 | | ; Remove the phrase-link, too. |
| 92 | ; Remove the phrase-link, return the list of edges. |
| 95 | 93 | (cog-extract-recursive! phrali) |
| 96 | | parses |
| 97 | 94 | ) |
| 98 | 95 | |
| 99 | 96 | ; Parses arrive as LinkValues. We want to apply a function to each. |
| … | … | @@ -123,7 +120,7 @@ |
| 123 | 120 | (define txt-stream-gen |
| 124 | 121 | (ValueOf (Concept "foo") (Predicate "some place"))) |
| 125 | 122 | |
| 126 | | (cog-execute! (LgParseBonds txt-stream-gen DICT NUML)) |
| 123 | ; (cog-execute! (LgParseBonds txt-stream-gen DICT NUML)) |
| 127 | 124 | |
| 128 | 125 | ; (load "count-agent.scm") |
| 129 | 126 | ; (obs-txt text-blob) |