From 988fe8729a450c6e8889a5db30d4b47ab7dbf031 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 29 Jul 2012 09:43:06 -0500 Subject: [PATCH] Markov: add punctuation between chains when starting a second (or Nth) chain because the results so far are too short, add punctuation to the end of the chain, just to make things feel a bit more natural --- modules/Markov.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/Markov.py b/modules/Markov.py index 5b5f42b..ffb15ae 100644 --- a/modules/Markov.py +++ b/modules/Markov.py @@ -406,6 +406,14 @@ class Markov(Module): if gen_words[-1] == self.stop: gen_words = gen_words[:-1] + # monkey with the end word to make it more like an actual sentence end + sentence_end = gen_words[-1] + eos_punctuation = ['!', '?', ',', '.'] + if sentence_end[-1] not in eos_punctuation: + random.shuffle(eos_punctuation) + gen_words[-1] = sentence_end + eos_punctuation.pop() + self.log.debug("monkeyed with end of sentence, it's now: {0:s}".format(gen_words[:-1])) + # new word 1 key_hits = self._retrieve_chains_for_key(self.start1, self.start2, context_id) gen_words.append(self._get_suitable_word_from_choices(key_hits, gen_words, min_size))