diff --git a/src/tetrak_ocr/accuracy.py b/src/tetrak_ocr/accuracy.py index 0c57835..9fdf97e 100644 --- a/src/tetrak_ocr/accuracy.py +++ b/src/tetrak_ocr/accuracy.py @@ -24,6 +24,15 @@ # Armenian punctuation -> the ASCII character it is visually identical to. _PUNCTUATION_HOMOGLYPHS = str.maketrans({"։": ":", "․": "."}) +# The two-letter եւ and the ligature և are one thing for scoring (brief 014, +# decided 2026-10-08). Classical-orthography presses split 21 to 16 on which +# they set, reformed presses set the ligature, and transcribers follow the +# page or do not; ground truth stays as printed so the model learns to read +# both, and the metric refuses to rank an engine on which form it emitted. +# Applied after lowercasing, so Եւ and ԵՒ fold too. The trainer's copy of +# this module carries the same change. +_EW_LIGATURE = ("եւ", "և") + def _is_word(token: str) -> bool: """A token with at least one letter or digit; ``-`` or ``…`` alone is not.""" @@ -40,9 +49,11 @@ def normalise(text: str) -> str: throughout; every register uses ``.`` for ``․``) that holding an engine to either form would rank engines on which habit their output happens to share with the transcript, not on what they read. Mapped towards - ASCII so that text with no Armenian in it is unaffected. + ASCII so that text with no Armenian in it is unaffected. The two-letter + ``եւ`` is scored as the ligature ``և`` for the same reason (brief 014). """ - return re.sub(r"\s+", " ", text.lower().translate(_PUNCTUATION_HOMOGLYPHS)).strip() + lowered = text.lower().translate(_PUNCTUATION_HOMOGLYPHS).replace(*_EW_LIGATURE) + return re.sub(r"\s+", " ", lowered).strip() def character_similarity(actual: str, expected: str) -> float: diff --git a/tests/ocr/test_accuracy.py b/tests/ocr/test_accuracy.py index c501b5d..4e3e48c 100644 --- a/tests/ocr/test_accuracy.py +++ b/tests/ocr/test_accuracy.py @@ -32,6 +32,12 @@ def test_armenian_full_stop_and_colon_are_equal(self) -> None: """Transcripts type ':' for '։'; neither engine nor transcript is penalised.""" assert normalise("բժշկի։") == normalise("բժշկի:") + def test_two_letter_ew_and_ligature_are_equal(self) -> None: + """Brief 014: classical presses set եւ, reformed presses և; neither + form is a reading error. Capitals fold too, via lowercasing.""" + assert word_recall("Երեւան եւ Եւրոպա", "Երևան և Եւրոպա") == 1.0 + assert normalise("ԵՒ Եւ եւ") == "և և և" + def test_abbreviation_dot_and_full_stop_are_equal(self) -> None: """Transcripts type '.' for the Armenian abbreviation dot '․'.""" assert normalise("Ա․ Գրկ․") == normalise("Ա. Գրկ.")