-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
30 lines (28 loc) · 814 Bytes
/
utils.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
def skip_comment_generator(file):
"""
Returns a generator that skips the blank lines of a file,
as well as several types of comments:
- C-style: /* */
- CMU dict: ;
- Corpus: %
"""
in_comment_block = False
for line in file:
if line[0] in '";%\n':
continue
elif '/*' in line:
if '*/' not in line:
in_comment_block = True
elif '*/' in line:
in_comment_block = False
elif not in_comment_block:
yield line
def format_word(word):
"""
Remove spaces, line markers, punctuation and make uppercase.
"""
out_str = word.rstrip().upper()
unwanted_chars = ',."!'
for char in unwanted_chars:
out_str = out_str.replace(char, '')
return out_str