refactor(vocab): unify text normalization across VocabService and VocabPracticeDialog
All checks were successful
Deploy to production / deploy (push) Successful in 3m3s

- Enhanced text normalization methods in VocabService and VocabPracticeDialog to include normalization and improved regex for punctuation and symbols, ensuring consistent text handling.
- This update streamlines the normalization process, contributing to better user input processing and overall application reliability.
This commit is contained in:
Torsten Schulz (local)
2026-04-01 15:24:22 +02:00
parent d38231b52c
commit d39cea2c01
3 changed files with 14 additions and 6 deletions

View File

@@ -342,12 +342,14 @@ export default class VocabService {
} }
_normalizeTextAnswer(text) { _normalizeTextAnswer(text) {
return String(text || '') const normalized = String(text || '')
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(/[\p{P}]+/gu, ' ') .normalize('NFKC')
.replace(/[\p{P}\p{S}]+/gu, ' ')
.replace(/\s+/g, ' ') .replace(/\s+/g, ' ')
.trim(); .trim();
return normalized.replace(/\s+/g, '');
} }
_parseExercisePayload(value) { _parseExercisePayload(value) {

View File

@@ -224,10 +224,14 @@ export default {
} }
}, },
normalize(s) { normalize(s) {
return String(s || '') const normalized = String(s || '')
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(/\s+/g, ' '); .normalize('NFKC')
.replace(/[\p{P}\p{S}]+/gu, ' ')
.replace(/\s+/g, ' ')
.trim();
return normalized.replace(/\s+/g, '');
}, },
resetQuestion() { resetQuestion() {
this.current = null; this.current = null;

View File

@@ -2701,12 +2701,14 @@ export default {
} }
}, },
normalizeComparableText(value) { normalizeComparableText(value) {
return String(value || '') const normalized = String(value || '')
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(/[\p{P}]+/gu, ' ') .normalize('NFKC')
.replace(/[\p{P}\p{S}]+/gu, ' ')
.replace(/\s+/g, ' ') .replace(/\s+/g, ' ')
.trim(); .trim();
return normalized.replace(/\s+/g, '');
}, },
normalizeVocab(s) { normalizeVocab(s) {
return this.normalizeComparableText(s); return this.normalizeComparableText(s);