0006 ratcliff autojunk - CyrilB1531/lodestar GitHub Wiki
0006 — Ratcliff-Obershelp: difflib's autojunk heuristic
Status: accepted · Date: 2026-08-01
Context
difflib.SequenceMatcher applies an autojunk filter by default: in a sequence
of more than 200 elements, any element appearing in more than 1% of positions is
treated as "junk" and ignored when finding matching blocks. This can change
ratio() on long strings.
Decision
- Implement true Ratcliff-Obershelp, without autojunk:
RatcliffObershelpcomputes2·M/Tover the recursive pairing of the longest common sub-block, discarding no element. - Generate the oracle with
autojunk=False, so it is in exact parity with our implementation at all lengths.
Consequences
- For any input ≤ 200 elements,
RatcliffObershelp.Similarityis identical todifflibby default (autojunk doesn't trigger). - Beyond 200 elements, DataNet may differ from
difflibby default (but coincides withdifflib(autojunk=False)). This is a deliberate choice: autojunk is a heuristic optimization of difflib, not a property of the Ratcliff-Obershelp metric. Documented divergence per §5 of the brief.