Text normalization and sentence chunker #6

Closed
opened 2026-10-25 14:57:53 +00:00 by dsh · 1 comment
Owner

Goal

Turn markdown into speakable sentences. Pure, deterministic, unit-tested — no DOM, no engine.

Scope

  • normalize(text) — drop fenced/inline code, tables, HTML, link targets (keep link text), bare URLs, emoji; collapse whitespace; expand a small safe set of symbols (& → and, % → percent, -> → to). Keep it conservative; no re-writing of prose.
  • chunk(text, maxChars) — sentence splitter on . ! ? … + CJK 。!? and paragraph breaks, with guards for abbreviations (Mr., e.g., i.e., vs., Dr.), decimals (3.14), and list markers; hard-split anything over maxChars at word boundaries.
  • Default maxChars = 400 (Piper's library chunking); expose per-engine limits (API: 4096).
  • Table-driven tests: code fence, URL, 3 000-char answer, German umlauts, CJK, empty/whitespace, interrupted partial sentence.

Acceptance

  • A reply containing a 30-line code block is spoken as its surrounding prose only, in one or more complete sentences.
  • No chunk exceeds the configured limit; no sentence is split mid-word.
  • Tests are pure and fast (< 100 ms).

Notes

  • Depends on #1. Part of M1. Feeds both local and cloud engines.
## Goal Turn markdown into speakable sentences. Pure, deterministic, unit-tested — no DOM, no engine. ## Scope - [ ] `normalize(text)` — drop fenced/inline code, tables, HTML, link targets (keep link text), bare URLs, emoji; collapse whitespace; expand a small safe set of symbols (`&` → and, `%` → percent, `->` → to). Keep it conservative; no re-writing of prose. - [ ] `chunk(text, maxChars)` — sentence splitter on `. ! ? …` + CJK `。!?` and paragraph breaks, with guards for abbreviations (`Mr.`, `e.g.`, `i.e.`, `vs.`, `Dr.`), decimals (`3.14`), and list markers; hard-split anything over `maxChars` at word boundaries. - [ ] Default `maxChars = 400` (Piper's library chunking); expose per-engine limits (API: 4096). - [ ] Table-driven tests: code fence, URL, 3 000-char answer, German umlauts, CJK, empty/whitespace, interrupted partial sentence. ## Acceptance - A reply containing a 30-line code block is spoken as its surrounding prose only, in one or more complete sentences. - No chunk exceeds the configured limit; no sentence is split mid-word. - Tests are pure and fast (< 100 ms). ## Notes - Depends on #1. Part of M1. Feeds both local and cloud engines.
Author
Owner

Done in 468e565. src/text.js exposes normalizeText + chunkText; 13 table-driven tests cover fences/inline code, tables, links/URLs, emoji, symbols, abbreviations, decimals, CJK, umlauts, 3 000-char hard splits and oversized tokens. CI run #4 green.

Note: the ##6 subagent disappeared mid-task; the Lead implemented this directly. Test count now 78 total.

**Done** in `468e565`. `src/text.js` exposes `normalizeText` + `chunkText`; 13 table-driven tests cover fences/inline code, tables, links/URLs, emoji, symbols, abbreviations, decimals, CJK, umlauts, 3 000-char hard splits and oversized tokens. CI run #4 green. Note: the ##6 subagent disappeared mid-task; the Lead implemented this directly. Test count now 78 total.
dsh closed this issue 2026-10-25 17:43:49 +00:00
Sign in to join this conversation.
No description provided.