вырезание последнего предложения если содержит слово макс (любой регистр)
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 30s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 30s
This commit is contained in:
parent
39f10be7fd
commit
649cd8cc33
1 changed files with 6 additions and 0 deletions
|
|
@ -69,7 +69,13 @@ def clean_text(text: str) -> str:
|
||||||
text = re.sub(r'@\S+\s*', '', text)
|
text = re.sub(r'@\S+\s*', '', text)
|
||||||
text = re.sub(r'[ \t]+', ' ', text)
|
text = re.sub(r'[ \t]+', ' ', text)
|
||||||
text = re.sub(r'\n{2,}', '\n', text)
|
text = re.sub(r'\n{2,}', '\n', text)
|
||||||
|
text = re.sub(r'\n', ' ', text)
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
|
|
||||||
|
parts = re.split(r'(?<=[.!?])\s+', text)
|
||||||
|
if parts and re.search(r'макс', parts[-1], re.IGNORECASE):
|
||||||
|
text = ' '.join(p.strip() for p in parts[:-1] if p.strip())
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
text += '\nПип.'
|
text += '\nПип.'
|
||||||
return text
|
return text
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue