Regarding the use of the Markov chain algorithm for generating text -


i'm reading book 'the practice of programming' brian w. kernighan , rob pike. chapter 3 provides algorithm markov chain approach reads source text , uses generate random text "reads well" (meaning output closer proper-sounding english gibberish):

set w1 , w2 first 2 words in source text print w1 , w2 loop:    randomly choose w3, 1 of successors of prefix w1 , w2 in source text    print w3    replace w1 , w2 w2 , w3    repeat loop 

my question is: what's standard way handle situation new values w2 , w3 have no successor in source text?

many in advance!

here options:

  1. choose word @ random? (always works)
  2. choose new w2 @ random? (can conceivably still loop)
  3. back previous w1 , w2? (can conceivably still loop)

i'd go trying #2 or #3 once, fallback #1 -- work.


Comments