diff --git a/api/src/normalizer/ocr/text.py b/api/src/normalizer/ocr/text.py index 2ddc6bf..c4bc441 100644 --- a/api/src/normalizer/ocr/text.py +++ b/api/src/normalizer/ocr/text.py @@ -23,7 +23,7 @@ _CELL_SEPARATOR_LINE = re.compile(r"[\s\d|•·.:,]*") def fix_lookalikes(text: str, lookalikes: Mapping[str, str]) -> str: """Буквы-двойники → цифры только вплотную к цифре, в несколько проходов («2ОО5» → «2005»); `|` — разделитель клеток, если первая строка состоит из цифр, пробелов и пунктуации («2|0|2|4|» → «2 0 2 4 »).""" - text = text.replace(" ", " ") + text = text.replace("\xa0", " ") if _CELL_SEPARATOR_LINE.fullmatch(text.split("\n", 1)[0]): text = text.replace("|", " ") if not lookalikes: diff --git a/api/tests/unit/normalizer/test_text.py b/api/tests/unit/normalizer/test_text.py index d36e7db..dcd7dfd 100644 --- a/api/tests/unit/normalizer/test_text.py +++ b/api/tests/unit/normalizer/test_text.py @@ -51,6 +51,11 @@ class TestFixLookalikes: def test_empty_table_keeps_text(self) -> None: assert fix_lookalikes("2ОО5", {}) == "2ОО5" + def test_nbsp_replacement(self) -> None: + # неразрывный пробел (U+00A0) → обычный пробел (U+0020) + assert fix_lookalikes("31\xa012\xa02024", LOOKALIKES) == "31 12 2024" + assert fix_lookalikes("31\xa012\xa02024", {}) == "31 12 2024" + @pytest.mark.parametrize( ("raw", "expected"),