fix(vocabLesson): improve answer validation logic for gap fill exercises
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s

- Enhanced the answer validation process by introducing checks for native word and answer text, ensuring they are trimmed and compared correctly.
- Added logic to identify likely fragment mismatches based on sentence structure and word count, preventing incorrect answer submissions.
- Updated debug logging to provide clearer insights into the validation process, improving maintainability and debugging capabilities.
This commit is contained in:
Torsten Schulz (local)
2026-04-14 14:57:54 +02:00
parent deb6f5f36c
commit 7e5a46a9bf

View File

@@ -2285,13 +2285,20 @@ export default {
answers.forEach((answer, index) => {
if (answer && answer.trim()) {
const nativeWord = nativeWords[index];
if (nativeWord && nativeWord.trim() && nativeWord !== answer) {
const nativeText = String(nativeWord || '').trim();
const answerText = String(answer || '').trim();
const nativeWordCount = nativeText.split(/\s+/).filter(Boolean).length;
const answerWordCount = answerText.split(/\s+/).filter(Boolean).length;
const nativeLooksSentence = /[?.!]/.test(nativeText) || nativeWordCount >= 4;
const answerLooksShortToken = answerWordCount <= 2;
const likelyFragmentMismatch = nativeLooksSentence && answerLooksShortToken;
if (nativeText && answerText && nativeText !== answerText && !likelyFragmentMismatch) {
// Die answer ist normalerweise Bisaya, nativeWord ist Muttersprache
// Nur hinzufügen, wenn sie unterschiedlich sind (verhindert "ko" -> "ko")
vocabMap.set(`${nativeWord}-${answer}`, { learning: nativeWord, reference: answer });
debugLog(`[importantVocab] Gap Fill extrahiert - Muttersprache:`, nativeWord, `Bisaya:`, answer);
vocabMap.set(`${nativeText}-${answerText}`, { learning: nativeText, reference: answerText });
debugLog(`[importantVocab] Gap Fill extrahiert - Muttersprache:`, nativeText, `Bisaya:`, answerText);
} else {
debugLog(`[importantVocab] Gap Fill übersprungen - keine Muttersprache oder gleich:`, nativeWord, answer);
debugLog(`[importantVocab] Gap Fill übersprungen - Satz/Fragment-Mismatch oder gleich:`, nativeText, answerText);
}
}
});