From d284edf2e2bfa4d10cf4406c9b507a8a62cddf87 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Thu, 8 Oct 2026 18:21:22 +0100 Subject: [PATCH] =?UTF-8?q?feat(accuracy):=20score=20the=20two-letter=20?= =?UTF-8?q?=D5=A5=D6=82=20and=20the=20ligature=20=D6=87=20as=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Brief 014, decided 2026-10-08. Classical-orthography presses split 21 to 16 on which form they set and reformed presses set the ligature, so an engine that emits one where the transcript has the other has not misread anything. Ground truth stays as printed; the metric folds եւ to և after lowercasing. The trainer's copy of this module carries the same change. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.1 --- src/tetrak_ocr/accuracy.py | 15 +++++++++++++-- tests/ocr/test_accuracy.py | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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("Ա. Գրկ.")