refactor(exercises): standardize answer language handling across exercise scripts
All checks were successful
Deploy to production / deploy (push) Successful in 2m48s
All checks were successful
Deploy to production / deploy (push) Successful in 2m48s
- Introduced a mechanism to infer answer language based on question phrasing in multiple exercise scripts, enhancing consistency in exercise data. - Updated question formats to clarify the intent of exercises, improving user understanding and engagement. - Streamlined the code for better maintainability and clarity in exercise generation processes.
This commit is contained in:
@@ -13,6 +13,31 @@ import VocabCourseLesson from '../models/community/vocab_course_lesson.js';
|
||||
import VocabGrammarExercise from '../models/community/vocab_grammar_exercise.js';
|
||||
import User from '../models/community/user.js';
|
||||
|
||||
function normalizeMcAnswerLanguage(question = '') {
|
||||
const q = String(question || '').trim();
|
||||
if (!q) return null;
|
||||
if (/Wie sagt man/i.test(q) || /auf Bisaya\?/i.test(q)) return 'target';
|
||||
if (/Was bedeutet/i.test(q) || /Was heißt/i.test(q)) return 'native';
|
||||
return null;
|
||||
}
|
||||
|
||||
function enrichAnswerLanguage(exercises = []) {
|
||||
return exercises.map((exercise) => {
|
||||
const qd = exercise?.questionData;
|
||||
if (!qd || qd.type !== 'multiple_choice') return exercise;
|
||||
if (qd.answerLanguage || qd.answerLanguageId) return exercise;
|
||||
const inferred = normalizeMcAnswerLanguage(qd.question);
|
||||
if (!inferred) return exercise;
|
||||
return {
|
||||
...exercise,
|
||||
questionData: {
|
||||
...qd,
|
||||
answerLanguage: inferred
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Spezifische Übungen für Überlebenssätze
|
||||
const SURVIVAL_EXERCISES = {
|
||||
'Überlebenssätze - Teil 1': [
|
||||
@@ -399,7 +424,7 @@ async function updateSurvivalExercises() {
|
||||
console.log(` ${lessons.length} "Überlebenssätze"-Lektionen gefunden\n`);
|
||||
|
||||
for (const lesson of lessons) {
|
||||
const exercises = SURVIVAL_EXERCISES[lesson.title];
|
||||
const exercises = enrichAnswerLanguage(SURVIVAL_EXERCISES[lesson.title]);
|
||||
|
||||
if (!exercises || exercises.length === 0) {
|
||||
console.log(` ⚠️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - keine Übungen definiert`);
|
||||
|
||||
Reference in New Issue
Block a user