From 7e5a46a9bf434bcdb3207a6b26a7175110d207dc Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Tue, 14 Apr 2026 14:57:54 +0200 Subject: [PATCH] fix(vocabLesson): improve answer validation logic for gap fill exercises - 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. --- frontend/src/views/social/VocabLessonView.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/social/VocabLessonView.vue b/frontend/src/views/social/VocabLessonView.vue index bf43d22..1001694 100644 --- a/frontend/src/views/social/VocabLessonView.vue +++ b/frontend/src/views/social/VocabLessonView.vue @@ -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); } } });