/
Chaizee
/
ZenithCode_Incident-LLM-analytics
Обзор
Документация
Войти
/
Chaizee
/
ZenithCode_Incident-LLM-analytics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/text_utils.py
18 строк
659 B
Chaizee
feat: new realisation
11 июн 2026, 19:58
11 июн 2026, 19:58
697b236
Код
Авторство
О чём код?
from __future__ import annotations import re _CJK = re.compile(r"[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af\u0e00-\u0e7f\u0600-\u06ff]") _MULTI_SPACE = re.compile(r"\s+") _PUNCT_JUNK = re.compile(r"[,;:\-–—]+\s*[,;:\-–—]+") def has_foreign_script(text: str) -> bool: return bool(_CJK.search(str(text or ""))) def sanitize_russian(text: str, *, fallback: str = "не определено", max_len: int = 120) -> str: cleaned = _CJK.sub("", str(text or "")) cleaned = _PUNCT_JUNK.sub(", ", cleaned) cleaned = _MULTI_SPACE.sub(" ", cleaned).strip(" ,.;:-") if len(cleaned) < 2: return fallback return cleaned[:max_len]