The basic mechanism is simple. For each couple of words, you maintain a list of possible successive words. For example, in the text suggested by me: this is an interesting text because this is
what could be a more interesting text for us
you have the following:this is => an, what (note: "this is" occurs two times)
is an => interesting
an interesting => text
interesting text => because, for
text because => this
because this => is
("this is" has already been included above)
is what => could
...
When generating a text, given the pair of "last written words", you go into your table and select one of the successors; in most cases (at least in the example) you are forced to a get the single word in the list, but in others you can choose from more alternatives (2 in our case, in particular for the couples "this is" and "interesting text").
If you want to apply this mechanism to the letters, you can "simply" substitute "letter" to "word" in the program. This means hacking on the split in the foreach while taking into proper account newlines in the text (in the program, the newline is considered a "terminator", see $NONWORD). The implementation is left as an exercise, as it would not fit in the border of this reply :)
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
Don't fool yourself.
|