Add much more practice content to every section
Hoeren 28 exercises, Lesen 22 texts, Schreiben 24 tasks, Sprechen 20 topics + 8 planning tasks + 10 presentations, Grammatik 20 lessons with ~260 exercises and a random drill, 332 words with gap-fill, plural and hat/ist drills.
This commit is contained in:
1 parent
1f1d28a34d
commit
c754477f07
16 files changed
+2054
-17
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import { allWords, type Word } from "@/data/vocab";
|
||||
|
||||
export interface DrillQ {
|
||||
id: string;
|
||||
prompt: string;
|
||||
hintAr: string;
|
||||
options: string[];
|
||||
answer: number;
|
||||
explain?: string;
|
||||
speak?: string;
|
||||
}
|
||||
|
||||
function shuffle<T>(a: T[]): T[] {
|
||||
const b = [...a];
|
||||
for (let i = b.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[b[i], b[j]] = [b[j], b[i]];
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
function withOptions(correct: string, wrong: string[]): { options: string[]; answer: number } {
|
||||
const options = shuffle([correct, ...shuffle([...new Set(wrong.filter((w) => w !== correct))]).slice(0, 3)]);
|
||||
return { options, answer: options.indexOf(correct) };
|
||||
}
|
||||
|
||||
const escape = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const isSimple = (w: Word) => !/[\s()…/]/.test(w.de);
|
||||
|
||||
/** Lückentext: das Wort fehlt im Beispielsatz. */
|
||||
export function gapFillQuestions(words: Word[]): DrillQ[] {
|
||||
const out: DrillQ[] = [];
|
||||
for (const w of words) {
|
||||
if (!isSimple(w)) continue;
|
||||
const re = new RegExp(`(^|[^A-Za-zÄÖÜäöüß])${escape(w.de)}(?=[^A-Za-zÄÖÜäöüß]|$)`);
|
||||
if (!re.test(w.ex)) continue;
|
||||
const sentence = w.ex.replace(re, (_m, pre: string) => `${pre}_____`);
|
||||
const sameKind = allWords.filter((x) => x.id !== w.id && isSimple(x) && Boolean(x.art) === Boolean(w.art) && x.de !== w.de);
|
||||
const sameTopic = sameKind.filter((x) => x.topic === w.topic);
|
||||
const pool = (sameTopic.length >= 3 ? sameTopic : sameKind).map((x) => x.de);
|
||||
const { options, answer } = withOptions(w.de, pool);
|
||||
out.push({ id: w.id, prompt: sentence, hintAr: w.exAr, options, answer, speak: w.ex, explain: `${w.art ? w.art + " " : ""}${w.de} = ${w.ar}` });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const umlaut = (s: string) => {
|
||||
const m = s.match(/(au|a|o|u)(?=[^aouäöü]*$)/);
|
||||
if (!m || m.index === undefined) return s;
|
||||
const rep = m[1] === "au" ? "äu" : m[1] === "a" ? "ä" : m[1] === "o" ? "ö" : "ü";
|
||||
return s.slice(0, m.index) + rep + s.slice(m.index + m[1].length);
|
||||
};
|
||||
|
||||
/** Pluralformen der Nomen. */
|
||||
export function pluralQuestions(words: Word[]): DrillQ[] {
|
||||
const out: DrillQ[] = [];
|
||||
for (const w of words) {
|
||||
if (!w.art || !w.pl || !w.pl.startsWith("die ") || !isSimple(w)) continue;
|
||||
const correct = w.pl;
|
||||
const b = w.de.endsWith("e") ? w.de.slice(0, -1) : w.de;
|
||||
const candidates = [w.de, w.de + "e", w.de + "en", w.de + "n", w.de + "s", w.de + "er", umlaut(w.de) + "e", umlaut(w.de) + "er", umlaut(b) + "en", b + "en"].map((c) => `die ${c}`);
|
||||
const { options, answer } = withOptions(correct, candidates);
|
||||
if (options.length < 3) continue;
|
||||
out.push({ id: w.id, prompt: `Wie heißt der Plural von „${w.art} ${w.de}“?`, hintAr: `ما جمع كلمة «${w.ar}»؟`, options, answer, speak: correct });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Perfekt mit „hat“ oder „ist“? */
|
||||
export function perfektQuestions(words: Word[]): DrillQ[] {
|
||||
const out: DrillQ[] = [];
|
||||
for (const w of words) {
|
||||
if (w.art || !w.pl || !/^(hat|ist) /.test(w.pl)) continue;
|
||||
const [aux, ...rest] = w.pl.split(" ");
|
||||
const options = ["hat", "ist"];
|
||||
out.push({
|
||||
id: w.id,
|
||||
prompt: `${w.de} → er ___ ${rest.join(" ")}`,
|
||||
hintAr: `${w.ar} – هل يُصرَّف في الماضي التام مع hat أم ist؟`,
|
||||
options,
|
||||
answer: options.indexOf(aux),
|
||||
speak: `er ${w.pl}`,
|
||||
explain: aux === "ist" ? "„ist“: Bewegung / Veränderung (gehen, fahren, umziehen …)" : "„hat“: die meisten Verben",
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user