| import re |
| from bg_text_normalizer import normalize_text as bg_norm |
|
|
| |
| EXTRA_ABBREVIATIONS = { |
| r"\bм²\b": "квадратен метър", |
| r"\bкв\.м\.\b": "квадратен метър", |
| r"\bт\.е\.\b": "тоест", |
| } |
|
|
| def normalize_text(text: str) -> str: |
| """ |
| Нормализира текста, използвайки bg-text-normalizer + наши специфични правила. |
| """ |
| |
| |
| text = re.sub(r'(\d)\.(\d)', r'\1,\2', text) |
| |
| |
| text = bg_norm(text) |
| |
| |
| text = text.replace("лева.", "лева") |
| text = text.replace("стотинки.", "стотинки") |
| |
| |
| for pattern, replacement in EXTRA_ABBREVIATIONS.items(): |
| text = re.sub(pattern, replacement, text, flags=re.IGNORECASE) |
| |
| |
| text = text.replace("м²", "квадратен метър") |
| |
| |
| text = re.sub(r"\s+", " ", text).strip() |
| |
| return text |
|
|
| if __name__ == "__main__": |
| test_text = "Цената е 1500 лв. за м² в кв. Лозенец." |
| print("Original:", test_text) |
| print("Normalized:", normalize_text(test_text)) |
|
|