|
@@ -28,6 +28,8 @@ class Markov:
|
|
|
return self.chain is not None
|
|
|
|
|
|
def generate(self, init_state=None):
|
|
|
+ orig_init_state = init_state
|
|
|
+
|
|
|
if init_state is not None:
|
|
|
init_state = self.tokenize(init_state)
|
|
|
init_state = tuple(init_state)
|
|
@@ -41,10 +43,7 @@ class Markov:
|
|
|
if not words:
|
|
|
return self.generate()
|
|
|
|
|
|
- if init_state:
|
|
|
- words = list(init_state) + words
|
|
|
-
|
|
|
- text = ""
|
|
|
+ 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 for c in word):
|
|
|
text += " "
|