Files
2026-07-12 10:17:17 -04:00

150 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OCR Parser Pattern Catalog
Extraction regexes and test cases for the `ocr-data-extraction` skill.
## Phone Numbers
```regex
/\(?\d{3}\)?[\s.\-]*\d{3}[\s.\-]*\d{4}/
```
Matches: `(555) 123-4567`, `555-123-4567`, `555.123.4567`, `8653353874`, `(865) 235-0156`
Normalize: strip all non-digits after match.
## VIN (17-char)
```regex
/\b[A-HJ-NPR-Z0-9OIQ]{17}\b/i
```
Lenient: accepts O (common OCR error for 0), I (for 1), Q (for 0).
Normalize: `v.toUpperCase().replace(/O/g,'0').replace(/I/g,'1').replace(/Q/g,'0')`
Standard VIN: 17 chars, alphanumeric, no I/O/Q in real VINs, but OCR produces them.
## Dates
Priority order of patterns:
```js
// 1. YYYY-MM-DD or YYYY/MM/DD
/(\d{4})[\/\-.](\d{1,2})[\/\-.](\d{1,2})/
// 2. MM/DD/YYYY or MM/DD (year defaults to current)
/(\d{1,2})[\/](\d{1,2})(?:[\/](\d{4}))?/
// 3. "Jan 15, 2024" or "January 15 2024"
/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\s+(\d{1,2})(?:[,\s]+(\d{4}))?/i
```
Normalize all to `YYYY-MM-DD`.
## Times
```regex
/\b(\d{1,2}):(\d{2})\s*(AM|PM|am|pm)?\b|\b(\d{1,2})\s*(AM|PM|am|pm)\b/
```
Matches: `9:00 AM`, `14:00`, `1:30PM`, `8am`, `8 AM`
Normalize to 24hr `HH:MM`. PM adds 12 unless hour=12. AM at 12 becomes 00.
## Duration
```regex
/\b(\d+)\s*(?:min|minutes?|hrs?|hours?)\b/i
```
Matches: `60 min`, `1 hour`, `2 hours`, `90min`
If "hour/hr" in match text, multiply value by 60.
## Vehicle Detection
Year pattern: `/\b(19|20)\d{2}\b/`
Make keywords (case-insensitive):
```
ford|chevy|chevrolet|toyota|honda|nissan|bmw|mercedes|audi|dodge|jeep|gmc|ram|hyundai|kia|subaru|mazda|vw|volkswagen|lexus|acura|infiniti|cadillac|buick|chrysler|lincoln|tesla|volvo
```
## Advisor + RO Code
```regex
/^([A-Z][a-z]+)\s+(\[[^\]]+\])\s+(.*)/
```
Strip group 1 (advisor name) and group 2 (RO code). Save group 2 as note. Return group 3 (service description).
## Boundary Detection
### Primary: multi-space gap before name+phone
```regex
/\s{2,}(?=\S+(?:\s+\S+){0,1}\s*$)/
```
Finds 2+ spaces before the last 1-2 words that precede a phone/VIN marker.
### Fallback: capitalized name before phone
```regex
/([A-Z][A-Za-z]+(?:\s+[A-Z][A-Za-z]+){0,1})\s*$/
```
When no multi-space gap exists, detect last 1-2 capitalized words as the next appointment's name.
## Header/Noise Filters
```regex
# Separator lines
/^[\-=_*#]{3,}$/
# Short all-caps headers (< 25 chars)
/^[A-Z\s]+$/ (with length check)
# Known header words (case-insensitive)
/^(schedule|appointments|roster|calendar|upcoming|date|time|customer|name|phone)$/i
# Table header row detection
/\b(name|phone|date|time|service|vehicle|vin|customer|appointment|mileage|advisor|status)\b/i
```
## Verified Test Cases
### 1. Two appointments with column spacing
```
John Smith (555) 123-4567 2024-06-15 9:00 AM Oil Change 60 min 2018 Toyota Camry
Jane Doe (555) 987-6543 06/20/2024 2:00 PM Brake Inspection 90 min 2020 Honda Civic
```
→ 2 appointments, all fields correct
### 2. Headers with separators
```
SCHEDULE
--------
Robert Brown 865-555-1234 Jan 15, 2024 8:00am Tire Rotation 1 hour Toyota Tacoma
Sarah Wilson (423)555-6789 03/01/2024 1:30PM AC Repair 2 hours Jeep Grand Cherokee
```
→ 2 appointments, headers/separators stripped
### 3. Single appointment
```
Mike Johnson 2024-07-01 10:30 AM Transmission Fluid 2022 Ford F-150
```
→ 1 appointment, vehicle correctly separated from service
### 4. Table with header row
```
Name Phone Date Time Service Vehicle
John Smith 555-123-4567 2024-06-15 9:00 AM Oil Change 2018 Toyota Camry
Jane Doe 555-987-6543 06/20/2024 2:00 PM Brake Inspection 2020 Honda Civic
```
→ 2 appointments, header row skipped
### 5. Real shop screenshot (3 appointments, OCR-garbled)
```
Gary Bowers 8653353874 Rrahman [REP] Tailgate wiring harness recall 2023 Honda RIDGELINE VIN SEPYK3F70PBO11523 60min garyb9623@gmail.com
HITESHKUMAR PATEL (865)235-0156 Rrahman [23-046:6MX00] Odyssey MOST 2023 Honda ODYSSEY VIN SENRLEHB9PB042710 60min
STEPHEN LOWERY (865)384-6984 Rrahman [MA10] Oil w/Filter Change 2013 HONDA CROSSTOUR VIN SJ6TF1HS4DLO01541 60min
```
→ 3 appointments, VINs corrected (O→0), RO codes extracted, advisor names stripped