| … | … | @@ -50,7 +50,67 @@ |
| 50 | 50 | ; that cruft might be confusing. |
| 51 | 51 | |
| 52 | 52 | ; -------------------------------------------------------------- |
| 53 | | ; Next ... |
| 53 | ; Some philosophy: |
| 54 | ; The filters and pipelines in the rest of this demo would be easy to |
| 55 | ; create, if one was writing in pure scheme. Or, heck, even Python: |
| 56 | ; there are Python wrappers into the AtomSpace. But that's not the |
| 57 | ; point. The goal here is to do it in Atomese, so that the processing |
| 58 | ; pipeline is stored in the AtomSpace, as Atomese, where other agents |
| 59 | ; can examine it, work with it, modify it, hook it up, etc. |
| 60 | ; |
| 61 | ; For these demos, all of this hooking-up is purely manual. The sensory |
| 62 | ; project (in https://github.com/opencog/sensory) aims to automate all |
| 63 | ; of that; it's not quite ready and is still under construction. |
| 64 | ; |
| 65 | ; For debugging the demos here, we need a printer that can be called |
| 66 | ; from Atomese. So here's how to call back into scheme from Atomese. |
| 67 | ; This works for python, too. |
| 68 | |
| 69 | ; Call some arbitrary scheme function, and pass two arguments: |
| 70 | (define exo |
| 71 | (ExecutionOutput |
| 72 | (GroundedSchema "scm: foo") ; the function |
| 73 | (List (Concept "bar") (Concept "baz")))) ; the arguments |
| 74 | |
| 75 | (define (foo x y) |
| 76 | (format #t "I got ~A and ~A\n" x y) |
| 77 | (Concept "this is the foo reply")) |
| 78 | |
| 79 | ; Run it and see. |
| 80 | (cog-execute! exo) |
| 81 | |
| 82 | ; Now, define the utility printer we actually need: |
| 83 | (define (print-atom x) (format #t "Got ~A" x)) |
| 84 | |
| 85 | (define (debug-prt x) |
| 86 | (ExecutionOutput |
| 87 | (GroundedSchema "scm: print-atom") |
| 88 | (List x))) |
| 89 | |
| 90 | ; -------------------------------------------------------------- |
| 91 | ; Create a filter that will extract just the edges from the compund |
| 92 | ; stream demoed above. This filter will ignore the list of words, |
| 93 | ; and will iterate over the list of edges. |
| 94 | ; |
| 95 | |
| 96 | (define edge-filter |
| 97 | (Filter |
| 98 | (Rule |
| 99 | ; Type decl |
| 100 | (Glob "$x") |
| 101 | ; Match clause - one per parse. |
| 102 | (LinkSignature |
| 103 | (Type 'LinkValue) ; the wrapper for the pair |
| 104 | (Type 'LinkValue) ; the word-list |
| 105 | (LinkSignature ; the edge-list |
| 106 | (Type 'LinkValue) ; edge-list wrapper |
| 107 | (Glob "$edge-list"))) ; all of the edges |
| 108 | ; Pipeline to apply to the resulting match. |
| 109 | (count-edges (Glob "$edge-list")) |
| 110 | ) |
| 111 | (LgParseBonds (Phrase "this is a test") (LgDict "any") (Number 1)))) |
| 112 | |
| 113 | (cog-execute! edge-filter) |
| 54 | 114 | |
| 55 | 115 | ; -------------------------------------------------------------- |
| 56 | 116 | ; This demo starts where the `file-read.scm` demo in the sensory |