| … | … | @@ -76,18 +76,23 @@ |
| 76 | 76 | ; it gets the next lump from the input. In the below, four stream |
| 77 | 77 | ; elements will be generated for each input sentence. |
| 78 | 78 | |
| 79 | | ; The declaration is very simple: just promise to apply the flattener |
| 80 | | ; to the parse stream. |
| 79 | ; The declaration is simple: just promise to apply the flattener |
| 80 | ; to the parse stream. Well, the flattener striped off one too |
| 81 | ; many layers, so the LinkSignature puts one layer back. |
| 81 | 82 | (define linker |
| 82 | | (PromiseLink (Type 'FlatStream) |
| 83 | | parse-stream)) |
| 83 | (LinkSignature (Type 'LinkValue) |
| 84 | (PromiseLink (Type 'FlatStream) |
| 85 | parse-stream))) |
| 84 | 86 | |
| 85 | | ; Just like the above. Create the anchor for the linkage text. |
| 87 | ; Sniff test. Does it work? |
| 88 | ; (cog-execute! linker) |
| 89 | |
| 90 | ; Just like the above. Create the anchor for the linkages. |
| 86 | 91 | (cog-execute! |
| 87 | 92 | (SetValue (Anchor "parse pipe") (Predicate "linkage stream") |
| 88 | | linker)) |
| 93 | (DontExec linker))) |
| 89 | 94 | |
| 90 | | ; Just as before: the Anchor reference. |
| 95 | ; Just as before: the Anchor reference to the stream of linkages. |
| 91 | 96 | (define linkage-stream |
| 92 | 97 | (ValueOf (Anchor "parse pipe") (Predicate "linkage stream"))) |
| 93 | 98 | |
| … | … | @@ -95,7 +100,12 @@ |
| 95 | 100 | ; (cog-execute! linkage-stream) |
| 96 | 101 | |
| 97 | 102 | ; -------------------------------------------------------- |
| 98 | | ; A rule to extract just the bonds from the stream |
| 103 | ; Each linkage has two parts: a word-list, and a list of linkages |
| 104 | ; between the words. The word-list is reapeated each time, as the |
| 105 | ; spelling-checker might select different alternatives for mis-spelled |
| 106 | ; words. The tokenizer might split them differently. For this demo, |
| 107 | ; we want to access only the bond list. The filer below will extract |
| 108 | ; this. |
| 99 | 109 | |
| 100 | 110 | (define bonder |
| 101 | 111 | (Filter |
| … | … | @@ -103,7 +113,7 @@ |
| 103 | 113 | (VariableList |
| 104 | 114 | (TypedVariable (Variable "$words") (Type 'LinkValue)) |
| 105 | 115 | (TypedVariable (Variable "$bonds") (Type 'LinkValue))) |
| 106 | | (LinkSignature (Type 'LinkValue) |
| 116 | (LinkSignature (TypeInh 'LinkValue) |
| 107 | 117 | (Variable "$words") |
| 108 | 118 | (Variable "$bonds")) |
| 109 | 119 | (Variable "$bonds")) |
| … | … | @@ -112,14 +122,18 @@ |
| 112 | 122 | ; Sniff test. Does it work? |
| 113 | 123 | ; (cog-execute! bonder) |
| 114 | 124 | |
| 115 | | ; Create the anchor for the parsed text. |
| 125 | ; Create the anchor for the word bonds |
| 116 | 126 | (cog-execute! |
| 117 | | (SetValue (Anchor "parse pipe") (Predicate "parsed text") |
| 118 | | (DontExec parser))) |
| 127 | (SetValue (Anchor "parse pipe") (Predicate "word bonds") |
| 128 | (DontExec bonder))) |
| 119 | 129 | |
| 120 | 130 | ; Anchor reference |
| 121 | | (define parse-stream |
| 122 | | (ValueOf (Anchor "parse pipe") (Predicate "parsed text"))) |
| 131 | (define bond-stream |
| 132 | (ValueOf (Anchor "parse pipe") (Predicate "word bonds"))) |
| 133 | |
| 134 | ; Sniff test. Does it work? |
| 135 | ; (cog-execute! bond-stream) |
| 136 | |
| 123 | 137 | |
| 124 | 138 | ; -------------------------------------------------------- |
| 125 | 139 | ; The End! That's All, Folks! |