Languages (v0.3.0): words, lemmas, coverage, levels, alignment #3

Merged
mnovak merged 2 commits from feature/languages into main 2026-11-17 19:35:10 +01:00
Owner

Day 3 core (v0.3.0): the pure half of "loved books in the original". The day page is docs/03_languages.md in the app repo.

New crate liber-lang (no outside data, no files, no clock; in the purity scan):

  • tokens: words, numbers (Roman numerals too) and punctuation by UAX #29, with the reader's UTF-16 offsets; sentence starts; sentences.
  • Lemmatizer trait; Table (form → lemma TSV, capped: hostile input), Rules per language (hand-written suffix rules and irregular lists), Headwords to choose among rule candidates, Chain = table → rules.
  • Profile: lemma counts per chapter; coverage, later ("comes up N more times"), warmup (5 most frequent unknown lemmas); lemma_at for a tapped word; names and numbers never count.
  • level: 500…8,000 known lemmas; unlock at 95% coverage, 90% for a book read in one's own language; percent rounds down.
  • concept_id: w-<lang>-<16 base32 of sha256(folded lemma)> (Ludus rule).
  • align: Gale–Church over 1:1/1:0/0:1/2:1/1:2/2:2 with anchors (numbers, name stems), banded so a book-length run stays small; sentence_pairs; score (P/R/F1 over links).

liber-library: Op::Word (known / learning / unknown, last writer wins), Op::KnownBand, Op::Edition, Field::Familiar; Library.words, Library.bands, Book.familiar, Book.editions; replayed by the export; caps on lang, lemma length and count.

Mandatory tests:

  1. Coverage (tests/coverage.rs, 7): hand-counted 10/16 with a name, numbers and a Roman numeral excluded; every inflected form of a known lemma known; German names need a lexicon; later counts, warm-up, tapped word, levels, concept ids.
  2. Lemmatizers (tests/lemma.rs, 3): rules only on fixtures written here: English 88.9% (56/63), German 78.3% (47/60), Latin 80.7% (46/57); floors 85/75/75. Table and headwords precedence; table caps.
  3. Alignment (tests/align.rs, 4): fixture pair (a story written here, DE/EN, CC0) with a merge, an omission and a split sentence: paragraph F1 1.00; sentence pairs (1:1, 1:2); a 1,500-paragraph synthetic book with omissions and merges: F1 0.999, last bead exact.
    Plus liber-library/tests/words.rs (3): any-order merge, hostile events, export round trip.

Workspace: 91 tests green; clippy 0; scripts/deps.mjs 101 crates, 0 not allowed (new: unicode-segmentation, MIT OR Apache-2.0).

Self-review:

  • The fixture pair is not a published edition: no published DE/EN pair is licence-clear to commit; ours is CC0 and exercises merge, omission and split. A real-edition evaluation follows once Mark picks a book.
  • Rules are a fallback, not the answer: German loses umlaut plurals and adjective/verb ambiguity, Latin the third declension. The tables (data decision pending) are what make it good.
  • An omission now costs its prior only (no length term): without that, Gale–Church preferred a bad 2:1 merge over the true omission.
  • German names cannot be told from nouns without a lexicon: every capitalised word counts until a table or headwords are installed (stated in the day page).
Day 3 core (v0.3.0): the pure half of "loved books in the original". The day page is `docs/03_languages.md` in the app repo. **New crate `liber-lang`** (no outside data, no files, no clock; in the purity scan): - `tokens`: words, numbers (Roman numerals too) and punctuation by UAX #29, with the reader's UTF-16 offsets; sentence starts; `sentences`. - `Lemmatizer` trait; `Table` (form → lemma TSV, capped: hostile input), `Rules` per language (hand-written suffix rules and irregular lists), `Headwords` to choose among rule candidates, `Chain` = table → rules. - `Profile`: lemma counts per chapter; `coverage`, `later` ("comes up N more times"), `warmup` (5 most frequent unknown lemmas); `lemma_at` for a tapped word; names and numbers never count. - `level`: 500…8,000 known lemmas; unlock at 95% coverage, 90% for a book read in one's own language; `percent` rounds down. - `concept_id`: `w-<lang>-<16 base32 of sha256(folded lemma)>` (Ludus rule). - `align`: Gale–Church over 1:1/1:0/0:1/2:1/1:2/2:2 with anchors (numbers, name stems), banded so a book-length run stays small; `sentence_pairs`; `score` (P/R/F1 over links). **liber-library:** `Op::Word` (known / learning / unknown, last writer wins), `Op::KnownBand`, `Op::Edition`, `Field::Familiar`; `Library.words`, `Library.bands`, `Book.familiar`, `Book.editions`; replayed by the export; caps on lang, lemma length and count. **Mandatory tests:** 1. Coverage (`tests/coverage.rs`, 7): hand-counted 10/16 with a name, numbers and a Roman numeral excluded; every inflected form of a known lemma known; German names need a lexicon; later counts, warm-up, tapped word, levels, concept ids. 2. Lemmatizers (`tests/lemma.rs`, 3): rules only on fixtures written here: **English 88.9% (56/63), German 78.3% (47/60), Latin 80.7% (46/57)**; floors 85/75/75. Table and headwords precedence; table caps. 3. Alignment (`tests/align.rs`, 4): fixture pair (a story written here, DE/EN, CC0) with a merge, an omission and a split sentence: **paragraph F1 1.00**; sentence pairs (1:1, 1:2); a 1,500-paragraph synthetic book with omissions and merges: **F1 0.999**, last bead exact. Plus `liber-library/tests/words.rs` (3): any-order merge, hostile events, export round trip. Workspace: 91 tests green; clippy 0; `scripts/deps.mjs` 101 crates, 0 not allowed (new: unicode-segmentation, MIT OR Apache-2.0). **Self-review:** - The fixture pair is not a published edition: no published DE/EN pair is licence-clear to commit; ours is CC0 and exercises merge, omission and split. A real-edition evaluation follows once Mark picks a book. - Rules are a fallback, not the answer: German loses umlaut plurals and adjective/verb ambiguity, Latin the third declension. The tables (data decision pending) are what make it good. - An omission now costs its prior only (no length term): without that, Gale–Church preferred a bad 2:1 merge over the true omission. - German names cannot be told from nouns without a lexicon: every capitalised word counts until a table or headwords are installed (stated in the day page).
mnovak added 1 commit 2026-11-17 19:34:01 +01:00
mnovak added 1 commit 2026-11-17 19:35:06 +01:00
mnovak merged commit 42404e8a1d into main 2026-11-17 19:35:10 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/Liber-public#3