-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_detect.py
More file actions
executable file
·304 lines (245 loc) · 9.69 KB
/
test_detect.py
File metadata and controls
executable file
·304 lines (245 loc) · 9.69 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/python
from detection.rhyme_detect import *
from detection.scrub import *
###########################
# BEGIN: GLOBAL VARIABLES #
###########################
# Sample rhymes in the form of a string, or a list of strings
# More sample rhymes are located in the text files
# Import text files by using command line arguments
# Lose Yourself - Eminem
LOSE_YOURSELF = ["His palms are sweaty knees weak arms are heavy",
"There vomit on his sweater already moms spaghetti",
"He nervous but on the surface he looks calm and ready to drop bombs",
"But he keeps on forgetting what he wrote down",
"The whole crowd goes so loud",
"He opens his mouth but the words wont come out"]
PERFECT_RHYME = ["This is a perfect rhyme",
"bitches split on a dime"]
BREAK_PERFECT_RHYME = ["This is NOT a perfect rhyme and with some luck",
"The method will know this and not be a dick"]
BREAK_PERFECT_RHYME_YET_AGAIN = ["Nice try Johnny boy your effort was good",
"but I have a leg up or at least a foot"]
ALLITERATION_RHYME1 = ["Look I was gonna go easy on you and not to hurt your feelings",
"But I'm only going to get this one chance"]
ALLITERATION_RHYME2 = ["Big big booty what you got a big booty"]
ASSONANCE_RHYME = ["Maybe bake cake Jay C rapper star"]
SAMPLE_TEXT = "Mackerel bat from hell"
SAMPLE_TEXT2 = "Wow Jay C is asking for it, gonna punch him in a little bit" # that doesn't rhyme, fish can't rap <<< happy? <- :(
RAP_GOD = ["I'm beginning to feel like a Rap God, Rap God",
"All my people from the front to the back nod, back nod"]
HOL_UP = ["I wrote this record while thirty thousand feet in the air",
"Stewardess complimenting me on my happy hair",
"If I can fuck her in front of all of these passengers",
"They'll probably think I'm a terrorist eat my asparagus",
"Then I'm asking her thoughts of a young bigger fast money and freedom",
"A crash dummy for dollars I know you dying to meet them",
"I'll holly die in a minute just bury me",
"With twenty bitches twenty million and a Cop town fitted"]
GET_RID_OF_DAT_PUNCT = "This'll, have: a; (ton) of _pointless -punctuation"
#########################
# END: GLOBAL VARIABLES #
#########################
#####################
# BEGIN SCRUB TESTS #
#####################
horiz_line()
print("BEGIN TESTS")
horiz_line()
if (len(sys.argv) > 1):
line_break()
print("ARGUMENTS DETECTED")
print("TEST COMMAND LINE:")
print("Argument List " + str(sys.argv))
print("Number of arguments: " + str(len(sys.argv)))
print("SCRUBBED LINES:")
print(read_and_scrub_text_file(1))
line_break()
print("TESTING: transcribe_string(SAMPLE_TEXT)")
sample_transcr = transcribe_string(SAMPLE_TEXT) # test that transcribe_string function works
print(sample_transcr) # Prints out phonemes for "Mackerel bat from hell"
line_break()
print("TESTING: transcribe_list(PERFECT_RHYME)")
perfect_transcr = transcribe_list(PERFECT_RHYME) # test that transcribe_list function works correctly
print(perfect_transcr) # output should match what we have below
print("WHAT ARE THE LENGTHS OF EACH TRANSCRIPTION")
arr = [0,0]
for i in range(len(perfect_transcr)):
for t in perfect_transcr[i]:
for s in t:
arr[i] += 1
print(arr)
line_break()
print("TEST FOR MATCH: transcribe_list(PERFECT_RHYME)") # test for matching output
for s in PERFECT_RHYME:
print(transcribe_string(s)) # transcribe_list ouputs match! yay!
line_break()
print("TEST FOR PUNCTUATION SCRUBBING:")
print GET_RID_OF_DAT_PUNCT
print scrub_punct(GET_RID_OF_DAT_PUNCT)
line_break()
print("TEST FOR SCRUB.PY")
scrub_lyrics("rap_god.txt")
###################
# END SCRUB TESTS #
###################
#########################
# BEGIN DETECTION TESTS #
#########################
line_break()
horiz_line()
print("Now comes the detection output:")
horiz_line()
line_break()
print("TEST FOR PERFECT RHYME:") # test that perfect rhyme detection works
print(PERFECT_RHYME) # ['This is a perfect rhyme', 'bitches split on a dime']
print(transcribe_list(PERFECT_RHYME))
print(detect_perfect_rhyme_two_lines(PERFECT_RHYME[0], PERFECT_RHYME[1])) # Expected: True (yay!)
line_break()
print("TEST FOR PERFECT RHYME:") # test that perfect rhyme doesnt give false positives
print(BREAK_PERFECT_RHYME) # 'This is NOT a perfect rhyme and with some luck', 'The method will know this and not be a dick']
print(detect_perfect_rhyme_two_lines(BREAK_PERFECT_RHYME[0], BREAK_PERFECT_RHYME[1])) # Expected: False (boo! :( )
line_break()
print("TEST FOR PERFECT RHYME:") # test that perfect rhyme doesnt give false positives
print(BREAK_PERFECT_RHYME_YET_AGAIN) # 'Nice try Johnny boy your effort was good', 'but I have a leg up or at least a foot']
print(detect_perfect_rhyme_two_lines(BREAK_PERFECT_RHYME_YET_AGAIN[0], BREAK_PERFECT_RHYME_YET_AGAIN[1])) # Expected: False (boo! :( )
line_break()
print("TEST FOR ALLITERATION RHYME:")
print(ALLITERATION_RHYME1)
print(detect_alliteration(ALLITERATION_RHYME1[0]))
line_break()
print(ALLITERATION_RHYME2)
print(detect_alliteration(ALLITERATION_RHYME2[0]))
line_break()
print("TEST FOR ASSONANCE RHYME WITHIN LINE:")
print(ASSONANCE_RHYME)
print(detect_assonance_in_line(ASSONANCE_RHYME[0]))
line_break()
print("TEST FOR MATCHING PHONEMES:")
print(find_matching_phonemes(transcribe_string(PERFECT_RHYME[0]), transcribe_string(PERFECT_RHYME[1])))
########################
# END DETECTION TESTS #
########################
#########################
# BEGIN SYLLABLE TESTS #
#########################
line_break()
horiz_line()
print("Jay C in the hiz-house testing dem syllables:")
horiz_line()
line_break()
print("TEST FOR SINGLE WORD:") # next test: mack-er-el
print("AMAZING")
print(syllable_count(transcribe_string("amazing")))
print(syllable_word(transcribe_string("amazing")))
print(transcribe_string("amazing"))
line_break()
print("TEST SYLLABLE_WORD METHOD:")
print "hello"
print syllable_word((transcribe_string("hello")))
print len(syllable_word((transcribe_string("hello")))) # Expected: 2 yay!
line_break()
print "this"
print syllable_word((transcribe_string("this")))
print len(syllable_word((transcribe_string("this")))) # Expected: 3 yay!
line_break()
print "bottle"
print syllable_word((transcribe_string("bottle")))
print len(syllable_word((transcribe_string("bottle")))) # Expected: 2 yay!
line_break()
print "is"
print syllable_word((transcribe_string("is")))
print len(syllable_word((transcribe_string("is")))) # Expected: 3 yay!
line_break()
print "wonderful"
print syllable_word((transcribe_string("wonderful")))
print len(syllable_word((transcribe_string("wonderful")))) # Expected: 3 yay!
line_break()
print "clocks"
print syllable_word((transcribe_string("clocks")))
print len(syllable_word((transcribe_string("clocks")))) # Expected: 1 yay!
line_break()
print("TEST SYLLABLE_STRING METHOD:")
print("hello this bottle is wonderful")
print(syllable_string("hello this bottle is wonderful"))
line_break()
print("TEST SYLLABLE TOTAL METHOD:")
pprint.pprint(LOSE_YOURSELF)
lose_yourself_total_syllables = syllable_total(LOSE_YOURSELF)
print(lose_yourself_total_syllables)
line_break()
print("FIND SYLLABLE COUNTS OF LOSE YOURSELF")
for x in lose_yourself_total_syllables:
print(len(x))
line_break()
print("TEST SYLLABLE TOTAL METHOD, HOL UP:")
pprint.pprint(HOL_UP)
hol_up_total_syllables = syllable_total(HOL_UP)
print(hol_up_total_syllables)
line_break()
print("FIND SYLLABLE COUNT OF HOL UP")
for x in hol_up_total_syllables:
print(len(x))
print("TEST SYLLABLE NO BOUNDARIES:")
pprint.pprint(SAMPLE_TEXT)
print(syllable_string_no_word_boundaries(SAMPLE_TEXT))
########################
# END SYLLABLE TESTS #
########################
####################
# BEGIN FREQ TESTS #
####################
line_break()
horiz_line()
print("Mack-lemore & Jay-C Collab on Frequency Methods, Ass & All")
horiz_line()
line_break()
print("TESTING VOWEL_FREQ")
print(SAMPLE_TEXT)
print(transcribe_string(SAMPLE_TEXT))
vowel_od_1 = vowel_freq(transcribe_string(SAMPLE_TEXT))
for k, v in vowel_od_1.items():
print k, v
line_break()
print("TESTING VOWEL FREQ MORE SERIOUSLY")
print(LOSE_YOURSELF)
print(transcribe_list(LOSE_YOURSELF))
vowel_od_2 = []
for l in LOSE_YOURSELF:
vowel_od_2.append(vowel_freq(transcribe_string(l)))
for x in vowel_od_2:
print("\n")
for k, v in x.items():
print k, v
line_break()
print("TESTING ALLITERATION_FREQ")
print(ALLITERATION_RHYME1[0])
print(transcribe_string(ALLITERATION_RHYME1[0]))
allit_od_1 = allit_freq(transcribe_string(ALLITERATION_RHYME1[0]))
for k, v in allit_od_1.items():
print k, v
##################
# END FREQ TESTS #
##################
#####################
# BEGIN MULTI TESTS #
#####################
horiz_line()
print("TESTING MULTISYLLABIC RHYMES BRACE YOUR ASSONANCE")
horiz_line()
line_break()
print(LOSE_YOURSELF[3])
print(LOSE_YOURSELF[4])
pprint.pprint(multi_sequence(LOSE_YOURSELF[3],LOSE_YOURSELF[4]))
if (len(sys.argv) > 1):
multi_file_swag = []
line_break()
file_swag = read_and_scrub_text_file(1)
for i in range(0, len(file_swag) - 1):
temp = multi_sequence(file_swag[i], file_swag[i + 1])
if len(temp) != 0:
multi_file_swag.append(temp)
pprint(multi_file_swag)
###################
# END MULTI TESTS #
###################