fix: nitpicks

This commit is contained in:
Mohamed Marrouchi
2025-05-12 17:19:06 +01:00
parent 8df658b429
commit 27cf8a343c
2 changed files with 16 additions and 9 deletions

View File

@@ -181,7 +181,9 @@ export class BlockService extends BaseService<
const scoredEntities =
await this.nlpService.computePredictionScore(nlp);
block = this.matchBestNLP(filteredBlocks, scoredEntities);
if (scoredEntities.entities.length > 0) {
block = this.matchBestNLP(filteredBlocks, scoredEntities);
}
}
}
@@ -395,10 +397,8 @@ export class BlockService extends BaseService<
prediction: NLU.ScoredEntities,
penaltyFactor = 0.95,
): number {
if (!patterns.length) {
throw new Error(
'Unable to compute the NLU match score : patterns are missing',
);
if (!patterns.length || !prediction.entities.length) {
return 0;
}
return patterns.reduce((score, pattern) => {
@@ -456,9 +456,7 @@ export class BlockService extends BaseService<
penaltyFactor: number = 0.95,
): number {
if (!entity || !pattern) {
throw new Error(
'Unable to compute pattern score : missing entity/pattern',
);
return 0;
}
// In case the pattern matches the entity regardless of the value (any)

View File

@@ -27,7 +27,16 @@ export const mockNlpGreetingNameEntities: NLU.ScoredEntities = {
export const mockNlpGreetingFullNameEntities: NLU.ParseEntities = {
entities: [
...mockNlpGreetingNameEntities.entities,
{
entity: 'intent',
value: 'greeting',
confidence: 0.999,
},
{
entity: 'firstname',
value: 'jhon',
confidence: 0.5,
},
{
entity: 'lastname',
value: 'doe',