wingbot 3.27.0-alpha.2 → 3.27.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
CHANGED
|
@@ -58,6 +58,14 @@ const { replaceDiacritics } = require('../utils');
|
|
|
58
58
|
|
|
59
59
|
/** @typedef {import('../Request')} Request */
|
|
60
60
|
|
|
61
|
+
function optionalWrap (l, r, content) {
|
|
62
|
+
const consistent = !l === !r;
|
|
63
|
+
if (consistent) {
|
|
64
|
+
return `(${content})`;
|
|
65
|
+
}
|
|
66
|
+
return `${l || ''}(${content})${r || ''}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
class CustomEntityDetectionModel {
|
|
62
70
|
|
|
63
71
|
/**
|
|
@@ -165,8 +173,9 @@ class CustomEntityDetectionModel {
|
|
|
165
173
|
]);
|
|
166
174
|
|
|
167
175
|
const cleanSubWordResults = subWordResults
|
|
168
|
-
.filter((regular) => regularResults
|
|
169
|
-
.some((e) => e.start < regular.end && e.end > regular.start
|
|
176
|
+
.filter((regular) => !regularResults
|
|
177
|
+
.some((e) => e.start < regular.end && e.end > regular.start
|
|
178
|
+
&& e.end >= regular.end && e.start <= regular.start));
|
|
170
179
|
|
|
171
180
|
subWord.push(...cleanSubWordResults);
|
|
172
181
|
|
|
@@ -352,11 +361,11 @@ class CustomEntityDetectionModel {
|
|
|
352
361
|
* @param {string} text
|
|
353
362
|
* @param {string} [singleEntity]
|
|
354
363
|
* @param {string[]} [expected]
|
|
355
|
-
* @param {DetectedEntity[]} [
|
|
364
|
+
* @param {DetectedEntity[]} [prevEnts] - previously detected entities to include
|
|
356
365
|
* @param {DetectedEntity[]} [subWord] - previously detected entities within words
|
|
357
366
|
* @returns {Promise<DetectedEntity[]>}
|
|
358
367
|
*/
|
|
359
|
-
async resolveEntities (text, singleEntity = null, expected = [],
|
|
368
|
+
async resolveEntities (text, singleEntity = null, expected = [], prevEnts = [], subWord = []) {
|
|
360
369
|
// mark unknown dependencies as resolved
|
|
361
370
|
const resolved = new Set(
|
|
362
371
|
this.getDependentEntities(false)
|
|
@@ -364,6 +373,15 @@ class CustomEntityDetectionModel {
|
|
|
364
373
|
);
|
|
365
374
|
|
|
366
375
|
let missing = Array.from(this._entityDetectors.keys());
|
|
376
|
+
const entities = prevEnts.map((e) => {
|
|
377
|
+
if (typeof e.text === 'string') {
|
|
378
|
+
return e;
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
...e,
|
|
382
|
+
text: text.substring(e.start, e.end)
|
|
383
|
+
};
|
|
384
|
+
});
|
|
367
385
|
|
|
368
386
|
while (missing.length !== 0) {
|
|
369
387
|
let detect = [];
|
|
@@ -498,16 +516,16 @@ class CustomEntityDetectionModel {
|
|
|
498
516
|
return null;
|
|
499
517
|
}
|
|
500
518
|
|
|
501
|
-
let replaced = source.replace(
|
|
519
|
+
let replaced = source.replace(/(\()?@([A-Z0-9-]+)(\))?/g, (value, l, ent, r) => {
|
|
502
520
|
const matchingEntities = entities
|
|
503
|
-
.filter((e) =>
|
|
521
|
+
.filter((e) => e.entity.toUpperCase() === ent)
|
|
504
522
|
.map((e) => this._escapeRegex(e.text, options.replaceDiacritics));
|
|
505
523
|
|
|
506
524
|
if (matchingEntities.length === 0) {
|
|
507
|
-
return
|
|
525
|
+
return optionalWrap(l, r, `@${ent}`);
|
|
508
526
|
}
|
|
509
527
|
matchingEntities.sort((a, z) => z.length - a.length);
|
|
510
|
-
return
|
|
528
|
+
return optionalWrap(l, r, matchingEntities.join('|'));
|
|
511
529
|
});
|
|
512
530
|
|
|
513
531
|
if (options.matchWholeWords && !searchWithinWords) {
|
|
@@ -539,19 +557,15 @@ class CustomEntityDetectionModel {
|
|
|
539
557
|
|
|
540
558
|
if (typeof extractValue === 'function') {
|
|
541
559
|
value = extractValue(match, useEntities);
|
|
542
|
-
} else if (typeof extractValue === 'string' || dependencies.length
|
|
560
|
+
} else if (typeof extractValue === 'string' || dependencies.length > 0) {
|
|
543
561
|
const entityName = typeof extractValue === 'string'
|
|
544
562
|
? extractValue
|
|
545
563
|
: dependencies[0];
|
|
546
564
|
|
|
547
565
|
const entity = this._entityByDependency(useEntities, entityName);
|
|
548
566
|
value = entity ? entity.value : null;
|
|
549
|
-
} else if (entities.length === 0) {
|
|
550
|
-
[value] = match;
|
|
551
567
|
} else {
|
|
552
|
-
value =
|
|
553
|
-
[e.entity]: e.value
|
|
554
|
-
}), {});
|
|
568
|
+
[value] = match;
|
|
555
569
|
}
|
|
556
570
|
|
|
557
571
|
return {
|