wingbot 3.36.0 → 3.36.1
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 +4 -0
- package/src/AiMatching.js +32 -8
- package/src/Request.js +3 -2
package/package.json
CHANGED
package/src/Ai.js
CHANGED
package/src/AiMatching.js
CHANGED
|
@@ -132,6 +132,12 @@ class AiMatching {
|
|
|
132
132
|
* @type {number}
|
|
133
133
|
*/
|
|
134
134
|
this.multiMatchGain = 1.2;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Score of a context entity within a conversation state
|
|
138
|
+
* (1 by default)
|
|
139
|
+
*/
|
|
140
|
+
this.stateEntityScore = 1;
|
|
135
141
|
}
|
|
136
142
|
|
|
137
143
|
get redundantHandicap () {
|
|
@@ -480,6 +486,10 @@ class AiMatching {
|
|
|
480
486
|
return winningIntent;
|
|
481
487
|
}
|
|
482
488
|
|
|
489
|
+
_getMultiMatchGain (entitiesScore, matchedCount, fromState = 0) {
|
|
490
|
+
return (this.multiMatchGain * entitiesScore) ** (matchedCount - fromState);
|
|
491
|
+
}
|
|
492
|
+
|
|
483
493
|
/**
|
|
484
494
|
*
|
|
485
495
|
* @private
|
|
@@ -505,7 +515,7 @@ class AiMatching {
|
|
|
505
515
|
}
|
|
506
516
|
|
|
507
517
|
const {
|
|
508
|
-
score: entitiesScore, handicap, matched, minScore
|
|
518
|
+
score: entitiesScore, handicap, matched, minScore, fromState
|
|
509
519
|
} = this
|
|
510
520
|
._entityMatching(
|
|
511
521
|
wantedEntities,
|
|
@@ -516,13 +526,20 @@ class AiMatching {
|
|
|
516
526
|
: (x) => x
|
|
517
527
|
);
|
|
518
528
|
|
|
529
|
+
// console.log({ entitiesScore, handicap, matched, minScore, requestIntent })
|
|
530
|
+
|
|
519
531
|
const allOptional = wantedEntities.every((e) => e.optional);
|
|
520
532
|
if (entitiesScore === 0 && !allOptional) {
|
|
521
533
|
return { score: 0, entities: [] };
|
|
522
534
|
}
|
|
523
535
|
|
|
524
|
-
const
|
|
525
|
-
|
|
536
|
+
const normalizedScore = Math.min(minScore + (handicap / 2), requestIntent.score);
|
|
537
|
+
const scoreWithHandicap = normalizedScore - handicap;
|
|
538
|
+
const multiMatchGain = this._getMultiMatchGain(entitiesScore, matched.length, fromState);
|
|
539
|
+
|
|
540
|
+
const score = scoreWithHandicap * multiMatchGain;
|
|
541
|
+
|
|
542
|
+
// console.log({ IMS: score, normalizedScore, scoreWithHandicap, multiMatchGain });
|
|
526
543
|
|
|
527
544
|
return {
|
|
528
545
|
score,
|
|
@@ -537,7 +554,7 @@ class AiMatching {
|
|
|
537
554
|
* @param {Entity[]} requestEntities
|
|
538
555
|
* @param {object} [requestState]
|
|
539
556
|
* @param {Function} [scoreFn]
|
|
540
|
-
* @returns {{score:
|
|
557
|
+
* @returns {{score:number,handicap:number, matched:Entity[],minScore:number,fromState:number}}
|
|
541
558
|
*/
|
|
542
559
|
_entityMatching (wantedEntities, requestEntities = [], requestState = {}, scoreFn = (x) => x) {
|
|
543
560
|
const occurences = new Map();
|
|
@@ -546,6 +563,7 @@ class AiMatching {
|
|
|
546
563
|
let handicap = 0;
|
|
547
564
|
let sum = 0;
|
|
548
565
|
let minScore = 1;
|
|
566
|
+
let fromState = 0;
|
|
549
567
|
|
|
550
568
|
for (const wanted of wantedEntities) {
|
|
551
569
|
const usedIndexes = occurences.has(wanted.entity)
|
|
@@ -579,9 +597,11 @@ class AiMatching {
|
|
|
579
597
|
requestEntity = {
|
|
580
598
|
value: requestState[`@${wanted.entity}`],
|
|
581
599
|
entity: wanted.entity,
|
|
582
|
-
score:
|
|
600
|
+
score: this.stateEntityScore
|
|
583
601
|
};
|
|
584
602
|
|
|
603
|
+
fromState += 1;
|
|
604
|
+
|
|
585
605
|
matching = this._entityIsMatching(
|
|
586
606
|
wanted.op,
|
|
587
607
|
wanted.compare,
|
|
@@ -596,7 +616,7 @@ class AiMatching {
|
|
|
596
616
|
|
|
597
617
|
if (!matching && !wanted.optional) {
|
|
598
618
|
return {
|
|
599
|
-
score: 0, handicap: 0, matched: [], minScore
|
|
619
|
+
score: 0, handicap: 0, matched: [], minScore, fromState
|
|
600
620
|
};
|
|
601
621
|
}
|
|
602
622
|
|
|
@@ -636,11 +656,15 @@ class AiMatching {
|
|
|
636
656
|
}
|
|
637
657
|
}
|
|
638
658
|
|
|
639
|
-
handicap
|
|
659
|
+
// console.log({ sum, handicap, rl: requestEntities.length, ml: matched.length });
|
|
660
|
+
|
|
661
|
+
// @todo - neni mozne, by doslo k negativnimu handicapu
|
|
662
|
+
handicap += (requestEntities.length + fromState - matched.length)
|
|
663
|
+
* this.redundantEntityHandicap;
|
|
640
664
|
const score = matched.length === 0 ? 0 : sum / matched.length;
|
|
641
665
|
|
|
642
666
|
return {
|
|
643
|
-
score, handicap, matched, minScore
|
|
667
|
+
score, handicap, matched, minScore, fromState
|
|
644
668
|
};
|
|
645
669
|
}
|
|
646
670
|
|
package/src/Request.js
CHANGED
|
@@ -1227,7 +1227,6 @@ class Request {
|
|
|
1227
1227
|
// to match the local context intent
|
|
1228
1228
|
const localRegexToMatch = this._getLocalPathRegexp();
|
|
1229
1229
|
|
|
1230
|
-
const localEnhancement = (1 - Ai.ai.confidence) / 2;
|
|
1231
1230
|
for (const gi of this.globalIntents.values()) {
|
|
1232
1231
|
const pathMatches = localRegexToMatch && localRegexToMatch.exec(gi.action);
|
|
1233
1232
|
if (gi.local && !pathMatches) {
|
|
@@ -1235,7 +1234,9 @@ class Request {
|
|
|
1235
1234
|
}
|
|
1236
1235
|
const intent = gi.matcher(this, null, true);
|
|
1237
1236
|
if (intent !== null) {
|
|
1238
|
-
const sort = intent.score + (pathMatches
|
|
1237
|
+
const sort = intent.score + (pathMatches
|
|
1238
|
+
? Ai.ai.localEnhancement
|
|
1239
|
+
: 0);
|
|
1239
1240
|
// console.log(sort, wi.intent);
|
|
1240
1241
|
aiActions.push({
|
|
1241
1242
|
...gi,
|