Legora / db /parsers /consitution /cleaner.py
sai-Rohan's picture
combined results of all parsers and made a single pipeline
dbabef2
Raw
History Blame Contribute Delete
1.14 kB
import re
class ConstitutionTextCleaner:
def clean(
self,
text: str
) -> str:
text = text.replace(
"\r\n",
"\n"
)
text = re.sub(
r"\r",
"\n",
text
)
# remove page numbers
text = re.sub(
r"(?m)^\s*\d+\s*$",
"",
text
)
# remove repeated spaces
text = re.sub(
r"[ \t]+",
" ",
text
)
# remove constitution headers
text = re.sub(
r"THE CONSTITUTION OF INDIA",
"",
text,
flags=re.I
)
# remove separators
text = re.sub(
r"_{3,}",
"",
text
)
# collapse blank lines
text = re.sub(
r"\n{3,}",
"\n\n",
text
)
return text.strip()