wingbot 3.37.2 → 3.37.3
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/Ai.js +2 -2
- package/src/AiMatching.js +32 -3
package/package.json
CHANGED
package/src/Ai.js
CHANGED
|
@@ -49,7 +49,7 @@ let uq = 1;
|
|
|
49
49
|
*/
|
|
50
50
|
class Ai {
|
|
51
51
|
|
|
52
|
-
constructor (
|
|
52
|
+
constructor () {
|
|
53
53
|
this._keyworders = new Map();
|
|
54
54
|
|
|
55
55
|
/**
|
|
@@ -111,7 +111,7 @@ class Ai {
|
|
|
111
111
|
*
|
|
112
112
|
* @type {AiMatching}
|
|
113
113
|
*/
|
|
114
|
-
this.matcher =
|
|
114
|
+
this.matcher = new AiMatching(this);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
package/src/AiMatching.js
CHANGED
|
@@ -91,6 +91,11 @@ const COMPARE = {
|
|
|
91
91
|
* @prop {object} [state]
|
|
92
92
|
*/
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {object} ConfidenceProvider
|
|
96
|
+
* @prop {number} confidence
|
|
97
|
+
*/
|
|
98
|
+
|
|
94
99
|
/**
|
|
95
100
|
* @class {AiMatching}
|
|
96
101
|
*
|
|
@@ -98,7 +103,11 @@ const COMPARE = {
|
|
|
98
103
|
*/
|
|
99
104
|
class AiMatching {
|
|
100
105
|
|
|
101
|
-
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @param {ConfidenceProvider} ai
|
|
109
|
+
*/
|
|
110
|
+
constructor (ai = { confidence: 0.8 }) {
|
|
102
111
|
/**
|
|
103
112
|
* When the entity is optional, the final score should be little bit lower
|
|
104
113
|
* (0.001 by default)
|
|
@@ -138,6 +147,8 @@ class AiMatching {
|
|
|
138
147
|
* (1 by default)
|
|
139
148
|
*/
|
|
140
149
|
this.stateEntityScore = 1;
|
|
150
|
+
|
|
151
|
+
this._ai = ai;
|
|
141
152
|
}
|
|
142
153
|
|
|
143
154
|
get redundantHandicap () {
|
|
@@ -447,11 +458,29 @@ class AiMatching {
|
|
|
447
458
|
? score - noIntentHandicap
|
|
448
459
|
: (regexpScore + score) / 2;
|
|
449
460
|
|
|
461
|
+
const matchedEntitiesTextLength = matched.reduce((tot, entity) => (
|
|
462
|
+
typeof entity.end === 'number' && typeof entity.start === 'number' && tot !== null
|
|
463
|
+
? (tot + (entity.end - entity.start))
|
|
464
|
+
: null
|
|
465
|
+
), 0);
|
|
466
|
+
|
|
467
|
+
let finalScore = (baseScore - handicap)
|
|
468
|
+
* (this.multiMatchGain ** countOfAdditionalItems);
|
|
469
|
+
|
|
470
|
+
const textLength = req.text().length;
|
|
471
|
+
|
|
472
|
+
if (matchedEntitiesTextLength && textLength) {
|
|
473
|
+
const remainingScore = Math.max(0, Math.min(1, finalScore) - (
|
|
474
|
+
this._ai.confidence + this.redundantEntityHandicap
|
|
475
|
+
));
|
|
476
|
+
|
|
477
|
+
finalScore -= (matchedEntitiesTextLength / textLength) * remainingScore;
|
|
478
|
+
}
|
|
479
|
+
|
|
450
480
|
return {
|
|
451
481
|
intent: null,
|
|
452
482
|
entities: matched,
|
|
453
|
-
score:
|
|
454
|
-
* (this.multiMatchGain ** countOfAdditionalItems)
|
|
483
|
+
score: finalScore
|
|
455
484
|
};
|
|
456
485
|
}
|
|
457
486
|
|