From a28d24470ddeca6196219a1333c1ccac1319efef Mon Sep 17 00:00:00 2001 From: href Date: Wed, 11 Mar 2020 21:18:34 +0100 Subject: welp --- priv/irc/txt/markov.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 priv/irc/txt/markov.py (limited to 'priv/irc') diff --git a/priv/irc/txt/markov.py b/priv/irc/txt/markov.py new file mode 100644 index 0000000..b72016e --- /dev/null +++ b/priv/irc/txt/markov.py @@ -0,0 +1,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)) + -- cgit v1.2.3