|
| 1 | +# Parking Sign Confidence Classifier — Example Program |
| 2 | + |
| 3 | +**Date:** 2026-05-17 |
| 4 | +**Persona:** Quill |
| 5 | +**Gate:** Fast-track G0/G1/G4 (< 1 day, no interpreter changes, example program only) |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## What happened |
| 10 | + |
| 11 | +Douglas asked what would be a good candidate to write in Codifide, given the |
| 12 | +projects in the workspace. The answer was a parking sign confidence classifier |
| 13 | +inspired by DecodeTheSign — the iOS app that interprets confusing parking signs |
| 14 | +and refuses to guess when confidence is low. |
| 15 | + |
| 16 | +The program was written, tested, and runs correctly on the first attempt (after |
| 17 | +one cost-ordering fix for sign type priority). |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## What shipped |
| 22 | + |
| 23 | +`examples/parking_sign.cod` — a 140-line Codifide program that demonstrates: |
| 24 | + |
| 25 | +1. **Belief dispatch** — `gate_ocr` uses `belief()` and `believe` to gate on |
| 26 | + OCR confidence. Above 0.85: proceed. Between 0.70–0.85: flag as low |
| 27 | + confidence. Below 0.70: refuse with `bottom`. |
| 28 | + |
| 29 | +2. **Cost-based multi-candidate dispatch** — `classify_sign_type` has six |
| 30 | + candidates ordered by specificity. Street cleaning (cost 1) beats the |
| 31 | + generic time-restricted pattern (cost 10) even though both match signs |
| 32 | + containing "AM"/"PM". |
| 33 | + |
| 34 | +3. **First-class refusal** — Two refusal paths: `gate_ocr` refuses below |
| 35 | + 0.70 confidence, and `verdict_for_unknown` refuses on unrecognized sign |
| 36 | + types. Both use `bottom "reason"` with explanatory strings. |
| 37 | + |
| 38 | +4. **Contracts** — Preconditions validate confidence range (0.0–1.0) and |
| 39 | + non-empty text. The runtime enforces these at every call boundary. |
| 40 | + |
| 41 | +5. **Pure functions throughout** — Every function declares `effects {}`. |
| 42 | + No I/O, no model calls. The sign text arrives pre-extracted (simulating |
| 43 | + the OCR-to-rule-engine handoff in DecodeTheSign's architecture). |
| 44 | + |
| 45 | +6. **Parallel evaluator opportunity** — The `main` function's `list()` |
| 46 | + call contains eight independent sign analyses with no shared state. |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Test results |
| 51 | + |
| 52 | +``` |
| 53 | +$ python3 -m codifide run examples/parking_sign.cod |
| 54 | +['NO', 'YES', 'NO', 'NO', 'CONDITIONAL', 'UNKNOWN', True, True] |
| 55 | +``` |
| 56 | + |
| 57 | +| Input | Confidence | Result | Explanation | |
| 58 | +|-------|-----------|--------|-------------| |
| 59 | +| "NO PARKING ANY TIME" | 0.95 | NO | Clear prohibition | |
| 60 | +| "2 HR PARKING 8AM-6PM EXCEPT SUNDAY" | 0.88 | YES | Metered — you can park | |
| 61 | +| "PERMIT PARKING ONLY ZONE 4" | 0.92 | NO | Need permit | |
| 62 | +| "NO STOPPING 7AM-9AM MON-FRI" | 0.91 | NO | Clear prohibition | |
| 63 | +| "STREET CLEANING TUESDAY 8AM-10AM" | 0.87 | CONDITIONAL | Time-dependent | |
| 64 | +| "FREE PARKING ALL DAY" | — | UNKNOWN | No recognized pattern | |
| 65 | +| "blurry text" | 0.45 | ⊥ (bottom) | Refused — confidence too low | |
| 66 | +| "maybe no parking?" | 0.72 | ⊥ (bottom) | Refused — low confidence path | |
| 67 | + |
| 68 | +Full test suite: 461 passed, 0 skipped, no regressions. |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## Design decision: cost ordering |
| 73 | + |
| 74 | +The first attempt used intuitive costs (no parking = 1, time-restricted = 5, |
| 75 | +cleaning = 15). This caused "STREET CLEANING TUESDAY 8AM-10AM" to match |
| 76 | +`TIME_RESTRICTED` (cost 5, matches "AM") before `STREET_CLEANING` (cost 15). |
| 77 | + |
| 78 | +The fix: order by specificity, not by intuition. More distinctive keywords |
| 79 | +get lower costs. The broad "contains AM or PM" pattern gets cost 10 — it's |
| 80 | +the catch-all for time-based signs that don't match a more specific category. |
| 81 | + |
| 82 | +This is the Codifide idiom working as designed: cost annotations let you |
| 83 | +express "prefer the more specific match" without complex guard logic. |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## Connection to DecodeTheSign |
| 88 | + |
| 89 | +The program models the same decision architecture as DecodeTheSign's rule |
| 90 | +engine: |
| 91 | +- OCR confidence gating (FR-001 acceptance criterion 5: refuse below threshold) |
| 92 | +- Sign type classification (FR-002: evaluate rules by type) |
| 93 | +- Conservative refusal (the app's core philosophy: never guess) |
| 94 | + |
| 95 | +The difference: DecodeTheSign's real engine is time-aware (evaluates against |
| 96 | +current time, handles midnight-wrapping windows, 30-minute SOON threshold). |
| 97 | +This Codifide version is a static classifier — it demonstrates the confidence |
| 98 | +and dispatch patterns without the clock dependency. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## What I'm not yet sure of |
| 103 | + |
| 104 | +Whether the `else if` chaining in `interpret_sign` is the most idiomatic |
| 105 | +Codifide pattern. An alternative would be six separate candidates on |
| 106 | +`interpret_sign` itself, each guarded by `eq(classify_sign_type(text), "X")`. |
| 107 | +That would be more graph-native but would call `classify_sign_type` six times |
| 108 | +(once per guard). The current approach calls it once and branches. Both are |
| 109 | +valid; the language doesn't yet have a "match" construct that would make this |
| 110 | +cleaner. |
0 commit comments