|
|
|
|
|
puncts_replacements = { |
|
"β": '"', |
|
"β": '"', |
|
"β": "'", |
|
"\n\n\n\n": "\n\n", |
|
"\n\n\n": "\n\n", |
|
"\xa0": " ", |
|
"β β": "-", |
|
".β ββ β¦": "...", |
|
"β β¦": "...", |
|
" ": " ", |
|
", , ": ", ", |
|
". ": ". ", |
|
", ": ", ", |
|
"; ": "; ", |
|
} |
|
|
|
|
|
def normalize_puncts(html: str): |
|
strp = html.strip() |
|
for k, v in puncts_replacements.items(): |
|
strp = strp.replace(k, v) |
|
return strp |
|
|
|
def merge_consecutive_lines(lines:str): |
|
last_line = None |
|
final_concate = [] |
|
for curr_line in lines.split("\n"): |
|
if last_line is None: |
|
last_line = curr_line.lstrip() |
|
final_concate.append(curr_line) |
|
continue |
|
if curr_line.strip(): |
|
|
|
if last_line: |
|
|
|
final_concate[-1] = f"{final_concate[-1]} {curr_line}" |
|
last_line = curr_line.lstrip() |
|
|
|
else: |
|
last_line = curr_line.lstrip() |
|
final_concate.append("\n") |
|
else: |
|
|
|
if last_line: |
|
final_concate.append(curr_line + "\n") |
|
else: |
|
continue |
|
return "\n".join(final_concate) |
|
|
|
def clean_newlines(lines: str): |
|
last_line = None |
|
final_concate = [] |
|
for line in lines.split("\n"): |
|
if last_line is None: |
|
last_line = line.lstrip() |
|
final_concate.append(line.lstrip()) |
|
continue |
|
if line.strip(): |
|
last_line = line.lstrip() |
|
final_concate.append(line.lstrip()) |
|
else: |
|
if last_line: |
|
last_line = line.lstrip() |
|
final_concate.append(line.lstrip()) |
|
else: |
|
continue |
|
return "\n".join(final_concate) |
|
|