-
Notifications
You must be signed in to change notification settings - Fork 0
/
replacer.py
52 lines (46 loc) · 1.26 KB
/
replacer.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
import re
def replacerfunction(text):
replacers_always = {
'v':'u',
'V':'U',
'j':'i',
'J':'I',
'uors':'uers',
'uort':'uert',
'uolt':'uelt',
}
replacers_standalone = {
',':' ',
'-':'',
'I.': '',
'II.': '',
'III.': '',
'IV.': '',
'V.': '',
'I': '',
'II': '',
'III': '',
'IV': '',
'V': '',
'ii': '',
'iii': '',
'iv': '',
'v': '',
'vi': '',
'vii': '',
}
replaced_text_finale = ""
replaced_text = re.sub("[^a-zA-Z]+", " ", text)
for key in replacers_always.keys():
replaced_text = replaced_text.replace(key,replacers_always[key])
for word in replaced_text.split():
wordlenght = len(word)
for key in replacers_standalone.keys():
if (wordlenght>len(key) or wordlenght<len(key)):
continue
elif(wordlenght==len(key) and word==key):
word = word.replace(word, replacers_standalone[key])
replaced_text_finale+=word+" "
break
replaced_text_finale+=word+" "
return replaced_text_finale