File size: 766 Bytes
882ea5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re

SYMBOLS_MAPPING = {
    "\n": ".",
    "…": ".",
    "β€œ": "'",
    "”": "'",
    "β€˜": "'",
    "’": "'",
    "【": "",
    "】": "",
    "[": "",
    "]": "",
    "(": "",
    "οΌ‰": "",
    "(": "",
    ")": "",
    "・": "",
    "Β·": "",
    "γ€Œ": "'",
    "」": "'",
    "γ€Š": "'",
    "》": "'",
    "β€”": "",
    "~": "",
    "~": "",
    ":": ",",
    "οΌ›": ",",
    ";": ",",
    ":": ",",
}

REPLACE_SYMBOL_REGEX = re.compile(
    "|".join(re.escape(p) for p in SYMBOLS_MAPPING.keys())
)


def clean_text(text):
    # Clean the text
    text = text.strip()

    # Replace all chinese symbols with their english counterparts
    text = REPLACE_SYMBOL_REGEX.sub(lambda x: SYMBOLS_MAPPING[x.group()], text)

    return text