| … | … | @@ -110,14 +110,32 @@ |
| 110 | 110 | (cog-extract-recursive! phrali) |
| 111 | 111 | ) |
| 112 | 112 | |
| 113 | ; Parse contents of a file. |
| 113 | 114 | (define (obs-file FILE-NAME) |
| 114 | 115 | (define txt-stream (ValueOf (Concept "foo") (Predicate "some place"))) |
| 115 | 116 | (define parser (make-parser txt-stream)) |
| 116 | 117 | |
| 117 | 118 | (define phrali (FileRead (string-append "file://" FILE-NAME))) |
| 118 | | (cog-set-value! (Concept "foo") (Predicate "some place") phrali) |
| 119 | 119 | |
| 120 | | (cog-execute! parser) |
| 120 | ; This will do the trick to set the value. Except it creates an Atom |
| 121 | ; (cog-execute! |
| 122 | ; (SetValue (Concept "foo") (Predicate "some place") |
| 123 | ; (FileRead "file:///tmp/demo.txt"))) |
| 124 | ; Same as bove, without creating Atom. |
| 125 | (cog-set-value! (Concept "foo") (Predicate "some place") |
| 126 | (cog-execute! phrali)) |
| 127 | |
| 128 | ; Parse only first line of file: |
| 129 | ; (cog-execute! parser) |
| 130 | |
| 131 | ; Loop over all lines. |
| 132 | (define (looper) (cog-execute! parser) (looper)) |
| 133 | |
| 134 | ; At end of file, exception will be thrown. Catch it. |
| 135 | (catch #t looper |
| 136 | (lambda (key . args) (format #t "The end ~A\n" key))) |
| 137 | |
| 138 | (cog-extract-recursive! phrali) |
| 121 | 139 | ) |
| 122 | 140 | |
| 123 | 141 | ; -------------------------- |
| … | … | @@ -153,5 +171,6 @@ |
| 153 | 171 | |
| 154 | 172 | ; (load "count-agent.scm") |
| 155 | 173 | ; (obs-txt text-blob) |
| 174 | ; (obs-file "/tmp/demo.txt") |
| 156 | 175 | ; (cog-report-counts) |
| 157 | 176 | ; (cog-get-atoms 'WordNode) |