txlyre 2 päivää sitten
vanhempi
commit
710d14e027
1 muutettua tiedostoa jossa 6 lisäystä ja 1 poistoa
  1. 6 1
      markov.py

+ 6 - 1
markov.py

@@ -2,6 +2,7 @@ import os.path
 import re
 import atexit
 import string
+import threading
 
 import spacy
 import ujson
@@ -58,11 +59,15 @@ class Markov:
 
         return text.strip()
 
-    def rebuild(self):
+    def _rebuild(self):
         self.chain = markovify.Chain(self.corpus, config.MARKOV_STATE_SIZE).compile()
 
+    def rebuild(self):
         self.counter = 0
 
+        t = threading.Thread(target=self._rebuild)
+        t.start()
+
     def tokenize(self, text):
         text = re.sub(r"(@[A-Za-z0-9_]+,?)", "", text)
         text = re.sub(