Markov: handle empty reply chains more gracefully

This commit is contained in:
Brian S. Stephan 2013-05-03 16:03:07 -05:00
parent 25e41150af
commit fb477a57b9
1 changed files with 11 additions and 5 deletions

View File

@ -497,9 +497,13 @@ class Markov(Module):
# chop off the seed data at the start
gen_words = gen_words[2:]
# chop off the end text, if it was the keyword indicating an end of chain
if gen_words[-1] == self.stop:
gen_words = gen_words[:-1]
if len(gen_words):
# chop off the end text, if it was the keyword indicating an end of chain
if gen_words[-1] == self.stop:
gen_words = gen_words[:-1]
else:
self.log.warning("after all this we have an empty list of words. "
"there probably isn't any data for this context")
return ' '.join(gen_words)
@ -616,10 +620,12 @@ class Markov(Module):
# check for addresses (the "whoever:" in
# __start1 __start2 whoever: some words)
addressing_suffixes = [':', ',']
if chain[2][-1] in addressing_suffixes and avoid_address:
if len(chain) > 2 and chain[2][-1] in addressing_suffixes and avoid_address:
return chain[3:]
else:
elif len(chain) > 2:
return chain[2:]
else:
return []
def _get_chatter_targets(self):
"""Get all possible chatter targets."""