in reply to Re: How do I use this Markov generator?
in thread How do I use this Markov generator?

Thanks, I got it working now. Although, this program generates text based on words. How difficult would it be to make it generate text based on characters?
  • Comment on Re^2: How do I use this Markov generator?

Replies are listed 'Best First'.
Re^3: How do I use this Markov generator?
by Anonymous Monk on Apr 20, 2007 at 03:35 UTC
    Same level of difficulty
      Unfortunately I am very new to Perl and I do not have any understanding of Markov chains. What would one need to do to convert this program into a character-level Markov text generator?
        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.