summaryrefslogtreecommitdiff
path: root/priv/irc/txt/markov.py
blob: b72016e415035c21bbcc44bf089b3d43c101381c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import markovify
import os
import string
import sys
import shlex
import unidecode

combined_model = None
text = ""

dir = sys.argv[1]

for (dirpath, _, filenames) in os.walk(dir):
    for filename in filenames:
        with open(os.path.join(dirpath, filename)) as f:
            text = text + unidecode.unidecode(f.read().lower())


# Build the model.
text_model = markovify.NewlineText(text, well_formed = False)

if len(sys.argv) > 1:
    insp = " ".join(map(shlex.quote, sys.argv[2:])).lower()
    print(text_model.make_sentence_with_start(unidecode.unidecode(insp), strict = False, tries = 1000))
else:
    print(text_model.make_short_sentence(280, tries=1000))