-
Notifications
You must be signed in to change notification settings - Fork 8
/
dict_cleaner.py
47 lines (39 loc) · 1.08 KB
/
dict_cleaner.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
#!/usr/bin/python
# -*- coding: latin-1 -*-
import string
import utils
#TODO(timifasubaa):refactor this fn out! nowin utils.py
def lower_case(word):
"""this function takes in a marked yoruba word and returns the lower case version"""
result = ""
marked_capital_letters = {"À":"à",
"Á":"á",
"É":"é",
"È":"è",
"Ẹ":"ẹ",
"Ì":"ì",
"Í":"í",
"Ó":"ó",
"Ò":"ò",
"Ṣ":"ṣ",
"Ọ":"ọ",
"Ú":"ú",
"Ù":"ù"
}
for letter in word:
if letter in marked_capital_letters.keys():
result += marked_capital_letters[letter]
else:
#print letter
result += letter.lower()
return result
filename = "yoruba_dictionary.txt"
file = open(filename, "r")
bad_chars = ["<", "?", ".", ",", "(", ")", ":", ";", "-", "\"", "'", "+", "\
̣", "!", "“", "`","c"] + list(string.digits)
fh = open("cleaned_yoruba_dict.txt","w")
for line in file:
if not any([bad_char in line for bad_char in bad_chars]):
fh.write(lower_case(line.strip()))
fh.write("\n")
fh.close()