refactor(vocab): standardize text normalization methods in VocabService and VocabLessonView
All checks were successful
Deploy to production / deploy (push) Successful in 3m1s
All checks were successful
Deploy to production / deploy (push) Successful in 3m1s
- Updated text normalization logic in VocabService to use a regex that replaces punctuation with spaces, improving text handling consistency. - Refactored VocabLessonView to utilize the new normalization method for comparable text, enhancing the accuracy of user input processing. - Ensured both components now share a unified approach to text normalization, streamlining code and improving maintainability.
This commit is contained in:
@@ -2041,7 +2041,7 @@ export default {
|
||||
const totalSlots = options.length;
|
||||
const need = totalSlots - correctTexts.length;
|
||||
if (need <= 0) return null;
|
||||
const norm = (s) => String(s).trim().toLowerCase();
|
||||
const norm = (s) => this.normalizeComparableText(s);
|
||||
const correctSet = new Set(correctTexts.map(norm));
|
||||
const poolRaw = side === 'target' ? this.distractorPool.target : this.distractorPool.native;
|
||||
let poolFiltered = poolRaw.filter((w) => w && !correctSet.has(norm(w)));
|
||||
@@ -2700,8 +2700,15 @@ export default {
|
||||
this.checkVocabAnswer();
|
||||
}
|
||||
},
|
||||
normalizeComparableText(value) {
|
||||
return String(value || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[\p{P}]+/gu, ' ')
|
||||
.replace(/\s+/g, ' ');
|
||||
},
|
||||
normalizeVocab(s) {
|
||||
return String(s || '').trim().toLowerCase().replace(/\s+/g, ' ');
|
||||
return this.normalizeComparableText(s);
|
||||
},
|
||||
checkVocabAnswer() {
|
||||
if (!this.currentVocabQuestion) return;
|
||||
|
||||
Reference in New Issue
Block a user