feat(VocabPracticeDialog): add answer variant expansion for improved vocabulary training
All checks were successful
Deploy to production / deploy (push) Successful in 1m55s

- Introduced a new method `expandAnswerVariants` to generate multiple answer variants from a given input, enhancing the flexibility of acceptable answers.
- Improved handling of words with slashes to create diverse answer options, ensuring a richer vocabulary training experience.
- Updated the answer collection logic to utilize the new method, allowing for a broader range of valid responses during practice sessions.
This commit is contained in:
Torsten Schulz (local)
2026-04-20 08:36:11 +02:00
parent f64c923db6
commit 553f132184

View File

@@ -543,11 +543,52 @@ export default {
const itemPrompt = direction === 'L2R' ? item.learning : item.reference; const itemPrompt = direction === 'L2R' ? item.learning : item.reference;
if (this.normalize(itemPrompt) === p) { if (this.normalize(itemPrompt) === p) {
const a = direction === 'L2R' ? item.reference : item.learning; const a = direction === 'L2R' ? item.reference : item.learning;
answers.add(a); this.expandAnswerVariants(a).forEach((variant) => answers.add(variant));
} }
} }
return Array.from(answers); return Array.from(answers);
}, },
expandAnswerVariants(answer) {
const base = String(answer || '').trim();
if (!base) return [];
const words = base.split(/\s+/).map((word) => {
if (!word.includes('/')) {
return [word];
}
const match = word.match(/^([([{„"'“‘]*)(.*?)([)\]}.,!?;:»"'”’]*)$/);
const prefix = match?.[1] || '';
const core = match?.[2] || word;
const suffix = match?.[3] || '';
const parts = core
.split('/')
.map((part) => part.trim())
.filter(Boolean);
if (parts.length < 2 || parts.length > 4) {
return [word];
}
return parts.map((part) => `${prefix}${part}${suffix}`);
});
const variants = [''];
for (const options of words) {
const next = [];
for (const current of variants) {
for (const option of options) {
next.push(`${current}${current ? ' ' : ''}${option}`);
}
}
if (next.length > 24) {
return [base];
}
variants.splice(0, variants.length, ...next);
}
return [...new Set([base, ...variants])];
},
computeWeight(item) { computeWeight(item) {
const st = this.perId[item.id] || { c: 0, w: 0, streak: 0, lastAsked: 0 }; const st = this.perId[item.id] || { c: 0, w: 0, streak: 0, lastAsked: 0 };
let w = 1; let w = 1;