tetrak_ocr.accuracy

Text similarity metrics for OCR evaluation.

Two metrics are provided:

character_similarity

Uses Python’s difflib.SequenceMatcher to compare the two texts character-by-character. Returns a ratio from 0.0 (nothing in common) to 1.0 (identical after normalisation). Good for detecting small transcription errors and OCR noise.

word_recall

Computes what fraction of the words in the expected text were also found in the actual OCR output. This is a recall-oriented metric: it rewards capturing all the content, and is tolerant of reordering or extra words introduced by the OCR engine.

Both functions normalise their inputs first (lowercase, collapsed whitespace) so that trivial formatting differences do not affect scores.

Functions

character_similarity(actual, expected)

Return character-level similarity as a ratio 0.0–1.0.

normalise(text)

Lowercase, equate Armenian punctuation homoglyphs, collapse whitespace.

word_recall(actual, expected)

Return the fraction of expected words present in the OCR output.