-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
91 lines (88 loc) · 3.04 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import nltk
def postprocess_text(inputs):
inputs = [inpt.strip() for inpt in inputs]
# rougeLSum expects newline after each sentence
inputs = ["\n".join(nltk.sent_tokenize(inpt)) for inpt in inputs]
return inputs
def replace_special_chars(text):
text = text.replace('€', '€')
text = text.replace('ã©', 'a')
text = text.replace('â', 'a')
text = text.replace('Â', 'A')
text = text.replace('å', 'a')
text = text.replace('Å', 'A')
text = text.replace('ă', 'a')
text = text.replace('Ă', 'A')
text = text.replace('ä', 'a')
text = text.replace('Ä', 'A')
text = text.replace('ą', 'a')
text = text.replace('Ą', 'A')
text = text.replace('á', 'a')
text = text.replace('Á', 'A')
text = text.replace('ć', 'c')
text = text.replace('č', 'c')
text = text.replace('Č', 'C')
text = text.replace('ď', 'd')
text = text.replace('Ď', 'D')
text = text.replace('ě', 'e')
text = text.replace('Ě', 'E')
text = text.replace('ę', 'e')
text = text.replace('Ę', 'E')
text = text.replace('ê', 'e')
text = text.replace('Ê', 'E')
text = text.replace('ễ', 'e')
text = text.replace('Ễ', 'E')
text = text.replace('ǧ', 'g')
text = text.replace('Ǧ', 'G')
text = text.replace('ị', 'i')
text = text.replace('Ị', 'I')
text = text.replace('ľ', 'l')
text = text.replace('Ľ', 'L')
text = text.replace('ň', 'n')
text = text.replace('Ň', 'N')
text = text.replace('ö', 'ö')
text = text.replace('Ö', 'O')
text = text.replace('ó', 'o')
text = text.replace('Ó', 'O')
text = text.replace('ô', 'o')
text = text.replace('Ô', 'O')
text = text.replace('œ', 'oe')
text = text.replace('Œ', 'OE')
text = text.replace('ř', 'r')
text = text.replace('Ř', 'R')
text = text.replace('š', 's')
text = text.replace('Š', 'S')
text = text.replace('ś', 's')
text = text.replace('Ś', 'S')
text = text.replace('ş', 's')
text = text.replace('Ş', 'S')
text = text.replace('ť', 't')
text = text.replace('Ť', 'T')
text = text.replace('ü', 'u')
text = text.replace('Ü', 'U')
text = text.replace('ủ', 'u')
text = text.replace('Ủ', 'U')
text = text.replace('ů', 'u')
text = text.replace('Ů', 'U')
text = text.replace('ŵ', 'w')
text = text.replace('Ŵ', 'w')
text = text.replace('ý', 'y')
text = text.replace('Ý', 'Y')
text = text.replace('ŷ', 'y')
text = text.replace('Ŷ', 'Y')
text = text.replace('ž', 'z')
text = text.replace('Ž', 'Z')
text = text.replace('¥', 'Y')
text = text.replace('½', '1/2')
text = text.replace('¼', '1/4')
text = text.replace('¾', '3/4')
text = text.replace('¹', '1')
text = text.replace('²', '2')
text = text.replace('³', '3')
text = text.replace('⁴', '4')
text = text.replace('⁄', '/')
text = text.replace('˚', 'deg')
text = text.replace('呢', '')
text = text.replace('製', '')
text = text.replace('ยพ', '3/4')
return text