OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-sensory commits / be5818f

Continue workig on the parsing demo
be5818f8b7631e8640f6f800670581ba9bb97ba0
by Linas Vepštas <linasvepstas@gmail.com> · 2025-10-27T02:15:58.000Z

Changed files (1) +15 -47

examples/parse-pipeline.scm +15 -47
……@@ -45,7 +45,8 @@
4545(define parser
4646 (Filter
4747 (Rule
48 (TypedVariable (Variable "$x") (Type 'StringValue))
48 (TypedVariable (Variable "$x") (Type 'StringStream))
49 ; (Variable "$x") ; Use this for the untyped vardecl
4950 (Variable "$x")
5051 (LgParseBonds (Variable "$x") (LgDict "en") (Number 4)))
5152 txt-stream))
……@@ -66,66 +67,33 @@
6667; (cog-execute! parse-stream)
6768
6869; --------------------------------------------------------
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.
7581(define linker
7682 (PromiseLink (Type 'FlatStream)
7783 parse-stream))
7884
79; Create the anchor for the lingae text.
85; Just like the above. Create the anchor for the linkage text.
8086(cog-execute!
8187 (SetValue (Anchor "parse pipe") (Predicate "linkage stream")
8288 linker))
8389
84; Anchor reference
90; Just as before: the Anchor reference.
8591(define linkage-stream
8692 (ValueOf (Anchor "parse pipe") (Predicate "linkage stream")))
8793
8894; Sniff test. Does it work?
8995; (cog-execute! linkage-stream)
9096
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
12997; --------------------------------------------------------
13098; A rule to extract just the bonds from the stream
13199