Skip to content

About

Deterministic 3-layer Danish school & parent text parser (Aula, weekly plans, OCR slips) — MIT, 0 deps, Node 18+ & React Native

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

skole-parser

Dansk dokumentation (README.da.md)

Zero-dependency, offline-first Danish school & parent-message parser under the MIT license.

skole-parser powers Taskero ("Skoletaske + Ro"), turning Danish school weekly plans (ugeplaner), Aula threads, parent messages, and OCR-scanned flyers (skole sedler) into structured calendar and task actions with 0 network calls and 0 runtime dependencies.


Quick Start (skole-parser/core & skole-parser/aula)

import { extractHeuristicActions } from "skole-parser/core";
import { shouldFlipToTomorrow } from "skole-parser/aula";

const actions = extractHeuristicActions(
  "Emil (0. kl.): Juleklip fredag 27/11 kl. 14:00-16:00 i festsalen. Husk saks og lim. Ingen idræt fredag.",
  {
    today: "2026-11-26",
    child: "Emil",
    source: "prose",
  },
);

const eveningState = shouldFlipToTomorrow({
  presenceState: "Tjekket ud",
  isEveningWindow: false,
});

console.log(JSON.stringify(actions, null, 2));
console.log(eveningState); // { showTomorrow: true, reason: "picked_up" }

Exact output from extractHeuristicActions(...):

[
  {
    "id": "ecd7aad330902b93",
    "source": "prose",
    "date": "2026-11-27",
    "deadline": null,
    "type": "husk",
    "title": "Juleklip fredag 27/11 kl. 14:00-16:00 i festsalen",
    "timePlace": "kl. 14:00-16:00",
    "rsvpPhone": null,
    "mobilePayBox": null,
    "amountDkk": null,
    "url": null,
    "quote": "Emil (0. kl.): Juleklip fredag 27/11 kl. 14:00-16:00 i festsalen.",
    "prepLeadDays": 1,
    "smsRsvpHref": null,
    "child": "Emil"
  },
  {
    "id": "97541a31524bc6f1",
    "source": "prose",
    "date": "2026-11-27",
    "deadline": null,
    "type": "husk",
    "title": "Husk saks og lim",
    "timePlace": null,
    "rsvpPhone": null,
    "mobilePayBox": null,
    "amountDkk": null,
    "url": null,
    "quote": "Husk saks og lim.",
    "prepLeadDays": 1,
    "smsRsvpHref": null,
    "child": "Emil"
  },
  {
    "id": "2b7e44f8a7186138",
    "source": "prose",
    "date": "2026-11-27",
    "deadline": null,
    "type": "aendring",
    "title": "Ingen idræt (skemaændring)",
    "timePlace": null,
    "rsvpPhone": null,
    "mobilePayBox": null,
    "amountDkk": null,
    "url": null,
    "quote": "Ingen idræt fredag.",
    "prepLeadDays": 1,
    "smsRsvpHref": null,
    "child": "Emil"
  }
]

Architecture: skole-parser/core vs skole-parser/aula

skole-parser separates general Danish text parsing from optional family-app / Aula workflow helpers while keeping the root "skole-parser" entrypoint 100% backwards compatible:

Subpath Purpose Key Exports
"skole-parser/core" Pure Danish parsing, dates, OCR cleanup, LLM prompt contracts, deduplication, .ics export (0 SFO/UI assumptions) extractHeuristicActions, normalizeOcrText, prepareTextChunks, stripTimetableBoilerplate, extractStructuredCalendar, parseDanishDate, groundDate, buildTextExtractionPrompt, buildCompactExtractionPrompt, buildImageExtractionPrompt, parseLlmResponse, normalizeLlmOutput, dedupeActions, buildIcsCalendar
"skole-parser/aula" Optional Aula / daily-prep companion helpers shouldFlipToTomorrow, deriveTimetableGearFallbacks, extractUgeplanTimetableLessons, resolveDefaultPlanWeek, classifyAudienceStream, resolveActionCompletionKind, TIMETABLE_GEAR_RULES
"skole-parser" Full backwards-compatible barrel Re-exports everything from ./core and ./aula (generateIcs alias preserved)

Caller-Configurable Companions (./aula)

  • shouldFlipToTomorrow({ presenceState, isEveningWindow, checkedOutStates, noisyPresenceStates }) defaults to Danish SFO presence strings (such as "Tjekket ud" and "Hentet"), and accepts caller-supplied checkedOutStates / noisyPresenceStates iterables to adapt to any institution or locale without modifying library code.
  • deriveTimetableGearFallbacks(lessons, existingActions, { gearRules, ... }) defaults to TIMETABLE_GEAR_RULES (idraet, svoemning, udeskole, bibliotek) and accepts custom gearRules?: GearRule[], theme-week exclusions, cancellations, and excursion overrides.

3-Layer Hybrid Pipeline

  1. Layer 1 — Deterministic Preprocessing & OCR Cleanup (pre-layer.ts, ocr-clean.ts): Normalizes OCR glitches (normalizeOcrText), strips hourly timetable rows and EasyIQ boilerplate (stripTimetableBoilerplate), extracts structured calendar lines (extractStructuredCalendar), and chunks prose (<= 2.8 KB) with deterministic FNV-1a hashes (hashContent).
  2. Layer 2 — Heuristic Extractor or Local On-Device LLM (heuristic-extractor.ts, prompts.ts, llm-json.ts): Runs offline heuristics (extractHeuristicActions) or feeds bounded chunks to an on-device LLM via buildTextExtractionPrompt / buildCompactExtractionPrompt / buildImageExtractionPrompt, then recovers malformed or truncated JSON via parseLlmResponse and escapeRawControlCharsInJsonStrings.
  3. Layer 3 — Danish Grounding, Deduplication & Export (post-layer.ts, danish-date.ts, date-grounding.ts, dedupe.ts, ics.ts): Resolves DD/MM dates across school-year rollovers (resolveSchoolYearDate, groundDate), extracts 8-digit RSVP phone links (smsRsvpHref), MobilePay boxes (mobilePayBox), and DKK amounts (amountDkk), merges/deduplicates reminders (dedupeActions), and exports RFC 5545 calendars (buildIcsCalendar).

Reproducible Evaluation Benchmark (npm run bench)

Run npm run bench (source in bench/) to evaluate deterministic extraction across a 60-case anonymized synthetic Danish corpus spanning EasyIQ, MinUddannelse, Meebook, Docendo, SystematicMomo, Aula threads, OCR flyers, and adversarial noise traps:

Category Cases Expected Predicted TP FP FN Precision Recall F1 Critical Recall Noise Rejection
ugeplan 30 50 46 45 1 5 97.8% 90.0% 93.8% 88.0% 100.0%
aula_message 10 10 10 9 1 1 90.0% 90.0% 90.0% 100.0% 100.0%
ocr_slip 10 10 10 9 1 1 90.0% 90.0% 90.0% 100.0% 100.0%
adversarial_noise 10 1 2 1 1 0 50.0% 100.0% 66.7% 100.0% 88.9%
Overall 60 71 68 64 4 7 94.1% 90.1% 92.1% 92.7% 92.9%
  • Overall metrics (evaluatePublicCorpus()): 60 cases, 71 expected actions, 68 predicted actions (64 TP, 4 FP, 7 FN) — Precision 94.1%, Recall 90.1%, F1 92.1%, Critical-Deadline Recall 92.7% (38/41), Noise-Trap Rejection 92.9% (13/14).
  • Benchmark files (bench/): bench/types.ts, bench/corpus-ugeplaner.ts (30 weekly-plan cases), bench/corpus-messages-ocr.ts (30 message, OCR slip, and adversarial noise cases), and bench/run-bench.ts (evaluatePublicCorpus(), formatBenchmarkMarkdown()).

Unit & Regression Suite (test/ — 12 Files)

Test File Scope
test/danish-date-and-pre.test.ts Danish numeric/month/weekday dates, school-year rollover, grounding, pre-layer stripping
test/post-layer-and-ics.test.ts LLM JSON salvage, normalization, birthday/payment merging, RFC 5545 .ics export
test/heuristic-extractor.test.ts Offline prose/flyer extraction, silent inbox triage, noise suppression
test/daily-driver.test.ts Timetable gear fallbacks, audience streams, shouldFlipToTomorrow, plan week default
test/skema-rules.test.ts Theme-week suppression, PE vs. movement guard, excursion/day-off rules, priority sorting
test/action-completion-kind.test.ts 3-way "pakket" vs "udfoert" vs "set" completion classification
test/week-prompt-menu.test.ts Week-scoped weekday deadlines, compact GGUF prompt contract, canteen/menu header noise
test/week49-parser-fixes.test.ts Past-tense recap suppression, negated packing as aendring, conditional reassurance, photo headers
test/v0310-polish.test.ts Save-the-date filtering, calendar lookahead cap, undated dedupe, Bio cinema excursions
test/generalization.test.ts Cross-school generalization across municipal naming, rooms, and canteens
test/core-aula-ocr-compat.test.ts ./core vs ./aula isolation, custom state/gear rules, normalizeOcrText, zero-network audit
test/public-benchmark.test.ts 60-case synthetic corpus invariants, zero-PII enforcement, deterministic regression floors

Known Limitations, Recall Long-Tail & High-Stakes Deadlines

Deterministic regex and rule engines have a recall long-tail on free-form Danish prose with implicit wording (e.g. indirect reminders lacking explicit cues), unusual abbreviations, or severely degraded OCR scans (the 9.9% miss rate in the benchmark reflects these edge cases).

For safety-critical flows — payments, field-trip permissions, and hard RSVP deadlines — do not rely on heuristics alone:

  1. Pair skole-parser/core (prepareTextChunks + prompts.ts) with a Layer-2 on-device LLM normalized via normalizeLlmOutput.
  2. Present a human-in-the-loop confirmation step before saving deadlines or notifications (just like Taskero's 2-step slip confirmation modal).

Language Design Rationale

TypeScript symbols, types, test descriptions, and public documentation are written in English for international auditability, while src/prompts.ts and parsing rules are written in Danish:

  • Small 2B–4B on-device models achieve substantially higher extraction fidelity and date accuracy (DD/MM vs US MM/DD) when system instructions and examples match the Danish source prose directly.
  • Prompt structure and output normalization contracts are continuously regression-tested in test/week-prompt-menu.test.ts and test/post-layer-and-ics.test.ts.

OCR Input Contract (normalizeOcrText)

normalizeOcrText(raw: string): string prepares raw text from mobile OCR or PDF text layers:

  • Rejoins line-wrap hyphenation (e.g. "fødsels-\ndag" -> "fødselsdag").
  • Repairs O/o -> 0 and I/l -> 1 strictly inside explicit Danish time/date contexts (e.g. "kl. l4:OO" -> "kl. 14:00", "d. l5/l2" -> "d. 15/12", "kl. O9:3O" -> "kl. 09:30") without corrupting ordinary words ("Ole", "maj", "I/O").
  • Strips stray pipe (|, ¦) and bullet artifacts while preserving meaningful line breaks.

extractHeuristicActions automatically invokes normalizeOcrText when source: "photo" or normalizeOcr: true is passed. Supported upstream OCR sources include Google ML Kit (Android), Apple Vision (iOS), Android PdfRenderer, and Apple PDFKit.


Installation & Runtime Compatibility (Node >= 18, React Native / Hermes, Browsers)

Release builds commit precompiled ES2022 JavaScript (dist/*.js) and TypeScript declarations (dist/*.d.ts) with "sideEffects": false and "react-native", "import", "default", and "types" export conditions for Node.js >= 18, React Native / Metro / Hermes, and modern browsers with zero TypeScript loader required.

  1. Immutable GitHub Release Tarball (with SHA-256 verification):
    curl -fsSLO https://github.com/taskero-dk/skole-parser/releases/download/v0.2.0/skole-parser-0.2.0.tgz
    sha256sum skole-parser-0.2.0.tgz   # compare with the SHA-256 published in the v0.2.0 release notes
    npm install ./skole-parser-0.2.0.tgz
  2. Prebuilt GitHub Tag (#v0.2.0):
    npm install github:taskero-dk/skole-parser#v0.2.0
  3. npm Registry Readiness: package.json includes "publishConfig": { "access": "public", "provenance": true } for public npm publishing.

Verifiable Zero-Network & Zero-Dependency Guarantee

  • package.json ships with "dependencies": {} (zero transitive runtime dependencies).
  • Static audit command:
    grep -rnE "fetch|XMLHttpRequest|WebSocket|http|node:" src/
    Returns only pure URL-matching regex patterns in post-layer.ts / noise-filters.ts — zero HTTP clients, telemetry, file I/O, or Node built-ins.
  • Enforced automatically on every test run in test/core-aula-ocr-compat.test.ts.

License, Governance & Roadmap (MIT vs AGPLv3)

  • skole-parser (MIT, 0 CLA): Independent open-source library under the MIT License, versioned independently in CHANGELOG.md with no Contributor License Agreement required. See CONTRIBUTING.md and SECURITY.md.
  • Taskero Ecosystem (Open-Core, AGPLv3): github.com/taskero-dk/taskero is licensed under GNU AGPLv3 (AGPL-3.0-or-later); commercial distribution via taskero.dk and app stores funds ongoing parser and mobile maintenance.
  • Roadmap: Publish directly to the public npm registry with provenance attestation, expand the bench/ synthetic corpus across additional Danish school platforms and degraded OCR patterns, and continue refining prompts.ts + post-layer normalization for compact on-device models.

Taskero and skole-parser are independent parent tools and are not affiliated with KOMBIT A/S, Aula, or MitID.

About

Deterministic 3-layer Danish school & parent text parser (Aula, weekly plans, OCR slips) — MIT, 0 deps, Node 18+ & React Native

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages