markov: work harder to avoid short sentences

not sure how effective this will be, but it's worth a shot
This commit is contained in:
Brian S. Stephan 2016-06-30 23:16:49 -05:00
parent 464727cc74
commit ab9edb2c9b
1 changed files with 6 additions and 1 deletions

View File

@ -99,15 +99,20 @@ def generate_sentence(context, topics=None, min_words=15, max_words=30):
else:
target_hits = []
# if we're over min_words, and got a stop naturally, use it
if len(words) > min_words and MarkovState._stop in new_states:
# if we're over min_words, and got a stop naturally, use it
log.debug("found a stop in the results, intentionally picking it")
words.append(MarkovState._stop)
elif len(target_hits) > 0:
# if there's a target word in the states, pick it
target_hit = random.choice(target_hits)
log.debug("found a topic hit %s, using it", target_hit)
topics.remove(target_hit)
words.append(target_hit)
elif len(words) <= min_words:
# if we still need more words, intentionally avoid stop
words.append(get_word_out_of_states(new_states.exclude(v=MarkovState._stop)))
log.debug("picked (stop avoidance) %s", words[-1])
else:
words.append(get_word_out_of_states(new_states))
log.debug("picked %s", words[-1])