-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerators.py
92 lines (84 loc) · 2.09 KB
/
generators.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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import markovs
import strutil
class TookTooLong(Exception):
pass
def get_word_line(markovs, c):
while True:
word = markovs.mc1.get(markovs.MC1_ALL)
line = word
while strutil.count_syllables(line) < c:
word = markovs.mc2.get(word)
if word is None or word == markovs.MC2_END:
break
line = line + " " + word
if strutil.count_syllables(line) == c:
return line
def get_begin_line(markovs, c):
while True:
word = markovs.MC2_BEGIN
line = ""
while strutil.count_syllables(line) < c:
word = markovs.mc2.get(word)
if word is None or word == markovs.MC2_END:
break
line = line + " " + word
if strutil.count_syllables(line) == c:
return line
def get_end_line(markovs, c):
while True:
word = markovs.mc1.get(markovs.MC1_ALL)
line = word
while True:
word = markovs.mc2.get(word)
if word is None:
line = ""
break
if word == markovs.MC2_END:
break
line = line + " " + word
if strutil.count_syllables(line) == c:
return line
def get_begin_end_line(markovs, c):
while True:
word = markovs.MC2_BEGIN
line = ""
while True:
word = markovs.mc2.get(word)
if word is None:
line = ""
break
if word == markovs.MC2_END:
break
line = line + " " + word
if strutil.count_syllables(line) == c:
return line
def get_end_reverse_line(markovs, c):
while True:
word = markovs.MC2R_END
line = ""
while strutil.count_syllables(line) < c:
word = markovs.mc2r.get(word)
if word is None or word == markovs.MC2R_BEGIN:
break
line = word + " " + line
if strutil.count_syllables(line) == c:
return line
def get_end_reverse_with_rhyme(markovs, c, rhyme):
while True:
lwtries = 0
while True:
endword = markovs.mc2r.get(markovs.MC2R_END)
if strutil.last_n_letters(endword, len(rhyme)) == rhyme:
break
lwtries += 1
if lwtries >= 1000:
raise TookTooLong()
word = endword
line = endword
while strutil.count_syllables(line) < c:
word = markovs.mc2r.get(word)
if word is None or word == markovs.MC2R_BEGIN:
break
line = word + " " + line
if strutil.count_syllables(line) == c:
return line