-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmarkov_generators.py
More file actions
61 lines (47 loc) · 1.43 KB
/
markov_generators.py
File metadata and controls
61 lines (47 loc) · 1.43 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import markovify
import en_core_web_sm
import markovgen2_works as Markov
markov_data = open("Horror_plots.txt")
generator = Markov.Markov(2)
generator.train(markov_data)
print("Basic Markov model generated:")
generator.generate(30)
print("_______")
input_text = open('Horror_plots.txt').read()
nlp = en_core_web_sm.load()
# regular markovify
# Build the model.
text_model = markovify.Text(input_text, state_size=2)
# Print five randomly-generated sentences
print("Vanilla Markovify:")
print("---")
print("Sentence Gen:")
for i in range(10):
print(text_model.make_sentence())
print(" ")
print("Short sentence gen:")
# Print three randomly-generated sentences of no more than 140 characters
for i in range(10):
print(text_model.make_short_sentence(140))
print("________")
#sentence_gen()
# overwrite default markovify model
class POSText(markovify.Text):
def word_split(self, sentence):
return ["::".join((word.orth_, word.pos_)) for word in nlp(sentence)]
def word_join(self, words):
sentence = " ".join(word.split("::")[0] for word in words)
return sentence
text_model2 = POSText(input_text, state_size=3)
print("Modified Markov model:")
print("---")
print("Markov full sentence gen:")
print(" ")
for i in range(10):
print(text_model2.make_sentence())
print("________")
print("Markov short sentence gen:")
print(" ")
for i in range(10):
print(text_model2.make_short_sentence(150))
print("________")