-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMarkovChainCreator.py
More file actions
39 lines (25 loc) · 831 Bytes
/
Copy pathMarkovChainCreator.py
File metadata and controls
39 lines (25 loc) · 831 Bytes
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
29
30
31
32
33
34
import timeit
import sys
from WordChains import WordNode, WordChain, LetterChain, WordChainOld
# use if getting ascii error... i guess...
reload(sys)
#sys.setdefaultencoding('utf8')
text_file = open('TextFiles/CompleteRRMartin.txt', 'r')
txt = text_file.read()
print txt
# Remove all new lines
txt = txt.replace('\n', ' ')
# Remove hyperlinks
#txt = re.sub(r'https\S+', '', txt, flags=re.MULTILINE)
# Remove Emojis
#txt = txt.encode("utf-8").decode('unicode_escape').encode('ascii', 'ignore')
#
chain = WordChain()
start_time = timeit.default_timer()
chain.get_words(txt, 1)
time = (timeit.default_timer() - start_time)
chain.generate_text(print_to_console=True)
print 'Elapsed time: ', time
# for key, words in chain.dic.items():
# print words.followers
chain.to_csv('MarkovChains2.0/CompleteRRMartinDeg1.txt')