refactor(vocabService, VocabLessonView): unify answer language classification for multiple-choice questions
All checks were successful
Deploy to production / deploy (push) Successful in 2m51s
All checks were successful
Deploy to production / deploy (push) Successful in 2m51s
- Renamed and refactored the method for classifying answer languages in multiple-choice questions from _classifyMcQuestionSide to _resolveMcAnswerSide for clarity and consistency. - Updated the logic to classify answer languages based on questionData.answerLanguage and answerLanguageId, improving accuracy in determining the correct language context. - Adjusted VocabLessonView to utilize the new classification method, ensuring alignment with backend changes and enhancing the handling of distractor options based on answer language. - Enhanced documentation to clarify the expected input and output for the new method, improving maintainability and understanding of the codebase.
This commit is contained in:
@@ -3593,20 +3593,30 @@ export default class VocabService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ordnet eine Multiple-Choice-Frage der Zielsprache (zu lernen) oder Muttersprache (Erklärung) zu,
|
||||
* damit Distraktoren aus dem passenden Wortpool gewählt werden können.
|
||||
* Explizite Zuordnung der Antwortsprache (sprachneutral).
|
||||
* questionData.answerLanguage: 'target' | 'native'
|
||||
* oder questionData.answerLanguageId: 1 = target (Lernsprache), 2 = native (Muttersprache)
|
||||
* Ohne diese Felder: 'unknown' (kein Eintrag in den Distraktor-Pools für diese Frage).
|
||||
* @param {object} questionData
|
||||
* @returns {'target'|'native'|'unknown'}
|
||||
*/
|
||||
_classifyMcQuestionSide(question) {
|
||||
const q = String(question || '');
|
||||
if (/Wie sagt man\s/i.test(q) || /Übersetze/i.test(q)) return 'target';
|
||||
if (/Was bedeutet/i.test(q)) return 'native';
|
||||
_resolveMcAnswerSide(questionData) {
|
||||
if (!questionData || typeof questionData !== 'object') return 'unknown';
|
||||
const raw = questionData.answerLanguage;
|
||||
if (typeof raw === 'string') {
|
||||
const s = raw.trim().toLowerCase();
|
||||
if (s === 'target' || s === 'learning' || s === 'l2') return 'target';
|
||||
if (s === 'native' || s === 'l1') return 'native';
|
||||
}
|
||||
const id = questionData.answerLanguageId;
|
||||
if (id === 1 || id === '1') return 'target';
|
||||
if (id === 2 || id === '2') return 'native';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sammelt Vokabeln aus allen Multiple-Choice-Übungen von Lektionen **vor** der angegebenen Lektion
|
||||
* (gleicher Kurs), getrennt nach Ziel- vs. Muttersprache anhand der Frageformulierung.
|
||||
* (gleicher Kurs), getrennt nach Ziel- vs. Muttersprache anhand von answerLanguage / answerLanguageId.
|
||||
*/
|
||||
async getVocabDistractorPool(hashedUserId, courseId, beforeLessonId) {
|
||||
if (!beforeLessonId) {
|
||||
@@ -3659,10 +3669,9 @@ export default class VocabService {
|
||||
for (const ex of exercises) {
|
||||
const qd =
|
||||
typeof ex.questionData === 'string' ? JSON.parse(ex.questionData) : ex.questionData;
|
||||
const question = qd?.question || '';
|
||||
const opts = qd?.options;
|
||||
if (!Array.isArray(opts)) continue;
|
||||
const side = this._classifyMcQuestionSide(question);
|
||||
const side = this._resolveMcAnswerSide(qd);
|
||||
if (side === 'target') {
|
||||
opts.forEach((o) => target.add(String(o).trim()));
|
||||
} else if (side === 'native') {
|
||||
|
||||
Reference in New Issue
Block a user