-
Notifications
You must be signed in to change notification settings - Fork 0
/
getShortForms.py
34 lines (32 loc) · 1.16 KB
/
getShortForms.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
def justTwoInitSylls_CVC(word):
beforeThisIndex = 0
afterThisIndex = 0
for vowel1 in word:
if vowel1 in 'aeiou':
afterThisIndex = word.index(vowel1)
break
for vowel2 in word[afterThisIndex+1:]:
if vowel2 in 'aeiou':
beforeThisIndex = word[afterThisIndex+1:].index(vowel2)+1 + afterThisIndex+1
# if second syllable has two vowels, then ignore that final vowel to preserve two vowels/syllables per word
if beforeThisIndex < len(word) and word[beforeThisIndex] in 'aeiou':
beforeThisIndex -= 1
break
if beforeThisIndex!=0:
word = word[:beforeThisIndex+1]
return word
# get "shortform(word),English" pairs
filename = 'output_shortlist.txt'
entries = []
with open(filename,'r') as f:
for line in f:
# get just the output words
word = line.split(',')[0].replace(' \'','')
word = justTwoInitSylls_CVC(word)
english = line.split(',')[1]
entries.append(word+','+english+'\n')
# save pairs to a separate file
filename = 'shortforms.txt'
with open(filename,'w') as f:
for entry in entries:
f.write(entry)