feat(vocabService): enhance answer validation with comparable variants
All checks were successful
Deploy to production / deploy (push) Successful in 2m45s
All checks were successful
Deploy to production / deploy (push) Successful in 2m45s
- Introduced methods to expand comparable answer variants and improve answer equivalence checks, allowing for more flexible user responses. - Updated the answer validation logic to utilize the new methods, enhancing the accuracy of response evaluation during exercises.
This commit is contained in:
@@ -500,6 +500,33 @@ export default class VocabService {
|
||||
return normalized.replace(/\s+/g, '');
|
||||
}
|
||||
|
||||
_expandComparableAnswerVariants(text) {
|
||||
const raw = String(text || '').trim();
|
||||
if (!raw) return [];
|
||||
const variants = new Set([raw]);
|
||||
|
||||
// Beispiel: "heute (heute am Tag)" -> "heute" und "heute am Tag"
|
||||
const withoutParentheses = raw.replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
if (withoutParentheses) variants.add(withoutParentheses);
|
||||
|
||||
const parenMatches = raw.match(/\(([^)]+)\)/g) || [];
|
||||
parenMatches.forEach((chunk) => {
|
||||
const content = chunk.replace(/[()]/g, '').trim();
|
||||
if (content) variants.add(content);
|
||||
});
|
||||
|
||||
return Array.from(variants);
|
||||
}
|
||||
|
||||
_isEquivalentAnswer(userAnswer, canonicalAnswer) {
|
||||
const normalizedUser = this._normalizeTextAnswer(userAnswer);
|
||||
if (!normalizedUser) return false;
|
||||
const canonicalVariants = this._expandComparableAnswerVariants(canonicalAnswer)
|
||||
.map((entry) => this._normalizeTextAnswer(entry))
|
||||
.filter(Boolean);
|
||||
return canonicalVariants.includes(normalizedUser);
|
||||
}
|
||||
|
||||
_parseExercisePayload(value) {
|
||||
if (!value) return {};
|
||||
if (typeof value === 'string') {
|
||||
@@ -3550,7 +3577,7 @@ export default class VocabService {
|
||||
if (typeof userAnswer === 'string') {
|
||||
const u = norm(userAnswer);
|
||||
if (!u) return false;
|
||||
return correctTexts.some((t) => norm(t) === u);
|
||||
return correctTexts.some((t) => this._isEquivalentAnswer(userAnswer, t));
|
||||
}
|
||||
|
||||
// Legacy: Index in die gespeicherten (nicht gemischten) Optionen
|
||||
|
||||
Reference in New Issue
Block a user