Erweitere die Funktionalität zur Verarbeitung von Antwortvarianten; füge Unterstützung für Klammerinhalte und alternative Phrasen hinzu.

This commit is contained in:
Torsten Schulz (local)
2026-07-21 09:20:56 +02:00
parent a7e0fe1d97
commit a3f90772a7
3 changed files with 65 additions and 7 deletions

View File

@@ -1016,17 +1016,31 @@ export default {
expandAnswerVariants(answer) {
const base = String(answer || '').trim();
if (!base) return [];
const variants = new Set([base]);
const withoutParentheses = base.replace(/\s*\([^)]*\)\s*/g, ' ').replace(/\s+/g, ' ').trim();
if (withoutParentheses) {
variants.add(withoutParentheses);
}
const parenMatches = base.match(/\(([^)]+)\)/g) || [];
parenMatches.forEach((chunk) => {
const content = chunk.replace(/[()]/g, '').trim();
if (content) {
variants.add(content);
}
});
// Handle full-answer alternatives like "A / B" as separate valid answers.
// Word-level slash expansion alone does not cover this reliably.
const phraseAlternatives = this.splitPhraseAlternatives(base);
const phraseAlternatives = Array.from(variants).flatMap((entry) => this.splitPhraseAlternatives(entry));
if (phraseAlternatives.length >= 2) {
const expanded = phraseAlternatives.flatMap((part) => this.expandSingleAnswerVariants(part));
return [...new Set(expanded)];
}
return this.expandSingleAnswerVariants(base);
return this.expandSingleAnswerVariants(base).concat(withoutParentheses ? this.expandSingleAnswerVariants(withoutParentheses) : []);
},
computeWeight(item) {
const st = this.perId[item.id] || { c: 0, w: 0, streak: 0, lastAsked: 0 };