Erweitere die Funktionalität zur Verarbeitung von Antwortvarianten; füge Unterstützung für Klammerinhalte und alternative Phrasen hinzu.
All checks were successful
Deploy to production / deploy (push) Successful in 2m16s

This commit is contained in:
Torsten Schulz (local)
2026-07-21 09:20:56 +02:00
parent 1ab9407e79
commit c13339f771
3 changed files with 65 additions and 7 deletions

View File

@@ -1016,17 +1016,31 @@ export default {
expandAnswerVariants(answer) { expandAnswerVariants(answer) {
const base = String(answer || '').trim(); const base = String(answer || '').trim();
if (!base) return []; if (!base) return [];
const variants = new Set([base]);
const withoutParentheses = base.replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
if (withoutParentheses) {
variants.add(withoutParentheses);
}
const parenMatches = base.match(/\(([^)]+)\)/g) || [];
parenMatches.forEach((chunk) => {
const content = chunk.replace(/[()]/g, '').trim();
if (content) {
variants.add(content);
}
});
// Handle full-answer alternatives like "A / B" as separate valid answers. // Handle full-answer alternatives like "A / B" as separate valid answers.
// Word-level slash expansion alone does not cover this reliably. // Word-level slash expansion alone does not cover this reliably.
const phraseAlternatives = this.splitPhraseAlternatives(base); const phraseAlternatives = Array.from(variants).flatMap((entry) => this.splitPhraseAlternatives(entry));
if (phraseAlternatives.length >= 2) { if (phraseAlternatives.length >= 2) {
const expanded = phraseAlternatives.flatMap((part) => this.expandSingleAnswerVariants(part)); const expanded = phraseAlternatives.flatMap((part) => this.expandSingleAnswerVariants(part));
return [...new Set(expanded)]; return [...new Set(expanded)];
} }
return this.expandSingleAnswerVariants(base); return this.expandSingleAnswerVariants(base).concat(withoutParentheses ? this.expandSingleAnswerVariants(withoutParentheses) : []);
}, },
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 };

View File

@@ -127,6 +127,32 @@ export default {
}; };
return normalizeComparableWithNumberWords(s, baseNormalize); return normalizeComparableWithNumberWords(s, baseNormalize);
}, },
splitPhraseAlternatives(answer) {
const base = String(answer || '').trim();
if (!base) return [];
const parts = base.split(/\s*[\/|;]\s*/).map((part) => part.trim()).filter(Boolean);
return parts.length >= 2 && parts.length <= 6 ? parts : [base];
},
expandAnswerVariants(answer) {
const base = String(answer || '').trim();
if (!base) return [];
const variants = new Set([base]);
const withoutParentheses = base.replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
if (withoutParentheses) {
variants.add(withoutParentheses);
}
const parenMatches = base.match(/\(([^)]+)\)/g) || [];
parenMatches.forEach((chunk) => {
const content = chunk.replace(/[()]/g, '').trim();
if (content) {
variants.add(content);
}
});
return [...new Set(Array.from(variants).flatMap((entry) => this.splitPhraseAlternatives(entry)))];
},
getItemKey(item) { getItemKey(item) {
return `${String(item?.gloss || '').trim()}|${String(item?.target || '').trim()}`; return `${String(item?.gloss || '').trim()}|${String(item?.target || '').trim()}`;
}, },
@@ -190,9 +216,10 @@ export default {
}, },
async checkCurrent() { async checkCurrent() {
if (!this.currentItem) return; if (!this.currentItem) return;
const isCorrect = this.mode === 'multiple_choice' const expectedRaw = this.mode === 'multiple_choice' ? this.currentItem.gloss : this.currentItem.target;
? this.normalize(this.selectedOption) === this.normalize(this.currentItem.gloss) const expectedAnswers = this.expandAnswerVariants(expectedRaw).map((entry) => this.normalize(entry));
: this.normalize(this.typedAnswer) === this.normalize(this.currentItem.target); const userAnswer = this.mode === 'multiple_choice' ? this.selectedOption : this.typedAnswer;
const isCorrect = expectedAnswers.includes(this.normalize(userAnswer));
this.feedbackCorrect = isCorrect; this.feedbackCorrect = isCorrect;
if (isCorrect) { if (isCorrect) {

View File

@@ -4353,14 +4353,31 @@ export default {
expandAnswerVariants(answer) { expandAnswerVariants(answer) {
const base = String(answer || '').trim(); const base = String(answer || '').trim();
if (!base) return []; if (!base) return [];
const variants = new Set([base]);
const phraseAlternatives = this.splitPhraseAlternatives(base); const withoutParentheses = base.replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
if (withoutParentheses) {
variants.add(withoutParentheses);
}
const parenMatches = base.match(/\(([^)]+)\)/g) || [];
parenMatches.forEach((chunk) => {
const content = chunk.replace(/[()]/g, '').trim();
if (content) {
variants.add(content);
}
});
const phraseAlternatives = Array.from(variants).flatMap((entry) => this.splitPhraseAlternatives(entry));
if (phraseAlternatives.length >= 2) { if (phraseAlternatives.length >= 2) {
const expanded = phraseAlternatives.flatMap((part) => this.expandSingleAnswerVariants(part)); const expanded = phraseAlternatives.flatMap((part) => this.expandSingleAnswerVariants(part));
return [...new Set(expanded)]; return [...new Set(expanded)];
} }
return this.expandSingleAnswerVariants(base); return [...new Set(
this.expandSingleAnswerVariants(base)
.concat(withoutParentheses ? this.expandSingleAnswerVariants(withoutParentheses) : [])
)];
}, },
reportSrsReviewForCurrentQuestion(isCorrect) { reportSrsReviewForCurrentQuestion(isCorrect) {
if (!this.currentVocabQuestion?.vocab || !this.courseId) { if (!this.currentVocabQuestion?.vocab || !this.courseId) {