@@ -28,7 +28,11 @@ class Markov:
if not words:
return self.generate()
- return " ".join(words)
+ text = " ".join(words)
+ text = re.sub(r"(?:^| )?((\.{2,})|(\!{2,})|(\?{2,})|([.?!,:;\(\)\"'\$\+\-–—]))(?: |$)", r"\1 ", text)
+ text = text.strip()
+
+ return text
def rebuild(self):
self.chain = markovify.Chain(self.corpus, config.MARKOV_STATE_SIZE).compile()