Skip to content

data: resolve missing training filenames to canonical same-language corpora (#119) - #123

Merged
willwade merged 2 commits into
mainfrom
fix/119-training-corpus-resolution
Nov 18, 2026
Merged

willwade merged 2 commits into
mainfrom
fix/119-training-corpus-resolution

Conversation

@willwade

@willwade willwade commented Nov 18, 2026 •

Copy link
Copy Markdown

Stacked on #120 — review/merge that first. Raised from the Apple team's report (Dasher-Apple#92 worked around this in the frontend); this moves the fix into shared engine data so every frontend benefits and Apple can drop its packaging workaround.

Summary

43 shipped alphabets name training files that never shipped, although a compatible corpus exists for the same language and script (Español asks for training_spanish_ES.txt; training_wa_es_Latn.txt ships). Data-only fix, zero engine changes: Scripts/resolve-training-corpora.py (committed, idempotent, --dry-run) materializes an alias corpus under each legacy name from the canonical training_wa_<lang>_<script>.txt, so the engine's existing exact-filename lookup finds it. 31 alias files (4 NFD variants), index gains exactly the 43 training_available flips (summaries 194/46), Makefile.am registers everything.

Can this pick the WRONG corpus? (the design constraint)

Every rule exists to make that impossible, and each was verified against the data:

  • Exact (lang, script) key only — the target filename is derived from the pair, never fuzzy matching or runtime inference. Spanish has exactly one Spanish corpus (wa_es_Latn.txt, verified real Spanish); there is no second candidate to confuse it with.
  • Deliberate pairings untouched: resolution fires only when the exact declared filename is found nowhere, and existing files are never overwritten — user training accumulated under legacy names keeps its scope.
  • Fails closed on bad metadata: the "Pure Katakana" alphabets are tagged lang=ak (Akan — corrupt) → no wa_ak corpus → they stay untrained rather than risk a wrong-language corpus.
  • Japanese can't go wrong: wa_ja_Hira / wa_ja_Jpan / wa_ja_Kana are byte-identical (same md5), so the Kana-tagged "Japanese Canna" alphabet (mixed kana nodes) cannot receive a wrong-script distribution.
  • Conversion alphabets excluded (Mandarin/Pinyin conversion != "none" — their training files have conversion-specific formats).
  • Combining accents get NFD copies (their symbols are decomposed; the wa_ corpora are NFC).

Every mapping is a visible file in the diff — audit line by line.

Scope notes (deliberate, for reviewers)

  • 46 alphabets stay untrained by design (no canonical corpus for their pair): Pinyin, Bopomofo, Klingon, IPA, Hindi (lang=null), the pan-Cyrillic "Ukrainian", etc.
  • Bonus packaging fix: gamemode_en_Latn.txt / gamemode_english_GB.txt had never been listed in dist_pkgdata_DATA — autotools installs silently omitted the game-mode texts. Now registered.
  • Known limitations: "English, lower case" / "Jane Austen English Lower Case" stay untrained (lang=en, script=null — generator script-detection gap, out of scope); training_latex_GB / training_emma_GB alias generic wa_en_Latn prose (right language, no genre flavour); Data/training grows ~13MB.

Coverage (tests/test_training_corpora.cpp, 7 tests)

  1. index ↔ filesystem consistency including the summaries counters
  2. completeness: any newly-resolvable alphabet fails the build until the resolver is rerun
  3. unresolvable sentinels (Pinyin, Klingon, IPA, Pure Katakana, Mandarin, Abc) must stay reported-missing
  4. NFC aliases byte-equal their sources; NFD aliases genuinely decomposed (an NFC swap would fail loudly)
  5. Spanish trains at runtime — no "No training text" message, probabilities populated
  6. its NFD variant likewise
  7. the same alphabet minus the alias file still reports the missing corpus exactly as before — failure reporting preserved

Validation

  • Full suite 51/51 green with the new data in place; clang-format clean; changed TUs clean under -Werror; Makefile.am verified parseable (make -f behaves identically to HEAD)
  • Regeneration is generator-stable: rerunning generate-alphabet-index.py reproduces the staged index byte-identically except generated_utc
  • Two review-loop rounds with independent subagent verification of every mapping (44 alphabet→file pairs, zero mismatches), md5/normalization checks, idempotency and never-clobber reproduction

Fixes #119

Supersedes #121 — that PR was auto-closed when its stacked base branch was deleted on merge, and GitHub refuses reopen after the head rebuild. Same content: the branch is now exactly main + the two commits from #121 (3810eba data resolution + 8d1a825 Windows UTF-8 test fix). All validation history (51/51 local, full CI matrix, two review-loop rounds, Apple team review) is recorded on #121.

…orpora (#119)

43 shipped alphabets name training files that were never added to
Data/training although the engine ships a compatible corpus for the
same language and script (e.g. Espanol asks for training_spanish_ES.txt
while training_wa_es_Latn.txt ships). Only the Apple frontend papered
over this at packaging time; every other frontend started those
alphabets untrained.

Resolution is data-only (zero engine changes): the new committed
Scripts/resolve-training-corpora.py materializes an alias corpus file
under each legacy name from the canonical training_wa_<lang>_<script>
corpus for the alphabet's EXACT (lang, script) index key, so the
engine's existing exact-filename lookup finds it. Deliberately
conservative so it cannot pick a wrong corpus:

- the target is derived from the exact (lang, script) pair alone - no
  fuzzy matching, no runtime language inference; every mapping is a
  visible file in this diff
- conversion != none alphabets (Mandarin/pinyin) are excluded
- corrupt/missing lang metadata fails closed: the 'Pure Katakana'
  alphabets (tagged lang=ak, Akan) stay untrained rather than risk a
  wrong-language corpus; note the three Japanese corpora (ja_Hira,
  ja_Jpan, ja_Kana) ship byte-identical, so the Kana-tagged 'Japanese
  Canna' alphabet cannot receive a wrong-script distribution
- existing files are never overwritten - real corpora added later and
  user training accumulated under legacy names keep their scope
- combining-accents alphabets receive NFD-normalized copies (their
  symbols are decomposed; the wa_ corpora are NFC)

31 alias files cover 43 alphabets (4 NFD variants); 46 alphabets stay
untrained by design (no canonical corpus ships for their pair). The
index gains exactly the 43 training_available flips (summaries now
194/46), and Makefile.am registers the new files - which also fixes a
pre-existing packaging gap: gamemode_en_Latn.txt and
gamemode_english_GB.txt had never been listed in dist_pkgdata_DATA, so
autotools installs silently omitted the game-mode texts.

Accepted limitations: 'English, lower case' and 'Jane Austen English
Lower Case' stay untrained (lang=en but script=null in the index -
generator script-detection gap, out of scope here); training_latex_GB
and training_emma_GB alias the generic wa_en_Latn prose (right
language, no genre flavour); Data/training grows ~13MB, which
size-sensitive packaging inherits.

tests/test_training_corpora.cpp pins the invariants: index/files
consistency incl. summary counters, completeness (a newly resolvable
alphabet fails the build until the resolver is rerun), unresolvable
sentinels stay reported-missing, NFC aliases are byte-exact and NFD
aliases genuinely decomposed, Spanish and its NFD variant start
trained with no missing-corpus message, and the same alphabet minus
the alias file still reports the missing corpus exactly as before.

Fixes #119

Signed-off-by: will wade <willwade@gmail.com>
\u00f1 escapes in narrow string literals compile to a single CP1252 byte
under MSVC (the project does not pass /utf-8), so the Windows CI received
0xF1 where the engine's UTF-8 API contract requires 0xC3 0xB1 - the
alphabet lookup missed and a downstream narrow/wide conversion threw
'No mapping for the Unicode character exists in the target multi-byte
code page'. Raw UTF-8 source literals round-trip through MSVC unchanged;
same pattern the Windows-green test_multilingual.cpp already uses.

Signed-off-by: will wade <willwade@gmail.com>
@willwade
willwade merged commit de9ca60 into main Nov 18, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve missing training filenames to available compatible corpora

1 participant