wingbot 3.67.22 → 3.67.24
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 +8 -2
- package/src/AiMatching.js +18 -8
- package/src/BotApp.js +23 -14
- package/src/Request.js +1 -1
- package/src/Tester.js +10 -2
- package/src/fuzzy/factoryFuzzySearch.js +1 -1
package/package.json
CHANGED
package/src/Ai.js
CHANGED
|
@@ -553,9 +553,15 @@ class Ai {
|
|
|
553
553
|
};
|
|
554
554
|
}
|
|
555
555
|
|
|
556
|
-
ruleIsMatching (intent, req, stateless = false) {
|
|
556
|
+
ruleIsMatching (intent, req, stateless = false, noEntityThreshold = false) {
|
|
557
557
|
const rules = this.matcher.preprocessRule(intent);
|
|
558
|
-
const winningIntent = this.matcher.match(
|
|
558
|
+
const winningIntent = this.matcher.match(
|
|
559
|
+
req,
|
|
560
|
+
rules,
|
|
561
|
+
stateless,
|
|
562
|
+
undefined,
|
|
563
|
+
noEntityThreshold
|
|
564
|
+
);
|
|
559
565
|
|
|
560
566
|
if (!winningIntent || winningIntent.score < this.threshold) {
|
|
561
567
|
return null;
|
package/src/AiMatching.js
CHANGED
|
@@ -467,9 +467,10 @@ class AiMatching {
|
|
|
467
467
|
* @param {PreprocessorOutput} rule
|
|
468
468
|
* @param {boolean} [stateless]
|
|
469
469
|
* @param {Entity[]} [reqEntities]
|
|
470
|
+
* @param {boolean} [noEntityThreshold]
|
|
470
471
|
* @returns {Intent|null}
|
|
471
472
|
*/
|
|
472
|
-
match (req, rule, stateless = false, reqEntities = req.entities) {
|
|
473
|
+
match (req, rule, stateless = false, reqEntities = req.entities, noEntityThreshold = false) {
|
|
473
474
|
const { regexps, intents, entities } = rule;
|
|
474
475
|
|
|
475
476
|
const noIntentHandicap = req.intents.length === 0 ? 0 : this.redundantIntentHandicap;
|
|
@@ -510,7 +511,10 @@ class AiMatching {
|
|
|
510
511
|
textLength,
|
|
511
512
|
entities,
|
|
512
513
|
reqEntities,
|
|
513
|
-
useState
|
|
514
|
+
useState,
|
|
515
|
+
undefined,
|
|
516
|
+
undefined,
|
|
517
|
+
noEntityThreshold
|
|
514
518
|
);
|
|
515
519
|
|
|
516
520
|
const allOptional = entities.every((e) => e.optional
|
|
@@ -576,7 +580,8 @@ class AiMatching {
|
|
|
576
580
|
requestIntent,
|
|
577
581
|
entities,
|
|
578
582
|
req,
|
|
579
|
-
useState
|
|
583
|
+
useState,
|
|
584
|
+
noEntityThreshold
|
|
580
585
|
);
|
|
581
586
|
|
|
582
587
|
if (score > max) {
|
|
@@ -610,6 +615,7 @@ class AiMatching {
|
|
|
610
615
|
* @param {EntityExpression[]} wantedEntities
|
|
611
616
|
* @param {AIRequest} req
|
|
612
617
|
* @param {object} useState
|
|
618
|
+
* @param {boolean} [noEntityThreshold]
|
|
613
619
|
* @returns {{score:number,entities:Entity[]}}
|
|
614
620
|
*/
|
|
615
621
|
_intentMatchingScore (
|
|
@@ -618,7 +624,8 @@ class AiMatching {
|
|
|
618
624
|
requestIntent,
|
|
619
625
|
wantedEntities,
|
|
620
626
|
req,
|
|
621
|
-
useState
|
|
627
|
+
useState,
|
|
628
|
+
noEntityThreshold = false
|
|
622
629
|
) {
|
|
623
630
|
if (wantedIntent !== requestIntent.intent) {
|
|
624
631
|
return { score: 0, entities: [] };
|
|
@@ -644,7 +651,8 @@ class AiMatching {
|
|
|
644
651
|
requestIntent.entities
|
|
645
652
|
? (x) => Math.atan((x - 0.76) * 40) / Math.atan((1 - 0.76) * 40)
|
|
646
653
|
: (x) => x,
|
|
647
|
-
req.entities
|
|
654
|
+
req.entities,
|
|
655
|
+
noEntityThreshold
|
|
648
656
|
);
|
|
649
657
|
|
|
650
658
|
// eslint-disable-next-line max-len,object-curly-newline
|
|
@@ -680,7 +688,8 @@ class AiMatching {
|
|
|
680
688
|
* @param {Entity[]} requestEntities
|
|
681
689
|
* @param {object} [requestState]
|
|
682
690
|
* @param {Function} [scoreFn]
|
|
683
|
-
* @param {Entity[]} allEntities
|
|
691
|
+
* @param {Entity[]} [allEntities]
|
|
692
|
+
* @param {boolean} [noEntityThreshold]
|
|
684
693
|
*
|
|
685
694
|
* @returns {EntityMatchingResult}
|
|
686
695
|
*/
|
|
@@ -690,7 +699,8 @@ class AiMatching {
|
|
|
690
699
|
requestEntities = [],
|
|
691
700
|
requestState = {},
|
|
692
701
|
scoreFn = (x) => x,
|
|
693
|
-
allEntities = requestEntities
|
|
702
|
+
allEntities = requestEntities,
|
|
703
|
+
noEntityThreshold = false
|
|
694
704
|
) {
|
|
695
705
|
const occurences = new Map();
|
|
696
706
|
|
|
@@ -713,7 +723,7 @@ class AiMatching {
|
|
|
713
723
|
.findIndex((e, i) => {
|
|
714
724
|
if (e.entity !== wanted.entity
|
|
715
725
|
|| usedIndexes.includes(i)
|
|
716
|
-
|| e.score < ENTITY_OK) {
|
|
726
|
+
|| (!noEntityThreshold && e.score < ENTITY_OK)) {
|
|
717
727
|
return false;
|
|
718
728
|
}
|
|
719
729
|
entityExists = true;
|
package/src/BotApp.js
CHANGED
|
@@ -166,24 +166,33 @@ class BotApp {
|
|
|
166
166
|
* @param {Responder} res
|
|
167
167
|
*/
|
|
168
168
|
afterProcessMessage (req, res) {
|
|
169
|
-
|
|
170
|
-
const updatedVariables = Object.keys(res.newState)
|
|
171
|
-
.filter((key) => key.match(/^§/) && wasSet[key] !== res.newState[key]);
|
|
172
|
-
|
|
173
|
-
if (updatedVariables.length !== 0) {
|
|
174
|
-
const setContext = updatedVariables
|
|
175
|
-
.reduce((o, key) => Object.assign(o, {
|
|
176
|
-
[key.replace(/^§/, '')]: res.newState[key]
|
|
177
|
-
}), {});
|
|
178
|
-
|
|
179
|
-
res.send({
|
|
180
|
-
set_context: setContext
|
|
181
|
-
});
|
|
182
|
-
}
|
|
169
|
+
BotApp.sendContext(req, res);
|
|
183
170
|
}
|
|
184
171
|
};
|
|
185
172
|
}
|
|
186
173
|
|
|
174
|
+
/**
|
|
175
|
+
*
|
|
176
|
+
* @param {Request} req
|
|
177
|
+
* @param {Responder} res
|
|
178
|
+
*/
|
|
179
|
+
static sendContext (req, res) {
|
|
180
|
+
const wasSet = req.getSetContext(true);
|
|
181
|
+
const updatedVariables = Object.keys(res.newState)
|
|
182
|
+
.filter((key) => key.match(/^§/) && wasSet[key] !== res.newState[key]);
|
|
183
|
+
|
|
184
|
+
if (updatedVariables.length !== 0) {
|
|
185
|
+
const setContext = updatedVariables
|
|
186
|
+
.reduce((o, key) => Object.assign(o, {
|
|
187
|
+
[key.replace(/^§/, '')]: res.newState[key]
|
|
188
|
+
}), {});
|
|
189
|
+
|
|
190
|
+
res.send({
|
|
191
|
+
set_context: setContext
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
187
196
|
/**
|
|
188
197
|
* Get the processor instance
|
|
189
198
|
*
|
package/src/Request.js
CHANGED
|
@@ -1649,7 +1649,7 @@ It looks like the bot isn't connected to class BotApp or the Processor is used w
|
|
|
1649
1649
|
entity,
|
|
1650
1650
|
value,
|
|
1651
1651
|
score = 1,
|
|
1652
|
-
entityScore = Math.max(score, 0.
|
|
1652
|
+
entityScore = Math.max(score, 0.835),
|
|
1653
1653
|
timestamp = makeTimestamp()
|
|
1654
1654
|
) {
|
|
1655
1655
|
const res = Request.text(senderId, text, timestamp);
|
package/src/Tester.js
CHANGED
|
@@ -461,13 +461,21 @@ class Tester {
|
|
|
461
461
|
* @param {string} [value]
|
|
462
462
|
* @param {string} [text]
|
|
463
463
|
* @param {number} [score]
|
|
464
|
+
* @param {number} [entityScore]
|
|
464
465
|
* @returns {Promise}
|
|
465
466
|
*
|
|
466
467
|
* @memberOf Tester
|
|
467
468
|
*/
|
|
468
|
-
intentWithEntity (
|
|
469
|
+
intentWithEntity (
|
|
470
|
+
intent,
|
|
471
|
+
entity,
|
|
472
|
+
value = entity,
|
|
473
|
+
text = intent,
|
|
474
|
+
score = 1,
|
|
475
|
+
entityScore = score
|
|
476
|
+
) {
|
|
469
477
|
return this.processMessage(Request
|
|
470
|
-
.intentWithEntity(this.senderId, text, intent, entity, value, score));
|
|
478
|
+
.intentWithEntity(this.senderId, text, intent, entity, value, score, entityScore));
|
|
471
479
|
}
|
|
472
480
|
|
|
473
481
|
/**
|
|
@@ -41,7 +41,7 @@ function getIndexesToIterate (ngrams, tfEntry) {
|
|
|
41
41
|
function searchFnFactory (indexMap, ngramCounts, entities, maxIdf, {
|
|
42
42
|
stemmer = null,
|
|
43
43
|
keepMultipleValues = false,
|
|
44
|
-
threshold = 0.
|
|
44
|
+
threshold = 0.835,
|
|
45
45
|
limit = undefined
|
|
46
46
|
}, hasFuzzyMultiplier = false) {
|
|
47
47
|
/** @type {WordEntityDetector} */
|