txlyre 6 tháng trước cách đây
mục cha
commit
fd9ddc1db9
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      markov.py

+ 5 - 1
markov.py

@@ -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()