Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 8d7ee7f

Browse files
authored
Fix max features numbers validation issue (#1131)
* fix max number of features issue * add test cases to test the features boundary
1 parent 62f691e commit 8d7ee7f

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

packages/lu/src/parser/luis/luisValidator.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ const validateBoundaries = function(luisJSON) {
146146
// features - Maximum number of models that can be used as a descriptor (feature) to a specific model to be 10 models.
147147
["intents", "entities"].forEach(scope => {
148148
luisJSON[scope].forEach(item => {
149-
if (item.features && item.features.length > retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL) {
150-
validationError(retCode.errorCode.BOUNDARY_FEATURE_PER_MODEL, `${scope.substring(0, scope.length - 1)} ${item.name} has ${item.features.length} descriptors (feature). At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} is allowed.`)
149+
if (item.features && item.features.filter(f => f.modelName).length > retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL) {
150+
validationError(retCode.errorCode.BOUNDARY_FEATURE_PER_MODEL, `${scope.substring(0, scope.length - 1)} ${item.name} has ${item.features.filter(f => f.modelName).length} model descriptors (feature). At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} is allowed.`)
151+
}
152+
153+
if (item.features && item.features.filter(f => f.featureName).length > retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL) {
154+
validationError(retCode.errorCode.BOUNDARY_FEATURE_PER_MODEL, `${scope.substring(0, scope.length - 1)} ${item.name} has ${item.features.filter(f => f.featureName).length} phraselist descriptors (feature). At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} is allowed.`)
151155
}
152156
})
153157
})

packages/lu/test/parser/lufile/luis.boundary.test.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,38 @@ describe('Validations for LU content (based on LUIS boundaries)', function () {
151151
})
152152
})
153153

154-
it (`At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} descriptors per model`, function(done) {
154+
it (`At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} model descriptors per model`, function(done) {
155155
LuisBuilder.fromLUAsync(new Array(new luObj(getEntityWithFeatures())))
156156
.then(res => done(res))
157157
.catch(err => {
158158
assert.equal(err.errCode, retCode.errorCode.BOUNDARY_FEATURE_PER_MODEL);
159-
assert(err.text.includes(`At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} is allowed.`));
159+
assert(err.text.includes(`has ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL + 1} model descriptors (feature). At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} is allowed.`));
160160
done();
161161
})
162162
})
163163

164+
it (`At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} phraselist descriptors per model`, function(done) {
165+
166+
LuisBuilder.fromLUAsync(new Array(new luObj(getEntityWithFeatures(-1, retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL))))
167+
.then(res => done(res))
168+
.catch(err => {
169+
assert.equal(err.errCode, retCode.errorCode.BOUNDARY_FEATURE_PER_MODEL);
170+
assert(err.text.includes(`has ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL + 1} phraselist descriptors (feature). At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} is allowed.`));
171+
done();
172+
})
173+
})
174+
175+
it (`At most ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} model descriptors and ${retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL} phraselist descriptors per model(total 20)`, function(done) {
176+
177+
LuisBuilder.fromLUAsync(new Array(new luObj(getEntityWithFeatures(retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL - 1, retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL - 1))))
178+
.then(res => {
179+
assert.equal(res.entities.length, retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL + 1);
180+
assert.equal(res.entities[10].name, 'testEntity');
181+
assert.equal(res.entities[10].features.length, retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL * 2);
182+
done()
183+
}).catch(err => done(err))
184+
})
185+
164186
it (`At most ${retCode.boundaryLimits.MAX_NUM_PARENT_ENTITIES} parent nodes in an ML entitiy`, function(done) {
165187
LuisBuilder.fromLUAsync(new Array(new luObj(getMLEntity())))
166188
.then(res => done(res))
@@ -242,15 +264,23 @@ const getMLEntity = function() {
242264
}
243265
return fc;
244266
}
245-
const getEntityWithFeatures = function() {
267+
const getEntityWithFeatures = function(numModelFeatures = retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL, numberPhraselistFeatures = -1) {
246268
let fc = '';
247269
let descriptorsList = [];
248-
for (var i = 0; i <= retCode.boundaryLimits.MAX_NUM_DESCRIPTORS_PER_MODEL; i++) {
270+
for (var i = 0; i <= numModelFeatures; i++) {
249271
let newEntityName = `entity${i}`;
250272
descriptorsList.push(newEntityName);
251273
fc += `
252274
@ ml ${newEntityName}`;
253275
}
276+
277+
for (var i = 0; i <= numberPhraselistFeatures; i++) {
278+
descriptorsList.push(`PL${i}`);
279+
fc += `
280+
@ phraselist PL${i} =
281+
- phrase,phrase-last`;
282+
}
283+
254284
fc += `
255285
@ ml testEntity usesFeatures ${descriptorsList.join(',')}
256286
`;

0 commit comments

Comments
 (0)