From d39cea2c016dde5ab317981b1f379c07f282d42f Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 1 Apr 2026 15:24:22 +0200 Subject: [PATCH] refactor(vocab): unify text normalization across VocabService and VocabPracticeDialog - 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. --- backend/services/vocabService.js | 6 ++++-- .../src/dialogues/socialnetwork/VocabPracticeDialog.vue | 8 ++++++-- frontend/src/views/social/VocabLessonView.vue | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/services/vocabService.js b/backend/services/vocabService.js index 7feda36..e797ba6 100644 --- a/backend/services/vocabService.js +++ b/backend/services/vocabService.js @@ -342,12 +342,14 @@ export default class VocabService { } _normalizeTextAnswer(text) { - return String(text || '') + const normalized = String(text || '') .trim() .toLowerCase() - .replace(/[\p{P}]+/gu, ' ') + .normalize('NFKC') + .replace(/[\p{P}\p{S}]+/gu, ' ') .replace(/\s+/g, ' ') .trim(); + return normalized.replace(/\s+/g, ''); } _parseExercisePayload(value) { diff --git a/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue b/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue index 0ed4885..8073ec0 100644 --- a/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue +++ b/frontend/src/dialogues/socialnetwork/VocabPracticeDialog.vue @@ -224,10 +224,14 @@ export default { } }, normalize(s) { - return String(s || '') + const normalized = String(s || '') .trim() .toLowerCase() - .replace(/\s+/g, ' '); + .normalize('NFKC') + .replace(/[\p{P}\p{S}]+/gu, ' ') + .replace(/\s+/g, ' ') + .trim(); + return normalized.replace(/\s+/g, ''); }, resetQuestion() { this.current = null; diff --git a/frontend/src/views/social/VocabLessonView.vue b/frontend/src/views/social/VocabLessonView.vue index af31fa6..74bf20b 100644 --- a/frontend/src/views/social/VocabLessonView.vue +++ b/frontend/src/views/social/VocabLessonView.vue @@ -2701,12 +2701,14 @@ export default { } }, normalizeComparableText(value) { - return String(value || '') + const normalized = String(value || '') .trim() .toLowerCase() - .replace(/[\p{P}]+/gu, ' ') + .normalize('NFKC') + .replace(/[\p{P}\p{S}]+/gu, ' ') .replace(/\s+/g, ' ') .trim(); + return normalized.replace(/\s+/g, ''); }, normalizeVocab(s) { return this.normalizeComparableText(s);