Go to file
JasonFraser 054e2a1b60 Add raw-OCR-word-box fallback for Docling table-structure failures
Docling's own OCR engine swaps (tesseract, rapidocr) and table_mode
(fast vs accurate) were all benchmarked against the same problem page
and made no difference - confirmed the table-structure model itself
(TableFormer), not the OCR engine, is the bottleneck (see CLAUDE.md).

app/raw_ocr_extract.py sidesteps TableFormer entirely: runs OCR
directly (tesserocr) for raw per-word text+position, then reuses
table_extract.py's own column-geometry logic (_find_zones/_classify_
money/etc) to derive columns from word positions, the same way it
already does for native PDFs. Two real adaptations: pixel-to-point
scaling (exact for a scanned PDF via its own known point dimensions,
heuristic for a bare photo), and cross-page zone sharing (a page with
one-sided data, e.g. zero debits, can't reliably resolve its own
columns alone - confirmed for real on HSBC page 1 - so zones resolve
from whichever page is most complete and apply across the whole
document, deterministically fixing the sign-assignment bug a single
page alone can't).

Wired into reconcile._run_ocr_only as a PER-PAGE fallback, not
document-level - confirmed necessary for real: Docling succeeded on
one page and silently missed another's table in the same conversion
call, which a document-level "did any page work" check would have
missed entirely (10 real transactions, including debits, would have
vanished with no error).

Verified end-to-end through the real running app on a genuine 2-page
scanned test file (docs/scanned_statement_2page.pdf, built from real
HSBC pages 1+2): 17/17 transactions, correct signs and balances,
date_sanity correctly flagged the one real OCR misread. measure.py
confirms zero regression on the existing text-PDF corpus.

New dependencies: tesserocr, pypdfium2, pillow (Python) plus
tesseract-ocr/libtesseract-dev/libleptonica-dev (OS, Dockerfile).
TESSDATA_PREFIX must be set explicitly - tesserocr doesn't reliably
auto-discover Debian's tessdata path on its own.

Known limitation, documented not hidden: the one-sided-data edge case
is only reliably fixed with a second page to borrow zones from - a
true single-page photo upload has no such fallback and stays a close
geometric call.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 17:22:34 -04:00
app Add raw-OCR-word-box fallback for Docling table-structure failures 2026-10-11 17:22:34 -04:00
docs Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
fixtures Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
outputs Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
templates Route scanned/photographed statements through Docling OCR 2026-10-11 09:04:24 -04:00
uploads Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
zexample Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
.gitignore Route scanned/photographed statements through Docling OCR 2026-10-11 09:04:24 -04:00
CLAUDE.md Add raw-OCR-word-box fallback for Docling table-structure failures 2026-10-11 17:22:34 -04:00
Dockerfile Add raw-OCR-word-box fallback for Docling table-structure failures 2026-10-11 17:22:34 -04:00
UI_DESIGN_THEME.md Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
UI_DESIGN_THEME_ENTERPRISE.md Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
docker-compose.yml Initial commit: Phase 1 extraction, dual-engine checks, measurement harness 2026-10-11 07:56:19 -04:00
requirements.txt Add raw-OCR-word-box fallback for Docling table-structure failures 2026-10-11 17:22:34 -04:00