refactor(parser): extract item rules and selection engine #92

Closed
opened 2026-07-07 09:26:19 +01:00 by TimCane · 0 comments
TimCane commented 2026-07-07 09:26:19 +01:00 (Migrated from github.com)

Parent: #77 (Phase A, step 4). Invariants live in the epic.

Turn item parsing into competing rules behind a selection engine.

Anchors

  • Item build loop: ReceiptParser.cs:197-209.
  • Logic to move into rules: ExtractQuantity (245-256), StripUnitPrice
    (261-279), CleanName (237-243), IsBareCharge (284-285).
  • Regexes: LeadingQuantity (59), TrailingMoney (30), UnitPriceDetail (55),
    AtUnitPrice (69), ItemCode (63), LeadingPercent (35).

Steps

  1. Add IReceiptRule in Parsing/Rules returning a candidate + confidence.
  2. Port the logic above into named rules (e.g. QuantityNamePriceRule,
    UnitPriceColumnRule, BareChargeRejectRule).
  3. Add the engine: pick the highest-confidence candidate. Calibrate confidences
    so selection reproduces today's output exactly (mirrors the current
    first-match order).

Done

  • Corpus 100% green, byte-identical output.
  • Selection is the only new machinery; no new item behaviour.
Parent: #77 (Phase A, step 4). Invariants live in the epic. Turn item parsing into competing rules behind a selection engine. ## Anchors - Item build loop: `ReceiptParser.cs:197-209`. - Logic to move into rules: `ExtractQuantity` (245-256), `StripUnitPrice` (261-279), `CleanName` (237-243), `IsBareCharge` (284-285). - Regexes: `LeadingQuantity` (59), `TrailingMoney` (30), `UnitPriceDetail` (55), `AtUnitPrice` (69), `ItemCode` (63), `LeadingPercent` (35). ## Steps 1. Add `IReceiptRule` in `Parsing/Rules` returning a candidate + confidence. 2. Port the logic above into named rules (e.g. `QuantityNamePriceRule`, `UnitPriceColumnRule`, `BareChargeRejectRule`). 3. Add the engine: pick the highest-confidence candidate. Calibrate confidences so selection reproduces today's output exactly (mirrors the current first-match order). ## Done - [ ] Corpus 100% green, byte-identical output. - [ ] Selection is the only new machinery; no new item behaviour.
Sign in to join this conversation.
No description provided.