// Simulate routeLinesToSections P1+P2+P3 for screenshot cases. const fs = require('fs'); const html = fs.readFileSync('frontend/index.html', 'utf8'); const start = html.indexOf('const highConfidence = ['); const end = html.indexOf(' ];', start) + 4; const hcBlock = html.slice(start, html.indexOf(' ];', start) + 4); eval(hcBlock.replace('const highConfidence', 'global.highConfidence')); const routesStart = html.indexOf(' const routes = [', start); const routesEnd = html.indexOf(' ];', routesStart) + 4; const routesBlock = html.slice(routesStart, routesEnd); eval(routesBlock.replace(' const routes', 'global.routes')); function routeLine(t) { const explicitPrefix = /^\s*(?:section\s+)?([A-N]\d{1,2})\s*(?:[:,;\-–—\.]\s*|\s+)(.+)$/i; const explicit = t.match(explicitPrefix); if (explicit) return explicit[1].toUpperCase(); for (const { code, rx } of global.highConfidence) { if (rx.test(t)) return code; } for (const { code, rx } of global.routes) { if (rx.test(t)) return code; } return 'UNASSIGNED'; } const cases = [ 'Main roof: Pitched valley-style roof with imitation slate covering. Some tiles have slipped, lifted, or are laid flat. Valley gutters appear to be in good condition. One ridge tile is broken. Repointing is required and verges are cracked.', 'Rainwater fittings: UPVC gutters and gullies present. A blockage was noted. The point of discharge is unknown. Front right rainwater downpipe discharges below ground. Some fittings are brittle and faded.', ]; for (const c of cases) { console.log(routeLine(c.trim()), '::', c.slice(0, 60)); }