|
@@ -35,11 +35,13 @@ class Markov:
|
|
|
init_state = tuple(init_state)
|
|
|
|
|
|
size = len(init_state)
|
|
|
-
|
|
|
- if size < config.MARKOV_STATE_SIZE:
|
|
|
- init_state = (markovify.chain.BEGIN,) * (config.MARKOV_STATE_SIZE - size) + init_state
|
|
|
+
|
|
|
+ if size < config.MARKOV_STATE_SIZE:
|
|
|
+ init_state = (markovify.chain.BEGIN,) * (
|
|
|
+ config.MARKOV_STATE_SIZE - size
|
|
|
+ ) + init_state
|
|
|
elif size > config.MARKOV_STATE_SIZE:
|
|
|
- init_state = init_state[:-config.MARKOV_STATE_SIZE]
|
|
|
+ init_state = init_state[: -config.MARKOV_STATE_SIZE]
|
|
|
|
|
|
words = self.chain.walk(init_state)
|
|
|
if not words:
|
|
@@ -47,7 +49,9 @@ class Markov:
|
|
|
|
|
|
text = orig_init_state if orig_init_state is not None else ""
|
|
|
for word in words:
|
|
|
- if word in "-–—" or not all(c in string.punctuation or c == "…" for c in word):
|
|
|
+ if word in "-–—" or not all(
|
|
|
+ c in string.punctuation or c == "…" for c in word
|
|
|
+ ):
|
|
|
text += " "
|
|
|
|
|
|
text += word
|
|
@@ -88,12 +92,18 @@ class Markov:
|
|
|
if text not in self.corpus:
|
|
|
self.corpus.insert(0, text)
|
|
|
|
|
|
- if len(self.corpus) > config.MARKOV_CORPUS_SIZE:
|
|
|
- self.corpus.pop(-1)
|
|
|
+ if (
|
|
|
+ config.MARKOV_CORPUS_SIZE > 0
|
|
|
+ and len(self.corpus) > config.MARKOV_CORPUS_SIZE
|
|
|
+ ):
|
|
|
+ self.corpus = self.corpus[: config.MARKOV_CORPUS_SIZE]
|
|
|
|
|
|
self.counter += 1
|
|
|
|
|
|
- if self.counter % config.MARKOV_REBUILD_RATE == 0:
|
|
|
+ if (
|
|
|
+ config.MARKOV_REBUILD_RATE > 0
|
|
|
+ and self.counter % config.MARKOV_REBUILD_RATE == 0
|
|
|
+ ):
|
|
|
self.rebuild()
|
|
|
|
|
|
def load(self):
|