@xapp/stentor-validation 1.32.137 → 1.32.140
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/lib/IntentValidator.d.ts +7 -0
- package/lib/IntentValidator.js +49 -0
- package/lib/IntentValidator.js.map +1 -0
- package/lib/UtteranceValidator.d.ts +6 -0
- package/lib/UtteranceValidator.js +35 -0
- package/lib/UtteranceValidator.js.map +1 -0
- package/lib/stringSegment.d.ts +11 -0
- package/lib/stringSegment.js +18 -0
- package/lib/stringSegment.js.map +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*! Copyright (c) 2021, XAPPmedia */
|
|
2
|
+
import { Validator, ValidationResult } from "lakmus";
|
|
3
|
+
import { Intent } from "stentor-models";
|
|
4
|
+
export declare class IntentValidator extends Validator<Intent> {
|
|
5
|
+
constructor();
|
|
6
|
+
validate(intent: Intent): ValidationResult;
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2021, XAPPmedia */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.IntentValidator = void 0;
|
|
5
|
+
const lakmus_1 = require("lakmus");
|
|
6
|
+
const stentor_interaction_model_1 = require("stentor-interaction-model");
|
|
7
|
+
const UtteranceValidator_1 = require("./UtteranceValidator");
|
|
8
|
+
class IntentValidator extends lakmus_1.Validator {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
// Required fields
|
|
12
|
+
this.ruleFor(x => x.intentId)
|
|
13
|
+
.notNull()
|
|
14
|
+
.notEmpty();
|
|
15
|
+
}
|
|
16
|
+
validate(intent) {
|
|
17
|
+
const result = super.validate(intent);
|
|
18
|
+
const utterances = new stentor_interaction_model_1.UtteranceGenerator().forIntent(intent);
|
|
19
|
+
const slotNames = [];
|
|
20
|
+
if (utterances.length > 0) {
|
|
21
|
+
utterances.forEach((utterance) => {
|
|
22
|
+
// Validate them
|
|
23
|
+
const utteranceResult = new UtteranceValidator_1.UtteranceValidator().validate(utterance);
|
|
24
|
+
result.errors.push(...utteranceResult.errors);
|
|
25
|
+
// Pull out the slot names
|
|
26
|
+
slotNames.push(...stentor_interaction_model_1.getSlotNames(utterance));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const slots = intent.slots || [];
|
|
30
|
+
// Make sure we don't have any duplicate definitions
|
|
31
|
+
const slotMap = {};
|
|
32
|
+
slots.forEach((slot) => {
|
|
33
|
+
const name = slot.name;
|
|
34
|
+
if (slotMap[name]) {
|
|
35
|
+
result.errors.push(new lakmus_1.ValidationError(`Slot ${name} is defined more than once.`, "slots"));
|
|
36
|
+
}
|
|
37
|
+
slotMap[name] = slot;
|
|
38
|
+
});
|
|
39
|
+
// Every slot name needs a defined slot
|
|
40
|
+
slotNames.forEach((slotName) => {
|
|
41
|
+
if (!slotMap[slotName]) {
|
|
42
|
+
result.errors.push(new lakmus_1.ValidationError(`Slot ${slotName} does not have a defined type.`));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.IntentValidator = IntentValidator;
|
|
49
|
+
//# sourceMappingURL=IntentValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntentValidator.js","sourceRoot":"","sources":["../src/IntentValidator.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAEpC,mCAAsE;AACtE,yEAA6E;AAE7E,6DAA0D;AAE1D,MAAa,eAAgB,SAAQ,kBAAiB;IAClD;QACI,KAAK,EAAE,CAAC;QAER,kBAAkB;QAClB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;aACxB,OAAO,EAAE;aACT,QAAQ,EAAE,CAAC;IACpB,CAAC;IAEM,QAAQ,CAAC,MAAc;QAE1B,MAAM,MAAM,G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,CAAC,CAAC;aAC7F;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAlDD,0CAkDC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2021, XAPPmedia */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.UtteranceValidator = void 0;
|
|
5
|
+
const lakmus_1 = require("lakmus");
|
|
6
|
+
const stringSegment_1 = require("./stringSegment");
|
|
7
|
+
const INVALID_CHARACTERS = ["‘", "’", "“", "”"];
|
|
8
|
+
class UtteranceValidator extends lakmus_1.Validator {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
validate(utterance) {
|
|
13
|
+
const result = new lakmus_1.ValidationResult();
|
|
14
|
+
INVALID_CHARACTERS.forEach((invalid) => {
|
|
15
|
+
const index = utterance.indexOf(invalid);
|
|
16
|
+
if (index > -1) {
|
|
17
|
+
result.errors.push(new lakmus_1.ValidationError(`Utterance contains invalid character "${invalid}" at index ${index}: "${stringSegment_1.stringSegment(utterance, index)}"`));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
// Numbers need not apply
|
|
21
|
+
if (/[0-9]/.test(utterance)) {
|
|
22
|
+
result.errors.push(new lakmus_1.ValidationError(`Utterances cannot contain numbers.`));
|
|
23
|
+
}
|
|
24
|
+
//Look for the case where there is a spacing missing "}${" "}foo"
|
|
25
|
+
if (/}\S/.test(utterance) || /\S\${/.test(utterance)) {
|
|
26
|
+
result.errors.push(new lakmus_1.ValidationError("You must have a space separating slot values in the utterance."));
|
|
27
|
+
}
|
|
28
|
+
if (/[^\u0000-\u00ff]/.test(utterance)) {
|
|
29
|
+
result.errors.push(new lakmus_1.ValidationError("Utterance contains invalid characters."));
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.UtteranceValidator = UtteranceValidator;
|
|
35
|
+
//# sourceMappingURL=UtteranceValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UtteranceValidator.js","sourceRoot":"","sources":["../src/UtteranceValidator.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAEpC,mCAAsE;AACtE,mDAAgD;AAEhD,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAE/C,MAAa,kBAAmB,SAAQ,kBAAiB;IACrD;QACI,KAAK,EAAE,CAAC;IACZ,CAAC;IAEM,QAAQ,CAAC,SAAiB;QAE7B,MAAM,MAAM,GAAG,IAAI,yBAAgB,EAAE,CAAC;QAEtC,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACnC,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACzC,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;gBACZ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,wBAAe,CAAC,yCAAyC,OAAO,cAAc,KAAK,MAAM,6BAAa,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;aACvJ;QACL,CAAC,CAAC,CAAC;QAEH,yBAAyB;QACzB,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,wBAAe,CAAC,oCAAoC,CAAC,CAAC,CAAC;SACjF;QAED,iEAAiE;QACjE,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAClD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,wBAAe,CAAC,gEAAgE,CAAC,CAAC,CAAA;SAC5G;QAED,IAAI,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACpC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,wBAAe,CAAC,wCAAwC,CAAC,CAAC,CAAA;SACpF;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAhCD,gDAgCC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*! Copyright (c) 2021, XAPPmedia */
|
|
2
|
+
/**
|
|
3
|
+
* Returns a segment of the given string.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @param {string} input
|
|
7
|
+
* @param {number} index
|
|
8
|
+
* @param {number} [window=4]
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export declare function stringSegment(input: string, index: number, window?: number): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2021, XAPPmedia */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.stringSegment = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Returns a segment of the given string.
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @param {string} input
|
|
10
|
+
* @param {number} index
|
|
11
|
+
* @param {number} [window=4]
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
function stringSegment(input, index, window = 4) {
|
|
15
|
+
return input.substring(index - window, index + window);
|
|
16
|
+
}
|
|
17
|
+
exports.stringSegment = stringSegment;
|
|
18
|
+
//# sourceMappingURL=stringSegment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringSegment.js","sourceRoot":"","sources":["../src/stringSegment.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAEpC;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,KAAa,EAAE,KAAa,EAAE,SAAiB,CAAC;IAC1E,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;AAC3D,CAAC;AAFD,sCAEC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "restricted"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.32.
|
|
7
|
+
"version": "1.32.140",
|
|
8
8
|
"description": "Model validation for Stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -20,18 +20,20 @@
|
|
|
20
20
|
"@xapp/config": "0.2.3",
|
|
21
21
|
"chai": "4.3.4",
|
|
22
22
|
"mocha": "9.0.0",
|
|
23
|
-
"stentor-guards": "1.42.
|
|
24
|
-
"stentor-
|
|
25
|
-
"stentor-
|
|
26
|
-
"stentor-
|
|
23
|
+
"stentor-guards": "1.42.12",
|
|
24
|
+
"stentor-interaction-model": "1.42.13",
|
|
25
|
+
"stentor-logger": "1.42.13",
|
|
26
|
+
"stentor-models": "1.42.12",
|
|
27
|
+
"stentor-utils": "1.42.13",
|
|
27
28
|
"ts-node": "9.1.1",
|
|
28
|
-
"typescript": "4.3.
|
|
29
|
+
"typescript": "4.3.3"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"lakmus": "0.3.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"stentor-guards": "1.x",
|
|
36
|
+
"stentor-interaction-model": "1.x",
|
|
35
37
|
"stentor-logger": "1.x",
|
|
36
38
|
"stentor-models": "1.x",
|
|
37
39
|
"stentor-utils": "1.x"
|
|
@@ -41,5 +43,5 @@
|
|
|
41
43
|
"clean": "rm -rf ./lib/*",
|
|
42
44
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
43
45
|
},
|
|
44
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "944655122215de46116dce222e7c7f0feb7210b0"
|
|
45
47
|
}
|