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

Commit 7d6ad59

Browse files
authored
[bf-lu] validate empty phrase list (#972)
* add empty phraseList validation in luisValidator * adjust error msg
1 parent 6acb191 commit 7d6ad59

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

packages/lu/src/parser/lufile/parseFileContents.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ const handlePhraseList = function(parsedContent, entityName, entityType, entityR
14221422
let errorMsg = `Phrase list entity ${entityName} has invalid role definition with roles = ${entityRoles.join(', ')}. Roles are not supported for Phrase Lists`;
14231423
let error = BuildDiagnostic({
14241424
message: errorMsg,
1425-
context: currentLine
1425+
context: range
14261426
})
14271427

14281428
throw (new exception(retCode.errorCode.INVALID_INPUT, error.toString(), [error]));
@@ -1448,7 +1448,7 @@ const handlePhraseList = function(parsedContent, entityName, entityType, entityR
14481448
let pLValues = [];
14491449
for (const phraseListValues of valuesList) {
14501450
phraseListValues.split(/[,;]/g).map(item => item.trim()).forEach(item => pLValues.push(item));
1451-
}
1451+
}
14521452

14531453
let pLEntityExists = parsedContent.LUISJsonStructure.model_features.find(item => item.name == entityName);
14541454
if (pLEntityExists) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ const validateBoundaries = function(luisJSON) {
120120
}
121121
})
122122

123+
// phrase list - phraselist cannot be null or empty.
124+
phraseLists.forEach(item => {
125+
console.log(item.words)
126+
if (item.words === undefined || item.words.trim() === '' || item.words.split(',').length === 0) {
127+
validationError(retCode.errorCode.BOUNDARY_MINMUM_PHRASE_LIMIT, `0 phrases found in phrase list: ${item.name}. Empty phrase list is not allowed.`)
128+
}
129+
})
130+
123131
// Roles - 10 roles per entity
124132
let totalRoles = 0;
125133
["prebuiltEntities", "patternAnyEntities", "regex_entities", "closedLists", "composites", "entities"].forEach(scope => {

packages/lu/src/parser/utils/enums/CLI-errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ module.exports = {
4949
BOUNDARY_FEATURE_PER_MODEL: 517,
5050
BOUNDARY_PARENT_ENTITY_LIMIT:518,
5151
BOUNDARY_TOTAL_ENTITIES_AND_ROLES:519,
52-
BOUNDARY_TOTAL_CLOSED_LISTS:520
52+
BOUNDARY_TOTAL_CLOSED_LISTS:520,
53+
BOUNDARY_MINMUM_PHRASE_LIMIT:521
5354
},
5455
boundaryLimits: {
5556
MAX_NUM_INTENTS: 500,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ describe('Validations for LU content (based on LUIS boundaries)', function () {
201201
})
202202
})
203203

204+
it (`At Least one phrase in any phrase list`, function(done) {
205+
LuisBuilder.fromLUAsync(new Array(new luObj(getMaxPhraseLists(1, 0), 'stdin', true)))
206+
.then(res => done(res))
207+
.catch(err => {
208+
assert.equal(err.errCode, retCode.errorCode.BOUNDARY_MINMUM_PHRASE_LIMIT);
209+
assert(err.text.includes(`0 phrases found in phrase list: PL0. Empty phrase list is not allowed.`));
210+
done();
211+
})
212+
})
213+
204214
})
205215

206216
const getMaxListEntity = function() {

0 commit comments

Comments
 (0)