-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
28 lines (25 loc) · 859 Bytes
/
bot.py
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
28
import sys
import pickle
from words import words
from quote import *
from markov import *
from frequency import probabilities, make_word_walker
quote_length = int(sys.argv[1])
algorithm_selection = sys.argv[2]
files = sys.argv[3:len(sys.argv)]
prefix_length = 2
if len(files) == 1 and files[0].split('.')[-1] == "pickle":
source = pickle.load(open(files[0], "rb"))
if algorithm_selection == 'markov':
walker = make_prefix_walker(source)
elif algorithm_selection == 'freq':
walker = make_word_walker(source)
else:
corpus = words(files)
if algorithm_selection == 'markov':
source = markov(corpus, prefix_length)
walker = make_prefix_walker(source)
elif algorithm_selection == 'freq':
source = probabilities(corpus)
walker = make_word_walker(source)
print( quote(quote_length, walker) )