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
This commit is contained in:
parent
390e925360
commit
988fe8729a
|
@ -406,6 +406,14 @@ class Markov(Module):
|
||||||
if gen_words[-1] == self.stop:
|
if gen_words[-1] == self.stop:
|
||||||
gen_words = gen_words[:-1]
|
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
|
# new word 1
|
||||||
key_hits = self._retrieve_chains_for_key(self.start1, self.start2, context_id)
|
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))
|
gen_words.append(self._get_suitable_word_from_choices(key_hits, gen_words, min_size))
|
||||||
|
|
Loading…
Reference in New Issue