| … | … | @@ -25,26 +25,32 @@ |
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | (define text-blob "this is just a bunch of words you know") |
| 28 | | (define NUML (Number 4)) |
| 29 | | (define DICT (LgDict "any")) |
| 30 | 28 | |
| 31 | 29 | |
| 32 | | ; From inside to out: |
| 33 | | ; LGParseBonds tokenizes a sentence, and then parses it. |
| 34 | | ; The PureExecLink makes sure that the parsing is done in a sub-AtomSpace |
| 35 | | ; so that the main AtomSpace is not garbaged up. |
| 36 | | ; |
| 37 | | ; The result of parsing is a list of pairs. First item in a pair is |
| 38 | | ; the list of words in the sentence; the second is a list of the edges. |
| 39 | | ; Thus, each pair has the form |
| 40 | | ; (LinkValue |
| 41 | | ; (LinkValue (Word "this") (Word "is") (Word "a") (Word "test")) |
| 42 | | ; (LinkValue (Edge ...) (Edge ...) ...)) |
| 43 | | ; |
| 44 | | ; The Filter matches this, so that (Variable "$x") is equated with the |
| 45 | | ; list of Edges. |
| 46 | | ; |
| 47 | | (define (obs-txt PLAIN-TEXT) |
| 30 | ; Return a text parser that counts edges on a stream. The |
| 31 | ; `txt-stream` must be an Atom that can serve as a source of text. |
| 32 | ; Typically, `txt-stream` will be |
| 33 | ; (ValueOf (Concept "some atom") (Predicate "some key")) |
| 34 | ; and the Value there will be a LinkStream from some file or |
| 35 | ; other text source. |
| 36 | (define (make-parser txt-stream) |
| 37 | ; From inside to out: |
| 38 | ; LGParseBonds tokenizes a sentence, and then parses it. |
| 39 | ; The PureExecLink makes sure that the parsing is done in a sub-AtomSpace |
| 40 | ; so that the main AtomSpace is not garbaged up. |
| 41 | ; |
| 42 | ; The result of parsing is a list of pairs. First item in a pair is |
| 43 | ; the list of words in the sentence; the second is a list of the edges. |
| 44 | ; Thus, each pair has the form |
| 45 | ; (LinkValue |
| 46 | ; (LinkValue (Word "this") (Word "is") (Word "a") (Word "test")) |
| 47 | ; (LinkValue (Edge ...) (Edge ...) ...)) |
| 48 | ; |
| 49 | ; The Filter matches this, so that (Variable "$x") is equated with the |
| 50 | ; list of Edges. |
| 51 | ; |
| 52 | (define NUML (Number 4)) |
| 53 | (define DICT (LgDict "any")) |
| 48 | 54 | |
| 49 | 55 | ; Increment the count on one edge. |
| 50 | 56 | (define (incr-cnt edge) |
| … | … | @@ -86,13 +92,36 @@ |
| 86 | 92 | ) |
| 87 | 93 | (parseli phrali))) |
| 88 | 94 | |
| 95 | ; Return the parser. |
| 96 | (filty txt-stream) |
| 97 | ) |
| 98 | |
| 99 | ; Parse a string. |
| 100 | (define (obs-txt PLAIN-TEXT) |
| 101 | (define txt-stream (ValueOf (Concept "foo") (Predicate "some place"))) |
| 102 | (define parser (make-parser txt-stream)) |
| 103 | |
| 89 | 104 | (define phrali (Phrase PLAIN-TEXT)) |
| 90 | | (cog-execute! (filty phrali)) |
| 105 | (cog-set-value! (Concept "foo") (Predicate "some place") phrali) |
| 106 | |
| 107 | (cog-execute! parser) |
| 91 | 108 | |
| 92 | 109 | ; Remove the phrase-link, return the list of edges. |
| 93 | 110 | (cog-extract-recursive! phrali) |
| 94 | 111 | ) |
| 95 | 112 | |
| 113 | (define (obs-file FILE-NAME) |
| 114 | (define txt-stream (ValueOf (Concept "foo") (Predicate "some place"))) |
| 115 | (define parser (make-parser txt-stream)) |
| 116 | |
| 117 | (define phrali (FileRead (string-append "file://" FILE-NAME))) |
| 118 | (cog-set-value! (Concept "foo") (Predicate "some place") phrali) |
| 119 | |
| 120 | (cog-execute! parser) |
| 121 | ) |
| 122 | |
| 123 | ; -------------------------- |
| 124 | ; Issues. |
| 96 | 125 | ; Parses arrive as LinkValues. We want to apply a function to each. |
| 97 | 126 | ; How? Need: |
| 98 | 127 | ; 4) IncrementLink just like cog-inc-value! |
| … | … | @@ -124,3 +153,5 @@ |
| 124 | 153 | |
| 125 | 154 | ; (load "count-agent.scm") |
| 126 | 155 | ; (obs-txt text-blob) |
| 156 | ; (cog-report-counts) |
| 157 | ; (cog-get-atoms 'WordNode) |