-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_filters.py
58 lines (47 loc) · 1.45 KB
/
common_filters.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
48
49
50
51
52
53
54
55
56
57
58
def clean_accents(word):
output = []
for letter in word:
if letter == u"á":
modified_letter = "a"
elif letter == u"é":
modified_letter = "e"
elif letter == u"í":
modified_letter = "i"
elif letter == u"ó":
modified_letter = "o"
elif letter == u"ú":
modified_letter = "u"
elif letter == u"ñ":
modified_letter = "N"
else:
modified_letter = letter
output.append(modified_letter)
return ''.join(output)
def filter_special_characters(word):
output = []
for letter in word:
if letter == u"-":
modified_letter = ""
elif letter == u"\n":
modified_letter = ""
elif letter == u"\.":
modified_letter = ""
elif letter == u"?":
modified_letter = ""
else:
modified_letter = letter
output.append(modified_letter)
return ''.join(output)
def allow_characters(word):
alphabet = "abcdefghijklmnNopqrstuvwxyz "
output = []
for letter in word:
if letter in alphabet:
output.append(letter)
return ''.join(output)
def extract_phones_from_word(word):
return ' '.join(apply_filters(word))
def apply_filters(word):
return allow_characters(filter_special_characters(clean_accents(word)))
def remove_jump_characters(word):
return word.replace("\n", "").replace("\r", "")