Refactor vocabulary extraction logic in VocabLessonView for multiple choice and gap fill exercises
- Enhanced the handling of multiple choice questions by extracting options and determining the correct answer index, improving accuracy in vocabulary mapping. - Updated the question analysis to support different patterns for extracting German and Bisaya words, enhancing the learning experience. - Improved gap fill answer extraction by iterating through possible answers and creating unique keys for vocabulary mapping, ensuring better context handling. - Added detailed error logging to assist in debugging vocabulary extraction issues.
This commit is contained in:
@@ -310,28 +310,51 @@ export default {
|
|||||||
if (qData && aData) {
|
if (qData && aData) {
|
||||||
// Für Multiple Choice: Extrahiere Optionen und richtige Antwort
|
// Für Multiple Choice: Extrahiere Optionen und richtige Antwort
|
||||||
if (this.getExerciseType(exercise) === 'multiple_choice') {
|
if (this.getExerciseType(exercise) === 'multiple_choice') {
|
||||||
const correct = Array.isArray(aData.correct) ? aData.correct[0] : aData.correct;
|
const options = qData.options || [];
|
||||||
const question = qData.text || '';
|
const correctIndex = aData.correctAnswer !== undefined ? aData.correctAnswer : (aData.correct || 0);
|
||||||
|
const correctAnswer = options[correctIndex] || '';
|
||||||
|
|
||||||
// Versuche die Frage zu analysieren (z.B. "Wie sagt man X auf Bisaya?")
|
if (correctAnswer) {
|
||||||
const match = question.match(/['"]([^'"]+)['"]/);
|
// Versuche die Frage zu analysieren (z.B. "Wie sagt man 'X' auf Bisaya?" oder "Was bedeutet 'X'?")
|
||||||
if (match) {
|
const question = qData.question || qData.text || '';
|
||||||
const germanWord = match[1];
|
|
||||||
vocabMap.set(correct, { learning: correct, reference: germanWord });
|
// Pattern 1: "Wie sagt man 'X' auf Bisaya?" -> X ist Deutsch, correctAnswer ist Bisaya
|
||||||
} else if (correct) {
|
let match = question.match(/['"]([^'"]+)['"]/);
|
||||||
// Fallback: Verwende die richtige Antwort als Lernwort
|
if (match) {
|
||||||
vocabMap.set(correct, { learning: correct, reference: correct });
|
const germanWord = match[1];
|
||||||
|
vocabMap.set(correctAnswer, { learning: correctAnswer, reference: germanWord });
|
||||||
|
} else {
|
||||||
|
// Pattern 2: "Was bedeutet 'X'?" -> X ist Bisaya, correctAnswer ist Deutsch
|
||||||
|
match = question.match(/Was bedeutet ['"]([^'"]+)['"]/);
|
||||||
|
if (match) {
|
||||||
|
const bisayaWord = match[1];
|
||||||
|
vocabMap.set(bisayaWord, { learning: bisayaWord, reference: correctAnswer });
|
||||||
|
} else {
|
||||||
|
// Fallback: Verwende die richtige Antwort als Lernwort
|
||||||
|
vocabMap.set(correctAnswer, { learning: correctAnswer, reference: correctAnswer });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Für Gap Fill: Extrahiere richtige Antworten
|
// Für Gap Fill: Extrahiere richtige Antworten
|
||||||
if (this.getExerciseType(exercise) === 'gap_fill' && aData.correct) {
|
if (this.getExerciseType(exercise) === 'gap_fill') {
|
||||||
const correct = Array.isArray(aData.correct) ? aData.correct[0] : aData.correct;
|
const answers = aData.answers || (aData.correct ? (Array.isArray(aData.correct) ? aData.correct : [aData.correct]) : []);
|
||||||
vocabMap.set(correct, { learning: correct, reference: correct });
|
if (answers.length > 0) {
|
||||||
|
// Versuche aus dem Text Kontext zu extrahieren
|
||||||
|
const text = qData.text || '';
|
||||||
|
answers.forEach((answer, index) => {
|
||||||
|
if (answer && answer.trim()) {
|
||||||
|
// Erstelle einen eindeutigen Key
|
||||||
|
const key = `${answer}-${index}`;
|
||||||
|
vocabMap.set(key, { learning: answer, reference: answer });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Fehler beim Extrahieren von Vokabeln aus Übung:', e);
|
console.warn('Fehler beim Extrahieren von Vokabeln aus Übung:', e, exercise);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user