From 949fee281ad8d20c1ea43ea6932b1acd95f17aa7 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Tue, 13 May 2025 15:20:50 +0100 Subject: [PATCH] fix: minor fixes --- .../lib/__test__/base-nlp-helper.spec.ts | 31 +++++++++++++++++++ api/src/helper/lib/base-nlp-helper.ts | 2 +- .../nlp/components/NlpValueForm.tsx | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/api/src/helper/lib/__test__/base-nlp-helper.spec.ts b/api/src/helper/lib/__test__/base-nlp-helper.spec.ts index e9f4b88b..e2b958d9 100644 --- a/api/src/helper/lib/__test__/base-nlp-helper.spec.ts +++ b/api/src/helper/lib/__test__/base-nlp-helper.spec.ts @@ -326,6 +326,37 @@ describe('BaseNlpHelper', () => { ]); }); + it('should respect metadata stripDiacritics', () => { + const entity: NlpEntityFull = { + name: 'keyword', + values: [ + { + value: 'word', + metadata: { + pattern: '".+"', + toLowerCase: true, + removeSpaces: true, + stripDiacritics: true, + }, + }, + ], + } as NlpEntityFull; + + const result = helper.extractPatternBasedSlots( + 'The word "où" (where)', + entity, + ); + expect(result).toEqual([ + { + entity: 'keyword', + value: '"ou"', + start: 9, + end: 13, + confidence: 1, + }, + ]); + }); + it('should return empty array if no values', () => { const result = helper.extractPatternBasedSlots('test', { name: 'noop', diff --git a/api/src/helper/lib/base-nlp-helper.ts b/api/src/helper/lib/base-nlp-helper.ts index 94b766bc..b1928c2f 100644 --- a/api/src/helper/lib/base-nlp-helper.ts +++ b/api/src/helper/lib/base-nlp-helper.ts @@ -321,7 +321,7 @@ export default abstract class BaseNlpHelper< } if (patternValue.metadata?.stripDiacritics) { - value = text.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); + value = value.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); } return { diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index 113e154d..45233cf3 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -35,7 +35,7 @@ const getDefaultNlpMetadata = ( ): INlpMetadata => { if (nlpEntity?.lookups.includes(LookupStrategy.pattern)) { return { - pattern: "//", + pattern: "", wordBoundary: true, removeSpaces: false, toLowerCase: false,