worked example: improved-random-sentence
description:
learn some sentence fragments, and then produce a valid sentence
motivated by this: http://write-up.semantic-db.org/221-generating-random-grammatically-correct-sentences.html
this produces the same random sentences as the "random-sentence" example, but using an improved method
code:
pick-from-class |*> #=> spick-elt class |_self>
merge-class (*) #=> smerge[" "] sdrop pick-from-class |_self>
class |A> => |the>
class |B> => |young> . |>
class |C> => |girl> . |boy>
class |D> => |old> . |other> . |>
class |E> => |man> . |woman> . |lady>
class |F> => |saw>
class |G> => |through the>
class |H> => |telescope> . |binoculars> . |night vision goggles>
class |K> #=> merge-class (|B> . |C>) . merge-class (|D> . |E>)
class |M> #=> merge-class (|A> . |K>) . |>
class |N> #=> merge-class (|A> . |K> . |F> . |M> . |G> . |H>)
sentence |*> #=> to-upper[1] class |_self> _ |.>
examples:
sentence
|The other lady saw the old woman through the telescope.>
sentence
|The young boy saw the young girl through the binoculars.>
sentence
|The old woman saw the other man through the telescope.>
sentence
|The young boy saw the young girl through the night vision goggles.>
future:
scale it up, and given a text auto learn these structures
source code:
load sentence.sw
Home