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) {
|
||||
// Für Multiple Choice: Extrahiere Optionen und richtige Antwort
|
||||
if (this.getExerciseType(exercise) === 'multiple_choice') {
|
||||
const correct = Array.isArray(aData.correct) ? aData.correct[0] : aData.correct;
|
||||
const question = qData.text || '';
|
||||
const options = qData.options || [];
|
||||
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?")
|
||||
const match = question.match(/['"]([^'"]+)['"]/);
|
||||
if (match) {
|
||||
const germanWord = match[1];
|
||||
vocabMap.set(correct, { learning: correct, reference: germanWord });
|
||||
} else if (correct) {
|
||||
// Fallback: Verwende die richtige Antwort als Lernwort
|
||||
vocabMap.set(correct, { learning: correct, reference: correct });
|
||||
if (correctAnswer) {
|
||||
// Versuche die Frage zu analysieren (z.B. "Wie sagt man 'X' auf Bisaya?" oder "Was bedeutet 'X'?")
|
||||
const question = qData.question || qData.text || '';
|
||||
|
||||
// Pattern 1: "Wie sagt man 'X' auf Bisaya?" -> X ist Deutsch, correctAnswer ist Bisaya
|
||||
let match = question.match(/['"]([^'"]+)['"]/);
|
||||
if (match) {
|
||||
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
|
||||
if (this.getExerciseType(exercise) === 'gap_fill' && aData.correct) {
|
||||
const correct = Array.isArray(aData.correct) ? aData.correct[0] : aData.correct;
|
||||
vocabMap.set(correct, { learning: correct, reference: correct });
|
||||
if (this.getExerciseType(exercise) === 'gap_fill') {
|
||||
const answers = aData.answers || (aData.correct ? (Array.isArray(aData.correct) ? aData.correct : [aData.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) {
|
||||
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