wingbot 3.52.1 → 3.52.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/AiMatching.js +29 -10
package/package.json
CHANGED
package/src/AiMatching.js
CHANGED
|
@@ -127,11 +127,19 @@ class AiMatching {
|
|
|
127
127
|
constructor (ai = { confidence: 0.8 }) {
|
|
128
128
|
/**
|
|
129
129
|
* When the entity is optional, the final score should be little bit lower
|
|
130
|
+
* (0.002 by default)
|
|
131
|
+
*
|
|
132
|
+
* @type {number}
|
|
133
|
+
*/
|
|
134
|
+
this.optionalHandicap = 0.002;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* When the entity is equal-optional, the final score should be little bit lower
|
|
130
138
|
* (0.001 by default)
|
|
131
139
|
*
|
|
132
140
|
* @type {number}
|
|
133
141
|
*/
|
|
134
|
-
this.
|
|
142
|
+
this.optionalEqualityHandicap = 0.001;
|
|
135
143
|
|
|
136
144
|
/**
|
|
137
145
|
* When there are additional entities then required add a handicap for each unmatched entity
|
|
@@ -476,8 +484,10 @@ class AiMatching {
|
|
|
476
484
|
useState
|
|
477
485
|
);
|
|
478
486
|
|
|
479
|
-
const allOptional = entities.every((e) => e.optional
|
|
480
|
-
|
|
487
|
+
const allOptional = entities.every((e) => e.optional
|
|
488
|
+
&& (!e.op || reqEntities.every((n) => n.entity !== e.entity)));
|
|
489
|
+
|
|
490
|
+
if (score <= 0 && !allOptional) {
|
|
481
491
|
return null;
|
|
482
492
|
}
|
|
483
493
|
const countOfAdditionalItems = Math.max(
|
|
@@ -489,6 +499,8 @@ class AiMatching {
|
|
|
489
499
|
? score - noIntentHandicap
|
|
490
500
|
: (regexpScore + score) / 2;
|
|
491
501
|
|
|
502
|
+
// console.log({ baseScore, score, allOptional, entities, reqEntities });
|
|
503
|
+
|
|
492
504
|
const matchedEntitiesTextLength = matched.reduce((tot, entity) => (
|
|
493
505
|
typeof entity.end === 'number' && typeof entity.start === 'number' && tot !== null
|
|
494
506
|
? (tot + (entity.end - entity.start))
|
|
@@ -508,6 +520,10 @@ class AiMatching {
|
|
|
508
520
|
finalScore -= (matchedEntitiesTextLength / textLength) * remainingScore;
|
|
509
521
|
}
|
|
510
522
|
|
|
523
|
+
if (finalScore <= 0) {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
|
|
511
527
|
return {
|
|
512
528
|
intent: null,
|
|
513
529
|
entities: matched,
|
|
@@ -586,10 +602,11 @@ class AiMatching {
|
|
|
586
602
|
: (x) => x
|
|
587
603
|
);
|
|
588
604
|
|
|
589
|
-
// console.log({ entitiesScore, handicap, matched, minScore, requestIntent })
|
|
605
|
+
// console.log({ entitiesScore, handicap, matched, minScore, requestIntent });
|
|
590
606
|
|
|
591
|
-
const allOptional = wantedEntities.every((e) => e.optional
|
|
592
|
-
|
|
607
|
+
const allOptional = wantedEntities.every((e) => e.optional
|
|
608
|
+
&& (!e.op || useEntities.every((n) => n.entity !== e.entity)));
|
|
609
|
+
if (entitiesScore <= 0 && !allOptional) {
|
|
593
610
|
return { score: 0, entities: [] };
|
|
594
611
|
}
|
|
595
612
|
|
|
@@ -597,7 +614,7 @@ class AiMatching {
|
|
|
597
614
|
const scoreWithHandicap = normalizedScore - handicap;
|
|
598
615
|
const multiMatchGain = this._getMultiMatchGain(entitiesScore, matched.length, fromState);
|
|
599
616
|
|
|
600
|
-
const score = scoreWithHandicap * multiMatchGain;
|
|
617
|
+
const score = Math.round((scoreWithHandicap * multiMatchGain) * 10000) / 10000;
|
|
601
618
|
|
|
602
619
|
// console.log({ IMS: score, normalizedScore, scoreWithHandicap, multiMatchGain });
|
|
603
620
|
|
|
@@ -674,19 +691,21 @@ class AiMatching {
|
|
|
674
691
|
._entityIsMatching(wanted.op, wanted.compare, undefined, requestState);
|
|
675
692
|
}
|
|
676
693
|
|
|
677
|
-
if (!matching && !wanted.optional) {
|
|
694
|
+
if (!matching && (!wanted.optional || entityExists)) {
|
|
678
695
|
return {
|
|
679
696
|
score: 0, handicap: 0, matched: [], minScore, fromState
|
|
680
697
|
};
|
|
681
698
|
}
|
|
682
699
|
|
|
683
|
-
if (!matching) { // optional
|
|
700
|
+
if (!matching) { // && optional && !entityExists
|
|
684
701
|
handicap += this.redundantEntityHandicap;
|
|
685
702
|
continue;
|
|
686
703
|
}
|
|
687
704
|
|
|
688
705
|
if (wanted.optional) {
|
|
689
|
-
handicap +=
|
|
706
|
+
handicap += wanted.op
|
|
707
|
+
? this.optionalEqualityHandicap
|
|
708
|
+
: this.optionalHandicap;
|
|
690
709
|
}
|
|
691
710
|
|
|
692
711
|
if (wanted.op === COMPARE.NOT_EQUAL) {
|