OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-sensory commits / dd3d80f

Continue work on the parsing demo
dd3d80fbeafeab13c0417aa9c0517c6f9fe12a8f
by Linas Vepštas <linasvepstas@gmail.com> · 2025-10-27T05:33:11.000Z

Changed files (1) +28 -14

examples/parse-pipeline.scm +28 -14
……@@ -76,18 +76,23 @@
7676; it gets the next lump from the input. In the below, four stream
7777; elements will be generated for each input sentence.
7878
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.
8182(define linker
82 (PromiseLink (Type 'FlatStream)
83 parse-stream))
83 (LinkSignature (Type 'LinkValue)
84 (PromiseLink (Type 'FlatStream)
85 parse-stream)))
8486
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.
8691(cog-execute!
8792 (SetValue (Anchor "parse pipe") (Predicate "linkage stream")
88 linker))
93 (DontExec linker)))
8994
90; Just as before: the Anchor reference.
95; Just as before: the Anchor reference to the stream of linkages.
9196(define linkage-stream
9297 (ValueOf (Anchor "parse pipe") (Predicate "linkage stream")))
9398
……@@ -95,7 +100,12 @@
95100; (cog-execute! linkage-stream)
96101
97102; --------------------------------------------------------
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.
99109
100110(define bonder
101111 (Filter
……@@ -103,7 +113,7 @@
103113 (VariableList
104114 (TypedVariable (Variable "$words") (Type 'LinkValue))
105115 (TypedVariable (Variable "$bonds") (Type 'LinkValue)))
106 (LinkSignature (Type 'LinkValue)
116 (LinkSignature (TypeInh 'LinkValue)
107117 (Variable "$words")
108118 (Variable "$bonds"))
109119 (Variable "$bonds"))
……@@ -112,14 +122,18 @@
112122; Sniff test. Does it work?
113123; (cog-execute! bonder)
114124
115; Create the anchor for the parsed text.
125; Create the anchor for the word bonds
116126(cog-execute!
117 (SetValue (Anchor "parse pipe") (Predicate "parsed text")
118 (DontExec parser)))
127 (SetValue (Anchor "parse pipe") (Predicate "word bonds")
128 (DontExec bonder)))
119129
120130; 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
123137
124138; --------------------------------------------------------
125139; The End! That's All, Folks!