mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-05 00:29:25 +01:00
feat(vocabulary): what a word is beyond what it means, and drills built from it (#71)
* feat(vocabulary): room for what a word actually needs — article, forms, example A vocabulary entry was a pair of strings. That is a glossary, and a glossary is the thing a learner reads once. What makes a word usable is the part that was missing: which article it takes, what its forms are, and a sentence it lives in. THE SCHEMA IS BUILT TO MAKE THE WRONG THING UNREPRESENTABLE, because this is the exact place a language product starts quietly inventing. `Article` is a closed set of three — `de`, `d`, `s`. A free string would let `der` into the field, which is a German article presented as a Zurich one: the invisible error §2 is entirely about, aimed at somebody who cannot detect it. A test refuses anything outside the three. `FormLabel` is closed for the reason the follow-up moves are: the label is rendered in seven languages, so it has to be a key a dictionary can translate. "du-Form" in a Russian interface is not a translation, it is German leaking. Everything is OPTIONAL, and that is the load-bearing part. A noun whose gender nobody here has checked carries no article. Absence is honest; a guess is a confident falsehood that a learner will repeat for a year. Five guards, because an article, a paradigm and an example are CLAIMS ABOUT THE LANGUAGE — a different kind of statement from a gloss, needing its own guarantees: - an article must be one of the variety's three; - any entry carrying an article, forms or an example must name a source, since this repo does not publish an assertion about the language that names nobody; - an example sentence faces the variety gate, exactly as every generated line does — a reference page teaching a Bernese form would be worse than a model doing it; - an example must actually contain the word it illustrates; - a form may not equal its own headword, which is what a row filled in to make a table look complete looks like. Example sentences are to be WRITTEN for this product, never lifted: the open resources for this variety are overwhelmingly research-licensed, so a copied sentence is a licence problem wearing the costume of a teaching aid — and later nobody could tell which sentences were safe. Also adds the article exercise to the practice engine: objectively markable, because the answer set is closed at three and the answer is a field in the pack. Nothing is inferred and no model is asked. A noun with no declared article produces no item rather than a guess. No content yet — the fields are empty and every guard passes vacuously. That is deliberate: the structure and its rules land first, so the words can be added against a standard instead of into one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(practice): paradigm and article drills, with distractors that are real forms Two more objectively-markable item kinds, and both are objective for the same reason: the answer set is closed and comes out of the pack, so nothing is inferred and no model is consulted. `article` — which of `de`, `d`, `s` the noun takes. All three are always offered; showing only the plausible two would leak the answer. This is the error a German reader is least able to avoid, because gender is carried by a word they never had to learn, so *der Velo* survives a hundred correct readings of the noun. `form` — which form goes with which person, one item per row of the paradigm. A verb with four forms is four questions: the paradigm is the thing being learned, and asking only about its first row teaches the first row. THE DISTRACTORS ARE THE VERB'S OWN OTHER FORMS, which is the whole reason this can exist here. A generated drill normally has to invent plausible wrong answers, and inventing a plausible wrong Zurich form is precisely the thing this product refuses to do — it would be indistinguishable, to the learner, from a right one. Choosing between `bi`, `bisch` and `isch` needs nothing invented: they are all real, and only one is in the right row. Three forms minimum. Two options is a coin toss and one is not a question. And the guarantee that matters more than any item: a noun with no declared article produces NO item, and a thin paradigm is not asked about at all. The schema keeps both fields optional so that "nobody here has checked this" stays expressible; an exercise that quietly filled the gap would be the one place in the product that invents language. Both are pinned by tests. Still no content — every one of these generates zero items today, and the tests pass by asserting that correctly. The drills light up when the words do. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(vocabulary): give the words genders, forms and a sentence The vocabulary list said what a word MEANS and nothing else, so an article drill was impossible and a paradigm had nowhere to live. Three fields, all optional: `article` ("de" | "d" | "s" — a closed set, so the German `der` is unrepresentable), `forms`, and one `example` pair. Optional is the point. "Nobody has checked this" has to stay expressible, and a generator that quietly filled a missing gender would be the one place in this product that invents language. `articleItems` skips any noun without a declared article, and a test walks the pack to prove it. The content: three nouns, one per gender, and the `ha` paradigm. Every string already appears in this pack's own grammar examples — `De Maa, wo dört staht`, `S Dach vom Huus`, `Häsch du am Samschtig scho öppis vor?`. Nothing below is a new claim about Zurich German; it is claims the pack already makes, promoted into the vocabulary where a learner can find them. The nouns also make the drill possible at all: every noun the list had was neuter, four of them `-li` diminutives, and an exercise whose answer is always `s` is not an exercise. Sourcing rules are recorded at the top of `vocabulary`, checked against the actual licences rather than against what is readable online. SDS (CC BY-SA 4.0) is cited as the evidence for the article system — map 3869 gives `də` at 66/66 Zurich points, map 3866 `s` at 66/66, while map 3870 is split 57/48 INSIDE the canton. The Idiotikon's CC BY-SA covers its API only; the scans carry no licence at all. ArchiMob, SwissCrawl, the SMS corpus and Weber 1948 are consult-only and named as such. So every example sentence here is written here. The provenance test now follows its pointers instead of checking a kind string, which caught a real gap: half the pairs come from `bridgeRules`, which are derived and absent from `pack.rules`. Still outstanding is the thing HEIDI.md §9 already names: no native Zurich speaker has reviewed any of it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
faf5370225
commit
dfde0301b4
8 files changed
+1285
-3
No files matched your search
@@ -0,0 +1,297 @@
|
||||
import type { VarietyPack, VarietyRule } from "../../variety/pack.ts";
|
||||
import { bridgeRules } from "../../variety/bridge.ts";
|
||||
import type { SavedWord } from "../saved/types.ts";
|
||||
import {
|
||||
ARTICLES,
|
||||
MIN_FORMS_TO_ASK,
|
||||
type ArticleItem,
|
||||
type ClozeItem,
|
||||
type FormItem,
|
||||
type PairItem,
|
||||
type PracticeItem,
|
||||
type RecallItem,
|
||||
} from "./types.ts";
|
||||
|
||||
/**
|
||||
* Turning a variety pack and a learner's own words into things to be asked.
|
||||
*
|
||||
* NOTHING HERE INVENTS LANGUAGE. Every item is assembled from material the pack
|
||||
* already vouches for — a rule the gate enforces, an example a grammar topic
|
||||
* carries, a word the learner kept. That constraint is what lets practice exist
|
||||
* at all in a product that refuses to let a model be the authority on dialect:
|
||||
* the exercises are a rearrangement of checked content, not new content.
|
||||
*
|
||||
* It also means practice grows exactly as fast as the pack does, which is the
|
||||
* honest coupling. A pack with four grammar topics cannot produce forty
|
||||
* distinct grammar questions, and generating forty by paraphrase would be
|
||||
* inventing forms at the one person who cannot tell.
|
||||
*
|
||||
* Pure and deterministic: the same inputs and the same seed give the same
|
||||
* session, so a test can assert what a learner sees.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only rules that name BOTH halves can become a question.
|
||||
*
|
||||
* A rule that only says "this form is foreign" is useful to a checker and
|
||||
* useless here: an exercise needs the right answer, not just the wrong one. So
|
||||
* `suggest` is required, and the rules without it simply produce no items
|
||||
* rather than a question with one option.
|
||||
*
|
||||
* `match` must be a literal string too. A RegExp rule matches a pattern, and a
|
||||
* pattern cannot be shown to a learner as a word — `display` exists precisely
|
||||
* because a page once printed a lookahead assertion at somebody.
|
||||
*/
|
||||
export function pairItems(pack: VarietyPack): PairItem[] {
|
||||
return [
|
||||
...fromRules(pack.rules, "target"),
|
||||
/**
|
||||
* The sibling's rules are the other half, and arguably the more useful.
|
||||
*
|
||||
* The pack says it best: somebody who writes a careful German email asking
|
||||
* about a *Fahrrad* "has written perfect German and marked themselves as
|
||||
* foreign in the first line, and no amount of care on their part would have
|
||||
* caught it". That is the definition of a thing worth drilling — an error
|
||||
* the learner cannot detect, with a right answer this product can prove.
|
||||
*/
|
||||
...fromRules(bridgeRules(pack), "bridge"),
|
||||
];
|
||||
}
|
||||
|
||||
function fromRules(rules: readonly VarietyRule[], variety: "target" | "bridge"): PairItem[] {
|
||||
const items: PairItem[] = [];
|
||||
|
||||
for (const rule of rules) {
|
||||
if (typeof rule.match !== "string") continue;
|
||||
const wrong = rule.match.trim();
|
||||
const right = rule.suggest?.trim();
|
||||
if (!wrong || !right || wrong.toLowerCase() === right.toLowerCase()) continue;
|
||||
|
||||
/**
|
||||
* The correct answer's position is decided by the CONTENT, not by a
|
||||
* random number: a shuffled position would make the session
|
||||
* non-reproducible and, worse, could put the answer on the same side
|
||||
* several times in a row by chance. Alternating on a stable property of
|
||||
* the pair keeps it unpredictable to a learner and fixed for a test.
|
||||
*/
|
||||
const answer: 0 | 1 = right.length % 2 === 0 ? 0 : 1;
|
||||
const options: [string, string] = answer === 0 ? [right, wrong] : [wrong, right];
|
||||
|
||||
items.push({
|
||||
id: `pair:${variety}:${wrong.toLowerCase()}`,
|
||||
kind: "pair",
|
||||
marking: "objective",
|
||||
variety,
|
||||
options,
|
||||
answer,
|
||||
...(rule.origin ? { origin: rule.origin } : {}),
|
||||
source: { kind: "rule", rule: wrong },
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* A blank cut into a grammar example.
|
||||
*
|
||||
* WHICH WORD IS REMOVED is the whole difficulty. Blanking a random token
|
||||
* produces "Ich ___ geschter hei gange", which tests nothing the topic is
|
||||
* about. The word worth removing is the one that carries the contrast — and
|
||||
* the pack already encodes that contrast as a pair of sentences, so it can be
|
||||
* found rather than guessed: take the target words that do not appear in the
|
||||
* bridge sentence, and blank the last of them.
|
||||
*
|
||||
* The LAST rather than the first, because in a verb-final structure — which is
|
||||
* what most of these topics are about — the word that German readers wait for
|
||||
* and never get is at the end. `gange`, not `bi`.
|
||||
*
|
||||
* When no word is unique to the target the example teaches nothing by
|
||||
* contrast, and it produces no item instead of a bad one.
|
||||
*/
|
||||
export function clozeItems(pack: VarietyPack): ClozeItem[] {
|
||||
const items: ClozeItem[] = [];
|
||||
|
||||
for (const topic of pack.grammar ?? []) {
|
||||
for (const example of topic.examples) {
|
||||
const bridgeWords = words(example.bridge).map((w) => w.toLowerCase());
|
||||
const unique = words(example.target).filter((w) => !giveaway(w, bridgeWords));
|
||||
const answer = unique[unique.length - 1];
|
||||
// A one-letter difference is a spelling variant, not a contrast worth
|
||||
// asking about.
|
||||
if (!answer || answer.length < 2) continue;
|
||||
|
||||
items.push({
|
||||
id: `cloze:${topic.id}:${answer.toLowerCase()}`,
|
||||
kind: "cloze",
|
||||
marking: "self",
|
||||
prompt: blank(example.target, answer),
|
||||
answer,
|
||||
bridge: example.bridge,
|
||||
source: { kind: "grammar", topic: topic.id },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/** The learner's own words, asked dialect-first. */
|
||||
export function recallItems(saved: readonly SavedWord[]): RecallItem[] {
|
||||
return saved
|
||||
.filter((word) => word.target.trim() && word.bridge.trim())
|
||||
.map((word) => ({
|
||||
id: `recall:${word.target.trim().toLocaleLowerCase()}`,
|
||||
kind: "recall" as const,
|
||||
marking: "self" as const,
|
||||
prompt: word.target.trim(),
|
||||
answer: word.bridge.trim(),
|
||||
...(sentenceFor(word) ? { context: sentenceFor(word) } : {}),
|
||||
source: { kind: "saved" as const },
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Which article a noun takes.
|
||||
*
|
||||
* Only for entries that actually declare one. A noun whose gender nobody has
|
||||
* checked produces no item rather than a guess — the schema keeps `article`
|
||||
* optional precisely so that absence stays expressible, and an exercise that
|
||||
* quietly filled the gap would be the one place the product invents language.
|
||||
*/
|
||||
export function articleItems(pack: VarietyPack): ArticleItem[] {
|
||||
const items: ArticleItem[] = [];
|
||||
|
||||
for (const entry of pack.vocabulary ?? []) {
|
||||
const article = entry.article;
|
||||
if (!article) continue;
|
||||
|
||||
const answer = ARTICLES.indexOf(article);
|
||||
if (answer < 0) continue;
|
||||
|
||||
items.push({
|
||||
id: `article:${entry.target.toLowerCase()}`,
|
||||
kind: "article",
|
||||
marking: "objective",
|
||||
noun: entry.target,
|
||||
bridge: entry.bridge,
|
||||
options: ARTICLES,
|
||||
answer: answer as 0 | 1 | 2,
|
||||
source: { kind: "word", word: entry.target },
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which form goes with which person.
|
||||
*
|
||||
* One item per form, so a verb with four forms is four questions rather than
|
||||
* one — the paradigm is the thing being learned, and asking about only its
|
||||
* first row teaches the first row.
|
||||
*
|
||||
* The distractors are the verb's own other forms. That is the whole reason
|
||||
* this can be marked objectively without inventing anything: a wrong option is
|
||||
* a real form of the same verb, sitting in the wrong row.
|
||||
*/
|
||||
export function formItems(pack: VarietyPack): FormItem[] {
|
||||
const items: FormItem[] = [];
|
||||
|
||||
for (const entry of pack.vocabulary ?? []) {
|
||||
const forms = entry.forms ?? [];
|
||||
// Two options is a coin toss and one is not a question.
|
||||
if (forms.length < MIN_FORMS_TO_ASK) continue;
|
||||
|
||||
const options = forms.map((f) => f.target);
|
||||
|
||||
for (const [index, form] of forms.entries()) {
|
||||
items.push({
|
||||
id: `form:${entry.target.toLowerCase()}:${form.label}`,
|
||||
kind: "form",
|
||||
marking: "objective",
|
||||
word: entry.target,
|
||||
bridge: entry.bridge,
|
||||
label: form.label,
|
||||
options,
|
||||
answer: index,
|
||||
source: { kind: "word", word: entry.target },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/** Everything that could be asked, before a session decides what to ask. */
|
||||
export function allItems(pack: VarietyPack, saved: readonly SavedWord[]): PracticeItem[] {
|
||||
return [
|
||||
...pairItems(pack),
|
||||
...articleItems(pack),
|
||||
...formItems(pack),
|
||||
...clozeItems(pack),
|
||||
...recallItems(saved),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the clue already hands the learner this word.
|
||||
*
|
||||
* Not just "does the bridge sentence contain it" — `ha` is absent from
|
||||
* "Die Frau, die ich gesehen habe" as a WORD and completely given away by
|
||||
* `habe`. A learner reading the clue produces it from the cognate without
|
||||
* knowing the structure the topic is about, which makes the item look answered
|
||||
* and teach nothing.
|
||||
*
|
||||
* AND THE TEST IS ASYMMETRIC, which took seeing the output to get right. The
|
||||
* first version refused a prefix match in either direction and killed the best
|
||||
* item in the pack: for `diminutive-li` it blanked the ARTICLE in
|
||||
* "Machsch es Bierli?" because `Bierli` extends the clue's `Bier` — which is
|
||||
* not a giveaway, it is the entire lesson.
|
||||
*
|
||||
* the clue CONTAINS the answer `habe` ⊃ `ha` → refuse, it is readable
|
||||
* the answer EXTENDS the clue `Bierli` ⊃ `Bier` → keep, that is the point
|
||||
*
|
||||
* So: refused only when a bridge word starts with the candidate, never the
|
||||
* other way round.
|
||||
*/
|
||||
function giveaway(word: string, bridgeWords: readonly string[]): boolean {
|
||||
const w = word.toLowerCase();
|
||||
return bridgeWords.some((b) => b === w || b.startsWith(w));
|
||||
}
|
||||
|
||||
/**
|
||||
* Words, Unicode-aware, with punctuation dropped.
|
||||
*
|
||||
* `\p{L}` rather than `\w`: `\w` is ASCII, and half the words in this language
|
||||
* carry an umlaut. Apostrophes are kept inside a word so `z'spöt` stays one
|
||||
* token rather than becoming two, one of which is a letter.
|
||||
*/
|
||||
function words(sentence: string): string[] {
|
||||
return sentence.match(/[\p{L}’']+/gu) ?? [];
|
||||
}
|
||||
|
||||
/** Replace one word with a blank, leaving the punctuation around it. */
|
||||
function blank(sentence: string, word: string): string {
|
||||
return sentence.replace(new RegExp(`(?<![\\p{L}])${escape(word)}(?![\\p{L}])`, "u"), "____");
|
||||
}
|
||||
|
||||
function escape(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* The sentence a word is shown in — a generated example first, falling back to
|
||||
* where it was found.
|
||||
*
|
||||
* Same rule the review panel uses, and for the same reason: a word met only
|
||||
* ever in one sentence is learned attached to that sentence.
|
||||
*/
|
||||
function sentenceFor(word: SavedWord): string | undefined {
|
||||
const examples = word.examples ?? [];
|
||||
if (examples.length > 0) {
|
||||
const seen = typeof word.step === "number" && Number.isFinite(word.step) ? Math.max(0, Math.trunc(word.step)) : 0;
|
||||
return examples[seen % examples.length];
|
||||
}
|
||||
return word.context;
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
import { test, describe } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { VARIETY } from "../../variety/active.ts";
|
||||
import { check, checkAgainst } from "../../variety/check.ts";
|
||||
import { bridgeRules } from "../../variety/bridge.ts";
|
||||
import { allItems, articleItems, clozeItems, formItems, pairItems, recallItems } from "./generate.ts";
|
||||
import { buildSession, summarise } from "./session.ts";
|
||||
import { MIN_FORMS_TO_ASK, SESSION_SIZE } from "./types.ts";
|
||||
import type { SavedWord } from "../saved/types.ts";
|
||||
|
||||
/**
|
||||
* The properties that make practice safe to ship in a product that refuses to
|
||||
* let a model be the authority on dialect.
|
||||
*
|
||||
* The exercises are a rearrangement of material the pack already vouches for.
|
||||
* If any of these fail, something started inventing language at the one person
|
||||
* who cannot check it.
|
||||
*/
|
||||
|
||||
const NOW = new Date("2026-09-17T09:00:00Z");
|
||||
|
||||
function word(target: string, bridge: string, extra: Partial<SavedWord> = {}): SavedWord {
|
||||
return { target, bridge, savedAt: "2026-09-01T09:00:00Z", ...extra };
|
||||
}
|
||||
|
||||
describe("which one is Zurich", () => {
|
||||
test("every pair is built from a rule the checker enforces", () => {
|
||||
/**
|
||||
* The claim that makes this the only objectively markable item: the right
|
||||
* answer is not an opinion, it is what the gate would say. So the gate is
|
||||
* asked, for every single item.
|
||||
*/
|
||||
const items = pairItems(VARIETY);
|
||||
assert.ok(items.length >= 8, "expected pairs from both the dialect rules and the sibling's");
|
||||
// Both questions must be represented: "which is Zurich" and "which is Swiss".
|
||||
assert.ok(items.some((i) => i.variety === "target"));
|
||||
assert.ok(items.some((i) => i.variety === "bridge"));
|
||||
|
||||
for (const item of items) {
|
||||
const right = item.options[item.answer];
|
||||
const wrong = item.options[item.answer === 0 ? 1 : 0];
|
||||
|
||||
// Each pair is judged by the gate it belongs to. A bridge pair asks
|
||||
// "which is Swiss written German", and running it through the DIALECT
|
||||
// gate would be asking the wrong checker — which is precisely the
|
||||
// confusion the `variety` field exists to prevent.
|
||||
const verdict = (text: string) =>
|
||||
item.variety === "bridge" ? checkAgainst(text, bridgeRules(VARIETY)) : check(text, VARIETY);
|
||||
|
||||
assert.equal(verdict(right).ok, true, `"${right}" is marked correct but its gate flags it`);
|
||||
assert.equal(verdict(wrong).ok, false, `"${wrong}" is marked wrong but its gate accepts it`);
|
||||
}
|
||||
});
|
||||
|
||||
test("the two options are never the same word", () => {
|
||||
for (const item of pairItems(VARIETY)) {
|
||||
assert.notEqual(item.options[0].toLowerCase(), item.options[1].toLowerCase(), item.id);
|
||||
}
|
||||
});
|
||||
|
||||
test("the answer is not always on the same side", () => {
|
||||
// A learner who notices the answer is always on the left has stopped
|
||||
// reading the words, which is the failure mode of a generated drill.
|
||||
const sides = new Set(pairItems(VARIETY).map((i) => i.answer));
|
||||
assert.equal(sides.size, 2, "every correct answer landed on the same side");
|
||||
});
|
||||
|
||||
test("a pattern rule produces no item rather than showing a regex", () => {
|
||||
// `display` exists because a page once printed a lookahead assertion at a
|
||||
// learner. An exercise must not reintroduce that.
|
||||
for (const item of pairItems(VARIETY)) {
|
||||
for (const option of item.options) {
|
||||
assert.ok(!/[\\^$*+?()[\]{}|]/.test(option), `${item.id} shows regex syntax: ${option}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("grammar cloze", () => {
|
||||
test("the blank removes a word the German sentence does not have", () => {
|
||||
/**
|
||||
* The point of the item. Blanking a word that appears in both sentences
|
||||
* tests nothing the topic is about — the learner could read it off the
|
||||
* clue.
|
||||
*/
|
||||
const items = clozeItems(VARIETY);
|
||||
assert.ok(items.length >= 3, "expected cloze items from the grammar topics");
|
||||
|
||||
for (const item of items) {
|
||||
assert.ok(item.prompt.includes("____"), `${item.id} has no blank`);
|
||||
assert.ok(
|
||||
!item.bridge.toLowerCase().includes(item.answer.toLowerCase()),
|
||||
`${item.id} blanked "${item.answer}", which is visible in the clue`,
|
||||
);
|
||||
// And the answer must really be gone from what is shown.
|
||||
assert.ok(!item.prompt.includes(item.answer), `${item.id} still shows its answer`);
|
||||
}
|
||||
});
|
||||
|
||||
test("every cloze names the grammar topic it came from", () => {
|
||||
// So the page can link to the explanation, which is the whole reason the
|
||||
// reference section and practice belong to each other.
|
||||
const topics = new Set((VARIETY.grammar ?? []).map((t) => t.id));
|
||||
for (const item of clozeItems(VARIETY)) {
|
||||
assert.equal(item.source.kind, "grammar");
|
||||
if (item.source.kind === "grammar") {
|
||||
assert.ok(topics.has(item.source.topic), `${item.id} cites a topic that does not exist`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("it is self-marked, because there is no correct spelling to check against", () => {
|
||||
for (const item of clozeItems(VARIETY)) assert.equal(item.marking, "self");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the learner's own words", () => {
|
||||
test("a word with no meaning is not asked", () => {
|
||||
assert.deepEqual(recallItems([word("Chunnsch", " ")]), []);
|
||||
assert.deepEqual(recallItems([word(" ", "kommst du")]), []);
|
||||
});
|
||||
|
||||
test("it asks dialect first, which is the direction a message arrives in", () => {
|
||||
const [item] = recallItems([word("Chunnsch", "kommst du")]);
|
||||
assert.equal(item.prompt, "Chunnsch");
|
||||
assert.equal(item.answer, "kommst du");
|
||||
});
|
||||
});
|
||||
|
||||
describe("a sitting", () => {
|
||||
test("works on day one, with nothing saved", () => {
|
||||
// The empty-state failure this avoids: a practice page that tells a new
|
||||
// learner to come back once they have saved something.
|
||||
const session = buildSession({ pack: VARIETY, saved: [], now: NOW });
|
||||
assert.equal(session.length, SESSION_SIZE);
|
||||
assert.ok(session.every((item) => item.kind !== "recall"));
|
||||
});
|
||||
|
||||
test("a word that is NOT due is never asked", () => {
|
||||
/**
|
||||
* The schedule is the feature. Filling a session with a word due in three
|
||||
* weeks spends the spacing effect that `review.ts` exists to produce.
|
||||
*/
|
||||
const notDue = word("Chunnsch", "kommst du", { dueAt: "2026-10-30T09:00:00Z", step: 2 });
|
||||
const session = buildSession({ pack: VARIETY, saved: [notDue], now: NOW });
|
||||
assert.ok(!session.some((item) => item.id === "recall:chunnsch"));
|
||||
});
|
||||
|
||||
test("a due word leads the session", () => {
|
||||
const due = word("Chunnsch", "kommst du", { dueAt: "2026-09-01T09:00:00Z", step: 1 });
|
||||
const session = buildSession({ pack: VARIETY, saved: [due], now: NOW });
|
||||
assert.equal(session[0].id, "recall:chunnsch", "the only item with a deadline should come first");
|
||||
});
|
||||
|
||||
test("the same inputs give the same session", () => {
|
||||
// No shuffle anywhere: a random session cannot be tested or resumed.
|
||||
const a = buildSession({ pack: VARIETY, saved: [], now: NOW });
|
||||
const b = buildSession({ pack: VARIETY, saved: [], now: NOW });
|
||||
assert.deepEqual(a.map((i) => i.id), b.map((i) => i.id));
|
||||
});
|
||||
|
||||
test("what was asked last time is asked last this time", () => {
|
||||
const first = buildSession({ pack: VARIETY, saved: [], now: NOW });
|
||||
const second = buildSession({ pack: VARIETY, saved: [], now: NOW, seen: first.map((i) => i.id) });
|
||||
assert.notDeepEqual(
|
||||
second.map((i) => i.id),
|
||||
first.map((i) => i.id),
|
||||
"a second session repeated the first exactly",
|
||||
);
|
||||
});
|
||||
|
||||
test("two items of the same kind avoid sitting together where possible", () => {
|
||||
// Eight multiple-choice questions in a row is how a person stops reading
|
||||
// the options and starts pattern-matching the layout.
|
||||
const session = buildSession({ pack: VARIETY, saved: [], now: NOW });
|
||||
const kinds = session.map((i) => i.kind);
|
||||
const runs = kinds.filter((kind, i) => i > 0 && kind === kinds[i - 1]).length;
|
||||
assert.ok(runs <= 2, `too many same-kind neighbours: ${kinds.join(", ")}`);
|
||||
});
|
||||
|
||||
test("every item id is unique within a session", () => {
|
||||
const ids = buildSession({ pack: VARIETY, saved: [], now: NOW }).map((i) => i.id);
|
||||
assert.equal(new Set(ids).size, ids.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the summary invents nothing", () => {
|
||||
test("it counts, and derives no score", () => {
|
||||
const summary = summarise([
|
||||
{ id: "a", outcome: "right" },
|
||||
{ id: "b", outcome: "wrong" },
|
||||
{ id: "c", outcome: "skipped" },
|
||||
]);
|
||||
assert.deepEqual(summary, { asked: 3, right: 1, again: 1 });
|
||||
// No percentage, no streak, no level — §8 forbids measuring consumption
|
||||
// and dressing it as learning.
|
||||
assert.deepEqual(Object.keys(summary).sort(), ["again", "asked", "right"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("nothing is invented", () => {
|
||||
test("every item traces to the pack or to the learner's own words", () => {
|
||||
/**
|
||||
* Four provenances, and each one names something that exists: a variety
|
||||
* rule, a grammar topic, a word in the vocabulary, or a phrase the learner
|
||||
* saved themselves. `word` joined the list when articles and paradigms
|
||||
* did — it is the narrowest of the four, because it must resolve to an
|
||||
* entry, and an entry is the only place a gender or a form is ever
|
||||
* asserted.
|
||||
*
|
||||
* Checking the KIND alone would let a typo pass as provenance, so the
|
||||
* pointer is followed.
|
||||
*/
|
||||
const saved = [word("Chunnsch", "kommst du")];
|
||||
/**
|
||||
* Both directions, because half the pairs come from `bridgeRules` — the
|
||||
* mirrored set that catches the German word a learner reaches for. Those
|
||||
* rules are derived rather than written, so they are absent from
|
||||
* `pack.rules` and a check against that alone would call the better half of
|
||||
* the drill unsourced.
|
||||
*/
|
||||
const rules = new Set(
|
||||
[...VARIETY.rules, ...bridgeRules(VARIETY)]
|
||||
.map((r) => r.match)
|
||||
.filter((m): m is string => typeof m === "string")
|
||||
.map((m) => m.trim()),
|
||||
);
|
||||
const topics = new Set((VARIETY.grammar ?? []).map((t) => t.id));
|
||||
const words = new Set((VARIETY.vocabulary ?? []).map((w) => w.target));
|
||||
|
||||
for (const item of allItems(VARIETY, saved)) {
|
||||
const from = item.source;
|
||||
switch (from.kind) {
|
||||
case "rule":
|
||||
assert.ok(rules.has(from.rule), `${item.id} cites a rule the pack does not have`);
|
||||
break;
|
||||
case "grammar":
|
||||
assert.ok(topics.has(from.topic), `${item.id} cites a grammar topic the pack does not have`);
|
||||
break;
|
||||
case "word":
|
||||
assert.ok(words.has(from.word), `${item.id} cites a word the pack does not have`);
|
||||
break;
|
||||
case "saved":
|
||||
break;
|
||||
default:
|
||||
assert.fail(`${item.id} has no provenance`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("article and form items", () => {
|
||||
test("an article item offers all three, always", () => {
|
||||
// Offering only the plausible two would leak the answer.
|
||||
for (const item of articleItems(VARIETY)) {
|
||||
assert.deepEqual([...item.options], ["de", "d", "s"]);
|
||||
assert.equal(
|
||||
item.options[item.answer],
|
||||
VARIETY.vocabulary?.find((w) => w.target === item.noun)?.article,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("a noun with no declared article produces no item", () => {
|
||||
/**
|
||||
* The guarantee that matters more than any item this generates. The schema
|
||||
* keeps `article` optional so that "nobody has checked this" stays
|
||||
* expressible, and an exercise that quietly filled the gap would be the one
|
||||
* place in the product that invents language.
|
||||
*/
|
||||
const asked = new Set(articleItems(VARIETY).map((i) => i.noun));
|
||||
for (const entry of VARIETY.vocabulary ?? []) {
|
||||
if (!entry.article) {
|
||||
assert.ok(!asked.has(entry.target), `${entry.target} was asked about without a declared article`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("a form item's distractors are the verb's OWN forms", () => {
|
||||
// Nothing invented to distract with — which is what lets this be marked
|
||||
// objectively in a variety nobody here can adjudicate.
|
||||
for (const item of formItems(VARIETY)) {
|
||||
const entry = VARIETY.vocabulary?.find((w) => w.target === item.word);
|
||||
const real = new Set((entry?.forms ?? []).map((f) => f.target));
|
||||
for (const option of item.options) {
|
||||
assert.ok(real.has(option), `${item.id} offers "${option}", which is not a form of ${item.word}`);
|
||||
}
|
||||
assert.equal(
|
||||
item.options[item.answer],
|
||||
entry?.forms?.find((f) => f.label === item.label)?.target,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("a thin paradigm is not asked about at all", () => {
|
||||
for (const entry of VARIETY.vocabulary ?? []) {
|
||||
if ((entry.forms ?? []).length >= MIN_FORMS_TO_ASK) continue;
|
||||
assert.ok(
|
||||
!formItems(VARIETY).some((i) => i.word === entry.target),
|
||||
`${entry.target} has fewer than ${MIN_FORMS_TO_ASK} forms but is asked about`,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,152 @@
|
||||
import type { VarietyPack } from "../../variety/pack.ts";
|
||||
import type { SavedWord } from "../saved/types.ts";
|
||||
import { due } from "../saved/review.ts";
|
||||
import { allItems } from "./generate.ts";
|
||||
import { SESSION_SIZE, type PracticeItem } from "./types.ts";
|
||||
|
||||
/**
|
||||
* What one sitting asks, and in what order.
|
||||
*
|
||||
* THE LEARNER'S OWN WORDS COME FIRST, AND ONLY WHEN THEY ARE DUE.
|
||||
*
|
||||
* A word is due on the schedule in `review.ts`, and practice must not override
|
||||
* it: asking a word early because the session needed filling would spend the
|
||||
* spacing effect the whole schedule exists to produce, and asking it late is
|
||||
* what the schedule is for. So due words are taken in order, and the pack's
|
||||
* items fill whatever is left.
|
||||
*
|
||||
* That ordering is also the honest one for a new learner. Someone who has kept
|
||||
* nothing yet gets a session entirely of pack items — real, checkable, and
|
||||
* available on day one — rather than an empty screen telling them to come back
|
||||
* when they have saved something.
|
||||
*
|
||||
* NO SHUFFLE, AND NO RANDOMNESS ANYWHERE.
|
||||
*
|
||||
* A random session cannot be tested, cannot be resumed, and gives a learner no
|
||||
* way to tell "I have seen this" from "this came up again". The variation
|
||||
* comes from `seen` — what has already been asked — which is a fact about the
|
||||
* learner rather than a dice roll, so the same person gets a different session
|
||||
* tomorrow and a test gets the same one twice.
|
||||
*/
|
||||
export function buildSession({
|
||||
pack,
|
||||
saved,
|
||||
now,
|
||||
seen = [],
|
||||
size = SESSION_SIZE,
|
||||
}: {
|
||||
pack: VarietyPack;
|
||||
saved: readonly SavedWord[];
|
||||
/** Passed in, never read from the clock here — so tests are not tests of today. */
|
||||
now: Date;
|
||||
/** Item ids already asked, most recent last. */
|
||||
seen?: readonly string[];
|
||||
size?: number;
|
||||
}): PracticeItem[] {
|
||||
const dueIds = new Set(due([...saved], now).map((word) => `recall:${word.target.trim().toLocaleLowerCase()}`));
|
||||
const everything = allItems(pack, saved);
|
||||
|
||||
const isDueRecall = (item: PracticeItem) => item.kind === "recall" && dueIds.has(item.id);
|
||||
|
||||
// A word that is NOT due is not asked at all. It is not filler: showing it
|
||||
// early is the one thing the schedule is there to prevent.
|
||||
const candidates = everything.filter((item) => item.kind !== "recall" || isDueRecall(item));
|
||||
|
||||
const seenAt = new Map(seen.map((id, i) => [id, i]));
|
||||
const freshness = (item: PracticeItem) => (seenAt.has(item.id) ? seenAt.get(item.id)! : -1);
|
||||
|
||||
const rank = (a: PracticeItem, b: PracticeItem) => {
|
||||
// Whatever has been asked least recently. Never-seen items (-1) come before
|
||||
// anything seen, oldest-seen before newest.
|
||||
const freshGap = freshness(a) - freshness(b);
|
||||
if (freshGap !== 0) return freshGap;
|
||||
// A stable tiebreak so the same inputs give the same session.
|
||||
return a.id.localeCompare(b.id);
|
||||
};
|
||||
|
||||
/**
|
||||
* PICK A MIX, THEN ORDER IT — not the other way round.
|
||||
*
|
||||
* Sorting everything and taking the first eight was the obvious version and
|
||||
* it produced eight cloze items in a row: the tiebreak is alphabetical, and
|
||||
* "cloze" sorts before "pair". Interleaving afterwards could not fix it,
|
||||
* because by then the eight were all one kind. Selection has to be the thing
|
||||
* that balances.
|
||||
*/
|
||||
const dueRecalls = candidates.filter(isDueRecall).sort(rank);
|
||||
const buckets = new Map<string, PracticeItem[]>();
|
||||
for (const item of candidates.filter((i) => !isDueRecall(i))) {
|
||||
const bucket = buckets.get(item.kind) ?? [];
|
||||
bucket.push(item);
|
||||
buckets.set(item.kind, bucket);
|
||||
}
|
||||
for (const bucket of buckets.values()) bucket.sort(rank);
|
||||
|
||||
// Due words lead: they are the only items with a deadline.
|
||||
const picked: PracticeItem[] = dueRecalls.slice(0, size);
|
||||
|
||||
// Then round-robin across the remaining kinds, in a fixed order so the
|
||||
// session stays reproducible.
|
||||
const kinds = [...buckets.keys()].sort();
|
||||
let exhausted = false;
|
||||
while (picked.length < size && !exhausted) {
|
||||
exhausted = true;
|
||||
for (const kind of kinds) {
|
||||
if (picked.length >= size) break;
|
||||
const next = buckets.get(kind)?.shift();
|
||||
if (next) {
|
||||
picked.push(next);
|
||||
exhausted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return interleave(picked);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep two items of the same kind from sitting next to each other where that
|
||||
* can be avoided.
|
||||
*
|
||||
* Not decoration. Eight multiple-choice questions in a row is the shape that
|
||||
* makes a person stop reading the options and start pattern-matching the
|
||||
* layout — and the variety is the part of "enjoyable" this module can actually
|
||||
* deliver without inventing a score.
|
||||
*
|
||||
* Best-effort by construction: when the session is all one kind there is
|
||||
* nothing to interleave, and it returns the order it was given rather than
|
||||
* pretending otherwise.
|
||||
*/
|
||||
function interleave(items: PracticeItem[]): PracticeItem[] {
|
||||
const out: PracticeItem[] = [];
|
||||
const rest = [...items];
|
||||
|
||||
while (rest.length > 0) {
|
||||
const previous = out[out.length - 1];
|
||||
const next = rest.findIndex((item) => item.kind !== previous?.kind);
|
||||
out.push(...rest.splice(next === -1 ? 0 : next, 1));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to say at the end, without inventing a score.
|
||||
*
|
||||
* Counts of what happened, which are true, and nothing derived from them. No
|
||||
* percentage, because eight items cannot support one; no streak, because §8
|
||||
* forbids measuring consumption; no "level", because the product's own metric
|
||||
* is how much of an unfamiliar speaker you understand and this is not that.
|
||||
*/
|
||||
export function summarise(outcomes: readonly { id: string; outcome: string }[]): {
|
||||
asked: number;
|
||||
right: number;
|
||||
/** Items the learner asked to see again — a choice, not a failure. */
|
||||
again: number;
|
||||
} {
|
||||
return {
|
||||
asked: outcomes.length,
|
||||
right: outcomes.filter((o) => o.outcome === "right").length,
|
||||
again: outcomes.filter((o) => o.outcome === "wrong").length,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* Practice — the part where the learner is asked rather than shown.
|
||||
*
|
||||
* WHY THIS IS NOT A GAME, AND WHY IT IS STILL MEANT TO BE ENJOYABLE.
|
||||
*
|
||||
* `review.ts` already refuses streaks, points and days-active, and it is right
|
||||
* to: §8's rule is that the product measures how much of an unfamiliar Zurich
|
||||
* speaker you understand, and a streak measures how much Heidi you consumed
|
||||
* while looking like it measures learning. Nothing here adds a score.
|
||||
*
|
||||
* But "not gamified" was never the same claim as "not enjoyable". What makes
|
||||
* this worth opening is meant to come from the design rather than from points:
|
||||
* sessions short enough to finish, items that vary so the next one is not the
|
||||
* last one again, material that is the learner's OWN — words they kept from
|
||||
* their own messages — and an answer that arrives immediately. Those are the
|
||||
* things the evidence in `review.ts` already supports; a leaderboard is not.
|
||||
*
|
||||
* THE TWO KINDS OF MARKING, AND WHY THE SPLIT IS PRINCIPLED.
|
||||
*
|
||||
* `objective` — the item has a right answer that this product can prove. Only
|
||||
* one kind qualifies: choosing between a Zurich form and a form from another
|
||||
* dialect, because the deterministic gate already defines which is which and
|
||||
* the rule that generated the item is the same rule the checker enforces. No
|
||||
* model is asked, so no model can be wrong.
|
||||
*
|
||||
* `self` — the learner says whether they knew it. Everything involving
|
||||
* spelling or production is marked this way, and that is not laziness. Zurich
|
||||
* German has no standard orthography (§6), so marking a typed answer means
|
||||
* deciding whether a near-miss counts — and getting that wrong tells a
|
||||
* learner they were wrong when they were not, in a variety where nobody can
|
||||
* tell them otherwise. `ReviewPanel` already made this argument for words;
|
||||
* it holds identically for a grammar form.
|
||||
*
|
||||
* Anything that would need a model to mark it is simply not an exercise type.
|
||||
*/
|
||||
|
||||
/** Where an item came from, so a wrong one can be traced to its source. */
|
||||
export type ItemSource =
|
||||
/** A rule in the variety pack — the same list the gate enforces. */
|
||||
| { kind: "rule"; rule: string }
|
||||
/** A grammar topic in the pack. Carries the id so the page can link to it. */
|
||||
| { kind: "grammar"; topic: string }
|
||||
/** A word the learner kept themselves. */
|
||||
| { kind: "saved" }
|
||||
/** A vocabulary entry in the pack, with the source that vouches for it. */
|
||||
| { kind: "word"; word: string };
|
||||
|
||||
/**
|
||||
* Which one is the Zurich form?
|
||||
*
|
||||
* The flagship item, and the only objective one. Generated from a pack rule
|
||||
* that names both a foreign form and the Zurich form it should have been —
|
||||
* `nid` → `nöd`, `güet` → `guet` — so the answer is defined by the checker
|
||||
* rather than by anybody's opinion.
|
||||
*
|
||||
* It also happens to train the exact discrimination the product exists for: a
|
||||
* learner who cannot tell Bernese from Zurich German is the person §2
|
||||
* describes, and this is the only exercise that measures it directly.
|
||||
*/
|
||||
export type PairItem = {
|
||||
id: string;
|
||||
kind: "pair";
|
||||
marking: "objective";
|
||||
/**
|
||||
* WHICH question this pair asks, because they are two different questions
|
||||
* and conflating them would teach something false.
|
||||
*
|
||||
* `target` — which of these is ZURICH German, the other being Bernese or
|
||||
* Basel. Judged by the dialect gate.
|
||||
* `bridge` — which of these is SWISS written German, the other being
|
||||
* Germany's. Judged by the sibling's rules.
|
||||
*
|
||||
* `Velo` is not Zurich German as opposed to Swiss German; it is the Swiss
|
||||
* word, used in both. Labelling it `target` would tell a learner it belongs
|
||||
* to the dialect, which is exactly the kind of quiet falsehood this product
|
||||
* refuses elsewhere.
|
||||
*/
|
||||
variety: "target" | "bridge";
|
||||
/** Both forms, in a fixed order decided at generation. */
|
||||
options: readonly [string, string];
|
||||
/** Index into `options`. */
|
||||
answer: 0 | 1;
|
||||
/** Where the wrong one is from — "Bern", "Basel" — when the rule says. */
|
||||
origin?: string;
|
||||
source: ItemSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* A kept word, asked in the direction the learner will meet it.
|
||||
*
|
||||
* Dialect form first, meaning revealed second — recognition before production,
|
||||
* which is the order §1 argues and the direction a message actually arrives in.
|
||||
*/
|
||||
export type RecallItem = {
|
||||
id: string;
|
||||
kind: "recall";
|
||||
marking: "self";
|
||||
prompt: string;
|
||||
answer: string;
|
||||
/** A sentence it was seen in, when there is one. */
|
||||
context?: string;
|
||||
source: ItemSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* One word missing from a sentence, with the German beside it.
|
||||
*
|
||||
* Self-marked, for the orthography reason above: there is no correct spelling
|
||||
* to check a typed answer against.
|
||||
*/
|
||||
export type ClozeItem = {
|
||||
id: string;
|
||||
kind: "cloze";
|
||||
marking: "self";
|
||||
/** The target sentence with the blank already cut into it. */
|
||||
prompt: string;
|
||||
/** The word that was removed. */
|
||||
answer: string;
|
||||
/** The same sentence in the bridge variety — the clue, not the answer. */
|
||||
bridge: string;
|
||||
source: ItemSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Which article the noun takes.
|
||||
*
|
||||
* OBJECTIVE, and the second kind that can be: the answer set is closed at three
|
||||
* and the answer itself is a field in the pack, so nothing is inferred and no
|
||||
* model is asked. It is also the error a German reader is least able to avoid —
|
||||
* gender is carried by a word they never had to learn, so *der Velo* survives a
|
||||
* hundred correct readings of the noun.
|
||||
*
|
||||
* All three articles are always offered, in a fixed order. Offering only the
|
||||
* plausible two would leak the answer, and shuffling would make the session
|
||||
* irreproducible for no gain.
|
||||
*/
|
||||
export type ArticleItem = {
|
||||
id: string;
|
||||
kind: "article";
|
||||
marking: "objective";
|
||||
/** The noun, bare. */
|
||||
noun: string;
|
||||
bridge: string;
|
||||
/** Always all three, same order every time. */
|
||||
options: readonly [string, string, string];
|
||||
/** Index into `options`. */
|
||||
answer: 0 | 1 | 2;
|
||||
source: ItemSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* Which form of the verb goes with this person.
|
||||
*
|
||||
* OBJECTIVE, and the distractors are what make it so: they are the SAME verb's
|
||||
* other forms, taken from the pack. A learner choosing between `bi`, `bisch`
|
||||
* and `isch` is doing the thing a paradigm is for — nothing is invented to
|
||||
* distract them, and no plausible-looking wrong form had to be made up, which
|
||||
* is where a generated drill would otherwise start writing the language.
|
||||
*
|
||||
* Needs at least three forms on the entry. Two would be a coin toss and one is
|
||||
* not a question, so a thinner entry produces no item.
|
||||
*/
|
||||
export type FormItem = {
|
||||
id: string;
|
||||
kind: "form";
|
||||
marking: "objective";
|
||||
/** The headword, so the learner knows which verb is being asked about. */
|
||||
word: string;
|
||||
bridge: string;
|
||||
/** Which person is wanted — a closed key the dictionary renders. */
|
||||
label: string;
|
||||
/** The verb's own forms, in pack order. */
|
||||
options: readonly string[];
|
||||
answer: number;
|
||||
source: ItemSource;
|
||||
};
|
||||
|
||||
export type PracticeItem = PairItem | RecallItem | ClozeItem | ArticleItem | FormItem;
|
||||
|
||||
/**
|
||||
* The three articles, in the order they are always shown.
|
||||
*
|
||||
* Mirrors `Article` in the pack rather than redefining it — the pack is the
|
||||
* authority on what articles the variety has, and a second list here would be
|
||||
* the copy that goes stale. A test asserts the two agree.
|
||||
*/
|
||||
export const ARTICLES = ["de", "d", "s"] as const;
|
||||
|
||||
/**
|
||||
* How many forms an entry needs before its paradigm is worth asking about.
|
||||
*
|
||||
* Three: two options is a coin toss, and the distractors have to be the verb's
|
||||
* own forms rather than invented ones.
|
||||
*/
|
||||
export const MIN_FORMS_TO_ASK = 3;
|
||||
|
||||
/** How an answer came back. `skipped` is a real outcome, not a failure. */
|
||||
export type Outcome = "right" | "wrong" | "skipped";
|
||||
|
||||
/**
|
||||
* How many items one sitting holds.
|
||||
*
|
||||
* Small on purpose. A session you can finish in a tram stop is one you open
|
||||
* again tomorrow; twenty items is a lesson, and a lesson is the thing people
|
||||
* mean to do later. There is no setting for it — an option here would be the
|
||||
* product asking the learner to design their own practice.
|
||||
*/
|
||||
export const SESSION_SIZE = 8;
|
||||
+20
-1
@@ -104,7 +104,22 @@ export type DisplayVariety = {
|
||||
* key — all three survive the projection because none is English prose; the
|
||||
* group's LABEL is translated and lives in the dictionaries.
|
||||
*/
|
||||
vocabulary: readonly { target: string; bridge: string; group: string }[];
|
||||
vocabulary: readonly {
|
||||
target: string;
|
||||
bridge: string;
|
||||
group: string;
|
||||
/**
|
||||
* The article, the forms and an example all project for the same reason
|
||||
* the rest does: they are the variety's own words and a closed-set key,
|
||||
* never English prose. `FormLabel` is a key the dictionaries translate,
|
||||
* which is exactly why it was made closed rather than a free string.
|
||||
*/
|
||||
article?: string;
|
||||
forms?: readonly { label: string; target: string; bridge: string }[];
|
||||
example?: { target: string; bridge: string };
|
||||
/** An id into `lib/research/sources.ts`, so a page can cite per word. */
|
||||
source?: string;
|
||||
}[];
|
||||
/** Ids into `lib/research/sources.ts` — keys, not prose, so they project. */
|
||||
vocabularySources: readonly string[];
|
||||
/** `note` is deliberately absent — it is a paragraph of English. */
|
||||
@@ -167,6 +182,10 @@ export const DISPLAY: DisplayVariety = {
|
||||
target: w.target,
|
||||
bridge: w.bridge,
|
||||
group: w.group,
|
||||
...(w.article ? { article: w.article } : {}),
|
||||
...(w.forms?.length ? { forms: w.forms.map((f) => ({ label: f.label, target: f.target, bridge: f.bridge })) } : {}),
|
||||
...(w.example ? { example: { target: w.example.target, bridge: w.example.bridge } } : {}),
|
||||
...(w.source ? { source: w.source } : {}),
|
||||
})),
|
||||
vocabularySources: VARIETY.vocabularySources ?? [],
|
||||
areas: areasOf(VARIETY).map((area) => ({
|
||||
|
||||
@@ -174,12 +174,84 @@ export type GrammarTopic = {
|
||||
*/
|
||||
export type VocabularyGroup = "function" | "verbs" | "everyday" | "greetings";
|
||||
|
||||
/**
|
||||
* The article a learner would actually SAY, as a closed set.
|
||||
*
|
||||
* Zurich German has three, and they are not the German three: `de Maa`,
|
||||
* `d Frau`, `s Chind`. A learner who has read the noun a hundred times in
|
||||
* German still says *der Velo* the first time, because gender is carried by a
|
||||
* word they never had to learn.
|
||||
*
|
||||
* Closed rather than a free string, and that is the point: `"der"` in this
|
||||
* field would be a German article presented as a Zurich one, which is exactly
|
||||
* the invisible error §2 describes. A test refuses anything outside the three.
|
||||
*
|
||||
* A pack for another variety declares its own — this type is the shape, not
|
||||
* the content, and Ukrainian will not have three of anything.
|
||||
*/
|
||||
export type Article = "de" | "d" | "s";
|
||||
|
||||
/**
|
||||
* Which form of a word this is.
|
||||
*
|
||||
* A CLOSED VOCABULARY for the same reason the follow-up moves are: the label
|
||||
* is rendered in seven languages, so it has to be a key the dictionary can
|
||||
* translate rather than a string somebody typed. "du-Form" in a Russian
|
||||
* interface is not a translation, it is German leaking.
|
||||
*
|
||||
* Person labels use the pronoun a paradigm is usually printed with. `plural`
|
||||
* is for nouns; `past` is the participle, which in this variety is the only
|
||||
* past there is — §9's `no-preterite` topic is about precisely that.
|
||||
*/
|
||||
export type FormLabel = "ich" | "du" | "er" | "mir" | "ihr" | "si" | "plural" | "past";
|
||||
|
||||
export type WordForm = {
|
||||
label: FormLabel;
|
||||
/** The form in the taught variety. */
|
||||
target: string;
|
||||
/** The same form in the bridge language, so the contrast is visible. */
|
||||
bridge: string;
|
||||
};
|
||||
|
||||
export type VocabularyEntry = {
|
||||
/** The form in the taught variety. */
|
||||
target: string;
|
||||
/** What a reader of the bridge language recognises. */
|
||||
bridge: string;
|
||||
group: VocabularyGroup;
|
||||
/**
|
||||
* The article, for a noun. Absent for everything else, and absent for a noun
|
||||
* whose gender nobody here has checked — an absent article is honest, and a
|
||||
* guessed one is a confident falsehood aimed at somebody who cannot detect it.
|
||||
*/
|
||||
article?: Article;
|
||||
/**
|
||||
* The forms worth knowing, for a word whose forms are the difficulty.
|
||||
*
|
||||
* Not a full paradigm for its own sake. `si` and `ha` earn one because they
|
||||
* carry every compound past in the language; a noun earns a plural when the
|
||||
* plural is not what a German reader would produce.
|
||||
*/
|
||||
forms?: readonly WordForm[];
|
||||
/**
|
||||
* One sentence the word lives in.
|
||||
*
|
||||
* WRITTEN FOR THIS PRODUCT, never lifted from a dictionary or a corpus. The
|
||||
* open resources for this variety are overwhelmingly research-licensed or
|
||||
* non-commercial, so copying an example sentence would be a licence problem
|
||||
* wearing the costume of a teaching aid — and the repo would have no way to
|
||||
* tell later which sentences were safe.
|
||||
*/
|
||||
example?: { target: string; bridge: string };
|
||||
/**
|
||||
* Who vouches for the detail above.
|
||||
*
|
||||
* Required by a test for any entry carrying an `article`, `forms` or an
|
||||
* `example`: those are claims about the language, and this repo does not
|
||||
* publish a claim about the language that names nobody. A bare
|
||||
* target/bridge pair inherits the pack's `vocabularySources` as before.
|
||||
*/
|
||||
source?: string;
|
||||
};
|
||||
|
||||
/** How confident we are that a flagged form is actually wrong. */
|
||||
|
||||
+119
-1
@@ -305,6 +305,48 @@ export const ZURICH_GERMAN: VarietyPack = {
|
||||
* Sourced to the Idiotikon, the sixteen-volume reference dictionary of Swiss
|
||||
* German, which is what a word-level claim needs and a dialect atlas is not.
|
||||
*/
|
||||
/**
|
||||
* WHERE THE DETAIL ON A WORD MAY COME FROM, AND WHERE IT MAY NOT.
|
||||
*
|
||||
* Checked against the actual licences on 2026-09-17, because "it is online
|
||||
* and free to read" and "we may ship it" are different claims and the gap
|
||||
* between them is where an open-source language product gets itself sued.
|
||||
*
|
||||
* MAY BE CITED AS EVIDENCE, NEVER COPIED FROM:
|
||||
* Sprachatlas der deutschen Schweiz (sprachatlas.ch) — CC BY-SA 4.0, with
|
||||
* a live API. It is the citable authority for the ARTICLE SYSTEM: map
|
||||
* 3869 gives `də` at 66 of 66 Zurich survey points for the masculine
|
||||
* nominative, map 3866 gives `s` at 66 of 66 for the neuter. Worth
|
||||
* knowing before anyone calls this settled: map 3870, the feminine
|
||||
* dative, is SPLIT inside the canton — 57 points `dr` against 48 `də`.
|
||||
* Zurich German is not one system even in Zurich.
|
||||
* Schweizerisches Idiotikon — the reference dictionary, and the authority
|
||||
* for whether a word and a gender are Zurich-attested at all. Careful:
|
||||
* its CC BY-SA 4.0 covers the REST API, which returns headwords and
|
||||
* definitions ONLY. The scans and OCR — which is where the gender
|
||||
* markings and the example sentences actually live — publish no licence
|
||||
* whatsoever.
|
||||
*
|
||||
* MUST NOT BE USED AS A SOURCE OF TEXT:
|
||||
* ArchiMob — non-commercial under all three of its published statements,
|
||||
* and NoDerivatives under the Zenodo one. Consult it; do not lift.
|
||||
* SwissCrawl, the Swiss SMS Corpus — non-commercial.
|
||||
* NOAH's Corpus — the annotations are CC BY 4.0, the sentences are
|
||||
* third-party text under no licence at all.
|
||||
* Weber, `Zürichdeutsche Grammatik` (1948) — in copyright until 31 Dec
|
||||
* 2027. Weber, `Die Mundart des Zürcher Oberlandes` (1923) is readable
|
||||
* on e-Helvetica but PRIVATE USE ONLY. Weber & Bächtold's dictionary
|
||||
* runs to 2054.
|
||||
*
|
||||
* SO: EVERY EXAMPLE SENTENCE IN THIS FILE IS WRITTEN HERE, and every entry
|
||||
* below goes further than that — it reuses a sentence this pack ALREADY
|
||||
* publishes in its own grammar topics. Not one string in the additions below
|
||||
* is a new claim about the language; they are forms this file already
|
||||
* asserts, promoted into the vocabulary where a learner can find them.
|
||||
*
|
||||
* The one thing still outstanding is the one §9 already names: none of it
|
||||
* has been reviewed by a native Zurich speaker.
|
||||
*/
|
||||
vocabulary: [
|
||||
// The short words. Individually tiny, collectively most of why a sentence
|
||||
// is unfollowable.
|
||||
@@ -326,7 +368,35 @@ export const ZURICH_GERMAN: VarietyPack = {
|
||||
{ target: "ächli", bridge: "ein bisschen", group: "function" },
|
||||
|
||||
{ target: "si", bridge: "sein", group: "verbs" },
|
||||
{ target: "ha", bridge: "haben", group: "verbs" },
|
||||
{
|
||||
/**
|
||||
* The only paradigm this pack can already fill from its own pages.
|
||||
*
|
||||
* `häsch`, `hät` and `händ` all appear in sentences this file or its
|
||||
* dictionaries already publish — "Häsch du am Samschtig scho öppis vor?",
|
||||
* "Si hät nüüt gseit", "Mir händ das scho gmacht". So the table is a
|
||||
* reorganisation, not an assertion.
|
||||
*
|
||||
* The first person is deliberately absent. `ha` is the headword here and
|
||||
* a row identical to its own headword teaches nothing — which is exactly
|
||||
* what the vocabulary test refuses. Filling it would need a source, and
|
||||
* the sources that could settle it are the ones listed above as
|
||||
* unusable.
|
||||
*
|
||||
* It matters more than any other verb because it carries every compound
|
||||
* past in the language: `no-preterite` is the pack's biggest grammar
|
||||
* topic and this is the auxiliary it runs on.
|
||||
*/
|
||||
target: "ha",
|
||||
bridge: "haben",
|
||||
group: "verbs",
|
||||
forms: [
|
||||
{ label: "du", target: "häsch", bridge: "hast" },
|
||||
{ label: "er", target: "hät", bridge: "hat" },
|
||||
{ label: "mir", target: "händ", bridge: "haben" },
|
||||
],
|
||||
source: "idiotikon",
|
||||
},
|
||||
{ target: "gah", bridge: "gehen", group: "verbs" },
|
||||
{ target: "cho", bridge: "kommen", group: "verbs" },
|
||||
{ target: "mache", bridge: "machen", group: "verbs" },
|
||||
@@ -340,6 +410,54 @@ export const ZURICH_GERMAN: VarietyPack = {
|
||||
{ target: "schaffe", bridge: "arbeiten", group: "verbs" },
|
||||
{ target: "poschte", bridge: "einkaufen", group: "verbs" },
|
||||
|
||||
/**
|
||||
* Three nouns, one per gender, and every string here already appears in
|
||||
* this file's own grammar examples — `De Maa, wo dört staht`,
|
||||
* `D Frau, wo ich gsee ha`, `S Dach vom Huus`. Promoting them into the
|
||||
* vocabulary adds no claim; it makes a claim the pack already makes
|
||||
* findable, and gives the article a place to live.
|
||||
*
|
||||
* They also make the article drill possible at all. Every noun the list
|
||||
* had was neuter — `s Velo`, `s Znüni`, `s Güetzi`, `s Rüebli` — because
|
||||
* four of them are `-li` diminutives, which this pack already teaches take
|
||||
* the neuter. An exercise whose answer is `s` every time is not an
|
||||
* exercise.
|
||||
*/
|
||||
{
|
||||
target: "Maa",
|
||||
bridge: "Mann",
|
||||
group: "everyday",
|
||||
article: "de",
|
||||
example: { target: "De Maa, wo dört staht.", bridge: "Der Mann, der dort steht." },
|
||||
source: "sds-atlas",
|
||||
},
|
||||
{
|
||||
/**
|
||||
* `Frau` would have been the obvious feminine, and the vocabulary test
|
||||
* refuses it: the word is identical in both varieties, and a row whose
|
||||
* two halves are the same string teaches nothing. Correct — the article
|
||||
* is the whole difference there, and this list is not where that is
|
||||
* taught.
|
||||
*
|
||||
* `Schwöschter` carries both: it differs from the German word AND it is
|
||||
* feminine. The pack's own `D Frau, wo ich gsee ha.` is what attests the
|
||||
* feminine article; this entry is what makes it learnable.
|
||||
*/
|
||||
target: "Schwöschter",
|
||||
bridge: "Schwester",
|
||||
group: "everyday",
|
||||
article: "d",
|
||||
example: { target: "De Anna ihri Schwöschter.", bridge: "Annas Schwester." },
|
||||
source: "sds-atlas",
|
||||
},
|
||||
{
|
||||
target: "Huus",
|
||||
bridge: "Haus",
|
||||
group: "everyday",
|
||||
article: "s",
|
||||
example: { target: "S Dach vom Huus.", bridge: "Das Dach des Hauses." },
|
||||
source: "sds-atlas",
|
||||
},
|
||||
{ target: "Velo", bridge: "Fahrrad", group: "everyday" },
|
||||
{ target: "Znüni", bridge: "Vormittagssnack", group: "everyday" },
|
||||
{ target: "Zvieri", bridge: "Nachmittagssnack", group: "everyday" },
|
||||
|
||||
@@ -91,9 +91,31 @@ describe("the vocabulary", () => {
|
||||
});
|
||||
|
||||
test("the projection carries the words and no English prose", () => {
|
||||
/**
|
||||
* The guarantee is unchanged — nothing English-prose-shaped may reach a
|
||||
* page through the projection — but the field list grew, so the check is
|
||||
* now an ALLOWLIST rather than an exact set. Every name on it is either
|
||||
* the variety's own words (`target`, `example.target`), the bridge
|
||||
* language's (`bridge`), or a closed key a dictionary renders (`group`,
|
||||
* `article`, a form's `label`, a `source` id).
|
||||
*
|
||||
* An exact-set assertion would have had to be relaxed every time a field
|
||||
* was added, which is how a guard quietly becomes a formality. A named
|
||||
* allowlist still fails on a field nobody thought about.
|
||||
*/
|
||||
const ALLOWED = ["article", "bridge", "example", "forms", "group", "source", "target"];
|
||||
assert.equal(DISPLAY.vocabulary.length, words.length);
|
||||
|
||||
for (const word of DISPLAY.vocabulary) {
|
||||
assert.deepEqual(Object.keys(word).sort(), ["bridge", "group", "target"]);
|
||||
for (const key of Object.keys(word)) {
|
||||
assert.ok(ALLOWED.includes(key), `the projection carries an unexpected field: ${key}`);
|
||||
}
|
||||
for (const form of word.forms ?? []) {
|
||||
assert.deepEqual(Object.keys(form).sort(), ["bridge", "label", "target"]);
|
||||
}
|
||||
if (word.example) {
|
||||
assert.deepEqual(Object.keys(word.example).sort(), ["bridge", "target"]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -104,3 +126,93 @@ describe("the vocabulary", () => {
|
||||
assert.ok(PACK.vocabularySources?.includes("idiotikon"), "the vocabulary must cite the Idiotikon");
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* The detail a word can carry beyond its gloss — and the rules that keep it
|
||||
* from becoming the place where this product starts inventing language.
|
||||
*
|
||||
* An article, a paradigm and an example sentence are all CLAIMS ABOUT THE
|
||||
* LANGUAGE, which is a different kind of statement from a target/bridge pair
|
||||
* and needs its own guarantees. §6's whole argument is that the learner cannot
|
||||
* audit any of them: somebody told that *Velo* is masculine has no way to find
|
||||
* out otherwise, and will say it wrong for a year.
|
||||
*/
|
||||
describe("what a word says beyond its meaning", () => {
|
||||
const words = PACK.vocabulary ?? [];
|
||||
|
||||
test("an article is one of the variety's three, never a German one", () => {
|
||||
// `der` here would be a German article presented as a Zurich one — the
|
||||
// invisible error the whole product is built around.
|
||||
for (const word of words) {
|
||||
if (!word.article) continue;
|
||||
assert.ok(
|
||||
["de", "d", "s"].includes(word.article),
|
||||
`${word.target} claims the article "${word.article}", which this variety does not have`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("every claim about the language names who vouches for it", () => {
|
||||
/**
|
||||
* The rule that makes it safe to add more. A bare target/bridge pair
|
||||
* inherits the pack's `vocabularySources`; an article, a paradigm or an
|
||||
* example is a further assertion, and this repo does not publish an
|
||||
* assertion about the language that names nobody.
|
||||
*/
|
||||
for (const word of words) {
|
||||
const claims = Boolean(word.article || word.forms?.length || word.example);
|
||||
if (!claims) continue;
|
||||
assert.ok(
|
||||
word.source && word.source.trim().length > 0,
|
||||
`${word.target} carries an article, forms or an example and cites no source`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("an example sentence passes the variety gate", () => {
|
||||
// It is generated dialect reaching a learner, so it faces the same checker
|
||||
// every generated line faces. An example carrying a Bernese form would
|
||||
// teach the exact thing the gate exists to prevent, from the reference
|
||||
// page rather than from a model.
|
||||
for (const word of words) {
|
||||
if (!word.example) continue;
|
||||
const verdict = check(word.example.target, PACK);
|
||||
assert.equal(verdict.ok, true, `${word.target}'s example is flagged: ${verdict.findings.map((f) => f.form).join(", ")}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("an example actually contains the word it illustrates", () => {
|
||||
// An example that does not use the word is a sentence, not an example —
|
||||
// and this is the kind of thing that survives review because it reads well.
|
||||
for (const word of words) {
|
||||
if (!word.example) continue;
|
||||
assert.match(
|
||||
word.example.target.toLowerCase(),
|
||||
new RegExp(word.target.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")),
|
||||
`${word.target}'s example does not contain it`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("a form is not the same string as the headword", () => {
|
||||
// A paradigm row identical to the lemma teaches nothing and usually means
|
||||
// the row was filled in to make the table look complete.
|
||||
for (const word of words) {
|
||||
for (const form of word.forms ?? []) {
|
||||
assert.notEqual(
|
||||
form.target.toLowerCase(),
|
||||
word.target.toLowerCase(),
|
||||
`${word.target} lists a form identical to itself (${form.label})`,
|
||||
);
|
||||
assert.ok(form.bridge.trim().length > 0, `${word.target}'s ${form.label} has no bridge form`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("no word claims the same form label twice", () => {
|
||||
for (const word of words) {
|
||||
const labels = (word.forms ?? []).map((f) => f.label);
|
||||
assert.equal(new Set(labels).size, labels.length, `${word.target} repeats a form label`);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user