diff --git a/dr_botzo/markov/lib.py b/dr_botzo/markov/lib.py index 12b794a..e75c8da 100644 --- a/dr_botzo/markov/lib.py +++ b/dr_botzo/markov/lib.py @@ -34,7 +34,7 @@ def generate_line(context, topics=None, min_words=15, max_words=30, max_sentence return line -def generate_longish_sentence(context, topics=None, min_words=15, max_words=30, max_tries=5): +def generate_longish_sentence(context, topics=None, min_words=15, max_words=30, max_tries=100): """Generate a Markov chain, but throw away the short ones unless we get desperate.""" sent = "" @@ -114,6 +114,11 @@ def generate_sentence(context, topics=None, min_words=15, max_words=30): words = [word for word in words if word not in (MarkovState._start1, MarkovState._start2, MarkovState._stop)] + # if what we found is too long, abandon it, sadly + if len(words) > max_words: + log.debug("%s is too long, i'm going to give up on it", words) + words.clear() + return words