Commit Graph

4 Commits

Author SHA1 Message Date
JasonFraser db11c1f7c5 Manual layout mapping: correct successful extractions, OCR-sourced statements, money-parsing fixes
- Compute a fingerprint unconditionally on every successful extraction
  (not just the two failure paths), so a "Map" button on an already-
  successful document can open the manual mapping screen to CORRECT it
  via a real fingerprint, not just the auto-triggered failure flow.
- Extend forced-mapping support to OCR-sourced statements (scanned PDFs
  and raw photos): raw_ocr_extract.py gains forced_zones/header_bottom/
  date_format/value_patterns support and a new header_candidate_geometry
  for OCR-derived fingerprinting; a forced OCR mapping bypasses Docling's
  table-structure call entirely.
- Recognize parenthesized negative amounts ("(25.00)") via a shared
  _split_sign() helper used by both _parse_money() and
  _parse_money_with_patterns() - fixes a real blank-extraction bug on a
  single-Amount-column statement using this accounting convention.
- Upscale a low-resolution image before OCR (_MIN_OCR_WIDTH_PX) - a real
  480x800px phone photo was barely readable by tesserocr at native size.
- ManualMappingView.vue: no longer requires a Balance column (some real
  statements don't print one), and imagePointScale converts a drawn
  region's coordinates from an image's natural-pixel space into PDF
  points before sending a forced mapping - every image-sourced mapping
  before this sent zones in the wrong coordinate space entirely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-24 08:15:34 -04:00
JasonFraser 62ad6168e5 Add modular layout-quirks tier; fix a new statement's wrapped header, $-prefixed amounts, and ISO dates
L.1 of the layout-mapper plan (docs at /Users/jason/.claude/plans/witty-inventing-walrus.md):
a new backend/services/extraction/layout_quirks.py runs as a zero-friction fallback after
the keyword/geometry header detector fails, fixing mechanical geometric oddities (here, a
header label wrapped across physical lines) without requiring a manual mapping step. Also
generalizes money-token recognition to accept a leading "$" and date recognition to accept
an unambiguous YYYY/MM/DD shape - both real gaps surfaced by the same new statement once its
header was fixed. Relocates table_extract.py's private header-matching helpers into
layout_rules.py as public functions to avoid a circular import with the new module.

Verified: measure.py byte-identical on HSBC/RBC (every change is a provable no-op there);
the real statement that prompted this now extracts 36/36 transactions through the live
container with statement_balance/running_balance/date_sanity/structure_sanity all passing,
every row spot-checked against the source PDF; the existing scanned-statement OCR fixture
re-verified with zero regression.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-14 01:09:43 -04:00
JasonFraser f65dd3fde0 Add per-row source position capture for the review screen's highlighting
R.1 (backend half) of the staged review-screen plan (Phase 2). Every
transaction now carries source_page/source_bbox - purely additive, so
the frontend's upcoming pdf.js viewer can box the exact printed row a
flagged transaction came from.

Traced extraction_service.py first: the canonical transactions list for
a normal text PDF always comes from pdfplumber (table_extract.py);
Docling's own extract_transactions() only feeds the cross-check
confidence signal, never the returned data. So this only needed to
touch table_extract.py and raw_ocr_extract.py (the OCR pixel-position
fallback), zero changes to engine-selection/cross-check logic.

One shared helper, table_extract._line_bbox(), used by both files
(mirrors how raw_ocr_extract.py already reuses _classify_money/_REF_RE
rather than re-implementing them) instead of two separate
implementations that could drift apart. A new _union_bbox() grows a
transaction's box as narrative lines merge into it, both the trailing
direction (HSBC) and leading direction (RBC).

Docling's own OCR-table-structure path doesn't get a real bbox (a
synthetic row-index, not a pixel position) - those transactions get
source_bbox: null, a graceful no-highlight rather than an error.

Verified: measure.py run before/after, byte-identical pass rate and
field accuracy on all three fixtures. A real /api/process call against
both HSBC and RBC fixtures confirmed every existing field unchanged.
Then the check measure.py can't make at all: rendered both fixtures'
pages for real and drew the reported source_bbox on the actual page
image - every box landed on exactly the right printed row, including
HSBC's trailing-narrative merge correctly widening the box.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-13 11:18:10 -04:00
JasonFraser 01cd607728 Fix edit-icon color, description autogrow, and add image zoom controls
Three small UI fixes from earlier testing, never committed:

- Pencil edit icon now uses the same blue accent token the Save button
  already does (.row-btn.edit), instead of the default muted gray.
- Description textarea boxes left stale blank space after hiding the
  Source Document panel - the drag-resizer already re-measures box
  height on resize (autoGrowAll()), but the Hide/Show toggle never did,
  so widening the transactions column left every description box at its
  old height until something else happened to trigger a re-measure.
  Added the missing call.
- Images shown in the Source Document panel had no zoom controls at all
  (unlike PDFs, which get the browser's native viewer toolbar for free).
  Added a dedicated zoomable/scrollable image panel with -/+/Fit
  controls, width-based zoom (not CSS transform, so the panel's
  overflow:auto actually produces real scrollbars when zoomed in),
  opening at fit-width by default.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 23:44:06 -04:00