Skip to content

Fix Editex overlapping letter groups (fixes #77) - #106

Open
youdie006 wants to merge 1 commit into
anhaidgroup:masterfrom
youdie006:fix/77-editex-overlapping-groups
Open

Fix Editex overlapping letter groups (fixes #77)#106
youdie006 wants to merge 1 commit into
anhaidgroup:masterfrom
youdie006:fix/77-editex-overlapping-groups

Conversation

@youdie006

Copy link
Copy Markdown

Fixes #77.

Problem

EditexHelper.letter_groups was a flat char -> int dict. The canonical Editex letter groups (Zobel & Dart 1996) OVERLAP -- C is in both {C,K,Q} and {C,S,Z}, P is in both {B,P} and {F,P,V}, and S/Z are in both {S,X,Z} and {C,S,Z}. A one-to-one char->group mapping cannot represent a character that belongs to more than one group, so later dict writes clobbered earlier keys (e.g. letter_groups['P']=1 was overwritten by ...=7). As a result r_cost's single-group equality test missed shared-group pairs and returned the mismatch cost (2) instead of the group cost (1). The last line also had a typo, {C,S,J} instead of the canonical {C,S,Z}, so Z was never in group 9 -- exactly the case reported in #77.

Fix

Replace the flat dict with the 10 canonical overlapping groups as a tuple of frozensets (the abydos reference already cited in the module docstring: AEIOUY, BP, CKQ, DT, LR, MN, GJ, FPV, SXZ, CSZ), and have r_cost return the group cost when the two characters share ANY group. d_cost/silent-letter handling and all non-overlapping return values are unchanged.

Tests

Added test_editex_overlapping_groups asserting the shared-group cases now cost 1, not 2:

  • Editex('BATTLE', 'PATTLE') == 1 (B/P share {B,P})
  • Editex('CAT', 'QAT') == 1 (C/Q share {C,K,Q})
  • Editex('MUSIC', 'MUSIQ') == 1 (C/Q share {C,K,Q})

Red/green verified in a clean python:3.12 container: the new test fails (2 != 1) before the fix and passes after; all pre-existing Editex tests and the get_raw_score docstring examples continue to pass unchanged (zero regression -- no existing test exercises any of the pairs whose cost changes).

Reference: Zobel, J. & Dart, P. (1996), "Phonetic string matching: Lessons from information retrieval"; abydos distance implementation.


This change was prepared with AI assistance and reviewed by me before submission.

EditexHelper.letter_groups was a flat char->int dict. The canonical Editex
letter groups (Zobel & Dart 1996) overlap: C is in both {C,K,Q} and {C,S,Z},
P is in both {B,P} and {F,P,V}, and S/Z are in both {S,X,Z} and {C,S,Z}. A
one-to-one char->group mapping cannot represent a character in more than one
group, so later dict writes clobbered earlier keys (e.g. P was moved from
{B,P} to {F,P,V}). The last line also had a typo, {C,S,J} instead of the
canonical {C,S,Z}, so Z was never in group 9 - the exact case in anhaidgroup#77. As a
result r_cost's single-group equality test missed shared-group pairs and
returned mismatch_cost (2) instead of group_cost (1).

Store the 10 canonical groups as a tuple of frozensets (matching the abydos
reference cited in the module) and have r_cost return the group cost when the
two characters share any group. d_cost/silent-letter handling and all
non-overlapping return values are unchanged.

Fixes anhaidgroup#77.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editex groupings not correct

1 participant