| … | … | @@ -45,7 +45,8 @@ |
| 45 | 45 | (define parser |
| 46 | 46 | (Filter |
| 47 | 47 | (Rule |
| 48 | | (TypedVariable (Variable "$x") (Type 'StringValue)) |
| 48 | (TypedVariable (Variable "$x") (Type 'StringStream)) |
| 49 | ; (Variable "$x") ; Use this for the untyped vardecl |
| 49 | 50 | (Variable "$x") |
| 50 | 51 | (LgParseBonds (Variable "$x") (LgDict "en") (Number 4))) |
| 51 | 52 | txt-stream)) |
| … | … | @@ -66,66 +67,33 @@ |
| 66 | 67 | ; (cog-execute! parse-stream) |
| 67 | 68 | |
| 68 | 69 | ; -------------------------------------------------------- |
| 69 | | ; XXXX Everything below here is broken junk XXXX |
| 70 | | ; A rule that unto |
| 71 | | |
| 72 | | (define fs (FlatStream parse-stream)) |
| 73 | | (cog-set-value! (Anchor "parse pipe") (Predicate "linkage stream") fs) |
| 74 | | |
| 70 | ; The parser above was configured to generate four linkages (parses) |
| 71 | ; per sentance. These are bundled together in a single LinkValue. |
| 72 | ; It is convenient to process them one at a time, rather than in one |
| 73 | ; big gulp. The FlatStream provides this utility. It accepts as input, |
| 74 | ; a stream where data items are bundled into lumps (with LinkValue), |
| 75 | ; and then doles them out one by until the lump has been emptied. Then |
| 76 | ; it gets the next lump from the input. In the below, four stream |
| 77 | ; elements will be generated for each input sentence. |
| 78 | |
| 79 | ; The declaration is very simple: just promise to apply the flattener |
| 80 | ; to the parse stream. |
| 75 | 81 | (define linker |
| 76 | 82 | (PromiseLink (Type 'FlatStream) |
| 77 | 83 | parse-stream)) |
| 78 | 84 | |
| 79 | | ; Create the anchor for the lingae text. |
| 85 | ; Just like the above. Create the anchor for the linkage text. |
| 80 | 86 | (cog-execute! |
| 81 | 87 | (SetValue (Anchor "parse pipe") (Predicate "linkage stream") |
| 82 | 88 | linker)) |
| 83 | 89 | |
| 84 | | ; Anchor reference |
| 90 | ; Just as before: the Anchor reference. |
| 85 | 91 | (define linkage-stream |
| 86 | 92 | (ValueOf (Anchor "parse pipe") (Predicate "linkage stream"))) |
| 87 | 93 | |
| 88 | 94 | ; Sniff test. Does it work? |
| 89 | 95 | ; (cog-execute! linkage-stream) |
| 90 | 96 | |
| 91 | | (cog-execute! (CollectionOf (Type 'List) linkage-stream)) |
| 92 | | |
| 93 | | (define relinker (cog-execute! linker)) |
| 94 | | |
| 95 | | (cog-value-ref fs 0) |
| 96 | | |
| 97 | | (use-modules (opencog) (opencog exec)) |
| 98 | | (define syn |
| 99 | | (LinkValue |
| 100 | | (LinkValue |
| 101 | | (FloatValue 1 2 3) |
| 102 | | (FloatValue 4 5 6)) |
| 103 | | |
| 104 | | (LinkValue |
| 105 | | (FloatValue 7 8 9) |
| 106 | | (FloatValue 10 11 12)))) |
| 107 | | |
| 108 | | (cog-set-value! (Concept "foo") (Predicate "bar") syn) |
| 109 | | |
| 110 | | (define fs (FlatStream (ValueOf (Concept "foo") (Predicate "bar")))) |
| 111 | | (cog-value-ref fs 0) |
| 112 | | |
| 113 | | |
| 114 | | ; Sniff test. Does it work? |
| 115 | | ; (cog-execute! linker) |
| 116 | | |
| 117 | | ; Create the anchor for the parsed text. |
| 118 | | (cog-execute! |
| 119 | | (SetValue (Anchor "parse pipe") (Predicate "linkages") |
| 120 | | (DontExec linker))) |
| 121 | | |
| 122 | | ; Anchor reference |
| 123 | | (define linkage-stream |
| 124 | | (ValueOf (Anchor "parse pipe") (Predicate "linkages"))) |
| 125 | | |
| 126 | | ; Sniff test. Does it work? |
| 127 | | ; (cog-execute! linkage-stream) |
| 128 | | |
| 129 | 97 | ; -------------------------------------------------------- |
| 130 | 98 | ; A rule to extract just the bonds from the stream |
| 131 | 99 | |