Skip to content

Fix OCR set-code position bug + collector-number leading zeros (no-match autopsy) - #23

Merged
WilfordGrimley merged 1 commit into
masterfrom
worktree-ocr-normalization-fix
Jul 15, 2026
Merged

Fix OCR set-code position bug + collector-number leading zeros (no-match autopsy)#23
WilfordGrimley merged 1 commit into
masterfrom
worktree-ocr-normalization-fix

Conversation

@WilfordGrimley

Copy link
Copy Markdown

Summary

Post-merge Hold #1 of the pre-scale program for Stage 8 (local printing-ID pilot): classified
all 176 OCR "parsed-but-no-match" cases from the real pilot run and found two real, contained
parser bugs, both fixed here.

1. Set-code token position. parse_collector_line's set-code search took the FIRST
plausible 3-5 char token anywhere in the line - which is virtually always leading noise (a
watermark, a rarity-letter glyph merging with a stray digit into something code-shaped) rather
than the real set code, which a genuine card layout always prints AFTER the collector number.
Fixed to search the text after the number first, falling back to before only if nothing
plausible follows.

2. Collector-number leading zeros. OCR frequently reads a spurious leading zero ("0093" for
a real "93") that literal string comparison silently rejected. Fixed via
_normalize_collector_number (strip leading zeros, keep any trailing variant letter), applied
symmetrically to both the parsed reading and every candidate's stored value.

Yield delta

Precisely measured by re-parsing the exact same 176 raw texts with both the old and new logic
(isolating this cohort from 3 cards that already matched under the old parser):
47/176 (26.7%) now match.

Projected full-engine impact: OCR yield 77/300 (25.7%) -> ~124/300 (41.3%), a ~60% relative
improvement, from this small parser fix.

Confirmed live via a real (non-simulated) --dry-run afterward: 62/250 votes on a fresh
selection window, consistent with the isolated measurement.

Of the 129 still-unfixed cases: only 2/176 (1.1%) are genuinely-missing printings; the
remaining 127/176 (72.2%) are true OCR garbage with no salvageable signal - a meaningful
fraction traceable to one specific custom-frame Drive source (Source pk=1, "WilfordGrimley")
whose non-standard branding text sits inside the collector-line crop region and defeats OCR
outright.

Cross-checked against the separate 1,097-card filename tag-gap census: NOT the same root
cause.
All 1,097 have a fully recognized CanonicalExpansion code - that gap is a
name-matching problem (many are (Front)/(Back) filename-parsing artifacts on basic lands),
unrelated to this OCR fix. Two separate issues, not one fix arriving twice - the D2.5
deterministic tier is not implied here and was not built.

Test plan

  • 4 new tests covering both fixes (TestOcrParsing, TestOcrValidationRail), all passing
  • All 40 pre-existing pilot tests still pass unchanged (no regression)
  • Full backend suite: 672 passed, only the 4 pre-existing/unrelated failures remain
  • mypy/ruff/black/isort clean
  • Real --dry-run against live production data confirms the projected yield improvement

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

@WilfordGrimley
WilfordGrimley marked this pull request as ready for review July 15, 2026 17:41
@WilfordGrimley
WilfordGrimley merged commit a8feeb4 into master Jul 15, 2026
2 of 3 checks passed
@WilfordGrimley
WilfordGrimley deleted the worktree-ocr-normalization-fix branch July 19, 2026 21:53
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.

1 participant