Markov: append a stop if we have nothing to append from a chain

somehow a chain led us down a path where there are no values for
the keys in the chain. if that happens, just abort.

i'm not quite sure how this could happen
This commit is contained in:
Brian S. Stephan 2011-03-17 17:24:11 -05:00
parent 2b8f0d2843
commit 5913a95165
1 changed files with 2 additions and 0 deletions

View File

@ -284,6 +284,8 @@ class Markov(Module):
else:
if len(gen_words) < min_size and len(filter(lambda a: a != self.stop, key_hits)) > 0:
gen_words.append(random.choice(filter(lambda a: a != self.stop, key_hits)))
elif len(key_hits) <= 0:
gen_words.append(self.stop)
else:
gen_words.append(random.choice(key_hits))