-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
39 lines (34 loc) · 988 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
31
32
33
34
35
36
37
38
39
accented = 'ãúàáąìíĩũỹýòõóẽéèñù'
unaccented = 'auaaąiiiuyyoooeeenu'
chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'ą', 'č', 'ę', 'ė', 'į', 'š', 'ų', 'ū', 'ž', ',', ' ', '\n']
replace_dict = {
'ė́': 'ė',
'l̃': 'l',
'õ': 'o',
'ỹ': 'y',
'ė̃': 'ė',
'r̃': 'r',
'm̃': 'm',
'ū̃': 'ū',
'ū́': 'ū',
'ą̃': 'ą',
'ù': 'u',
'ę́': 'e',
'į̃': 'į',
'ą́': 'a',
'ą́': 'a',
'ę̃': 'ę',
'ų́': 'ų'
}
def remove_accents(text):
trans = text.maketrans(accented, unaccented)
new_text = text.translate(trans)
for i, o in replace_dict.items():
new_text = new_text.replace(i, o)
return new_text
def add_prefix(d, prefix):
for k, v in d.items():
if(isinstance(v, dict)):
add_prefix(v, prefix)
else:
d[k] = prefix + v