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
All checks were successful
Deploy to production / deploy (push) Successful in 2m16s
This commit is contained in:
@@ -127,6 +127,32 @@ export default {
|
||||
};
|
||||
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) {
|
||||
return `${String(item?.gloss || '').trim()}|${String(item?.target || '').trim()}`;
|
||||
},
|
||||
@@ -190,9 +216,10 @@ export default {
|
||||
},
|
||||
async checkCurrent() {
|
||||
if (!this.currentItem) return;
|
||||
const isCorrect = this.mode === 'multiple_choice'
|
||||
? this.normalize(this.selectedOption) === this.normalize(this.currentItem.gloss)
|
||||
: this.normalize(this.typedAnswer) === this.normalize(this.currentItem.target);
|
||||
const expectedRaw = this.mode === 'multiple_choice' ? this.currentItem.gloss : this.currentItem.target;
|
||||
const expectedAnswers = this.expandAnswerVariants(expectedRaw).map((entry) => this.normalize(entry));
|
||||
const userAnswer = this.mode === 'multiple_choice' ? this.selectedOption : this.typedAnswer;
|
||||
const isCorrect = expectedAnswers.includes(this.normalize(userAnswer));
|
||||
|
||||
this.feedbackCorrect = isCorrect;
|
||||
if (isCorrect) {
|
||||
|
||||
@@ -4353,14 +4353,31 @@ export default {
|
||||
expandAnswerVariants(answer) {
|
||||
const base = String(answer || '').trim();
|
||||
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) {
|
||||
const expanded = phraseAlternatives.flatMap((part) => this.expandSingleAnswerVariants(part));
|
||||
return [...new Set(expanded)];
|
||||
}
|
||||
|
||||
return this.expandSingleAnswerVariants(base);
|
||||
return [...new Set(
|
||||
this.expandSingleAnswerVariants(base)
|
||||
.concat(withoutParentheses ? this.expandSingleAnswerVariants(withoutParentheses) : [])
|
||||
)];
|
||||
},
|
||||
reportSrsReviewForCurrentQuestion(isCorrect) {
|
||||
if (!this.currentVocabQuestion?.vocab || !this.courseId) {
|
||||
|
||||
Reference in New Issue
Block a user