File size: 2,665 Bytes
28fd7c1 664c81e 28fd7c1 |
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
from string import punctuation
def process_text_pipeline(text):
full_text_processed = replace_all(text.strip())
while '\n\n' in full_text_processed:
full_text_processed = full_text_processed.replace('\n\n', '\n')
full_text_processed = process_sticking_sentences(full_text_processed)
while ' ' in full_text_processed:
full_text_processed = full_text_processed.replace(' ', ' ')
return full_text_processed
def replace_all(text):
dict_map = {
"òa": "oà",
"Òa": "Oà",
"ÒA": "OÀ",
"óa": "oá",
"Óa": "Oá",
"ÓA": "OÁ",
"ỏa": "oả",
"Ỏa": "Oả",
"ỎA": "OẢ",
"õa": "oã",
"Õa": "Oã",
"ÕA": "OÃ",
"ọa": "oạ",
"Ọa": "Oạ",
"ỌA": "OẠ",
"òe": "oè",
"Òe": "Oè",
"ÒE": "OÈ",
"óe": "oé",
"Óe": "Oé",
"ÓE": "OÉ",
"ỏe": "oẻ",
"Ỏe": "Oẻ",
"ỎE": "OẺ",
"õe": "oẽ",
"Õe": "Oẽ",
"ÕE": "OẼ",
"ọe": "oẹ",
"Ọe": "Oẹ",
"ỌE": "OẸ",
"ùy": "uỳ",
"Ùy": "Uỳ",
"ÙY": "UỲ",
"úy": "uý",
"Úy": "Uý",
"ÚY": "UÝ",
"ủy": "uỷ",
"Ủy": "Uỷ",
"ỦY": "UỶ",
"ũy": "uỹ",
"Ũy": "Uỹ",
"ŨY": "UỸ",
"ụy": "uỵ",
"Ụy": "Uỵ",
"ỤY": "UỴ",
"\xa0": " ",
"…": "...",
"''": '"',
""": '"',
"'": "'",
"H'Mông": "Hmông",
"H'mông": "Hmông",
"H’mông": "Hmông",
"H’Mông": "Hmông",
"H’MÔNG": "Hmông",
"M'Nông": "Mnông",
"M'nông": "Mnông",
"M'NÔNG": "Mnông",
"M’Nông": "Mnông",
"M’NÔNG": "Mnông",
'\u200b\u200b': ""
}
for i, j in dict_map.items():
text = text.replace(i, j)
return text
def process_sticking_sentences(full_text):
for i in range(len(full_text) - 1):
c1 = full_text[i]
c2 = full_text[i + 1]
# 'end of sentence.Start'
if c1 in punctuation and c2.isalpha() and c2.isupper():
before = full_text[:i + 1]
after = full_text[i + 1:]
full_text = before + " " + after
# 'end of sentenceStart'
if c1.isalpha() and c1.islower() and c2.isalpha() and c2.isupper():
before = full_text[:i + 1]
after = full_text[i + 1:]
full_text = before + ". " + after
return full_text
|