in parsers/LU/JS/packages/lu/src/parser/lufile/parseFileContents.js [1374:1443]
const handlePhraseList = function(parsedContent, entityName, entityType, entityRoles, valuesList, range) {
let isPLEnabledForAllModels = undefined;
let isPLEnabled = undefined;
if (entityRoles.length !== 0) {
// Phrase lists cannot have roles; however we will allow inline definition of enabledForAllModels as well as disabled as a property on phrase list.
entityRoles.forEach(item => {
if (item.toLowerCase() === PLCONSTS.DISABLED) {
isPLEnabled = false;
} else if (item.toLowerCase() === PLCONSTS.ENABLEDFORALLMODELS) {
isPLEnabledForAllModels = true;
} else if (item.toLowerCase() === PLCONSTS.DISABLEDFORALLMODELS) {
isPLEnabledForAllModels = false;
} else if (item.toLowerCase() === PLCONSTS.INTERCHANGEABLE) {
entityName += item;
} else {
let errorMsg = `Phrase list entity ${entityName} has invalid role definition with roles = ${entityRoles.join(', ')}. Roles are not supported for Phrase Lists`;
let error = BuildDiagnostic({
message: errorMsg,
context: currentLine
})
throw (new exception(retCode.errorCode.INVALID_INPUT, error.toString(), [error]));
}
})
}
// check if this phraselist entity is already labelled in an utterance and or added as a simple entity. if so, throw an error.
try {
let rolesImport = VerifyAndUpdateSimpleEntityCollection(parsedContent, entityName, 'Phrase List');
if (rolesImport.length !== 0) {
rolesImport.forEach(role => !entityRoles.includes(role) ? entityRoles.push(role) : undefined);
}
} catch (err) {
throw (err);
}
// is this interchangeable?
let intc = false;
if (entityType && entityName.toLowerCase().includes('interchangeable')) {
intc = true;
entityName = entityName.split(/\(.*\)/g)[0]
}
// add this to phraseList if it doesnt exist
let pLValues = [];
for (const phraseListValues of valuesList) {
phraseListValues.split(/[,;]/g).map(item => item.trim()).forEach(item => pLValues.push(item));
}
let pLEntityExists = parsedContent.LUISJsonStructure.model_features.find(item => item.name == entityName);
if (pLEntityExists) {
if (entityType) {
if (pLEntityExists.mode !== intc) {
let errorMsg = `Phrase list: "${entityName}" has conflicting definitions. One marked interchangeable and another not interchangeable`;
let error = BuildDiagnostic({
message: errorMsg,
range: range
})
throw (new exception(retCode.errorCode.INVALID_INPUT, error.toString(), [error]));
}
}
let wordsSplit = pLEntityExists.words.split(',');
pLValues.forEach(function (plValueItem) {
if (!wordsSplit.includes(plValueItem)) pLEntityExists.words += (pLEntityExists.words !== '' ? ',' : '') + plValueItem;
})
} else {
pLEntityExists = new helperClass.modelObj(entityName, intc, pLValues.join(','), true);
parsedContent.LUISJsonStructure.model_features.push(pLEntityExists);
}
if (isPLEnabled !== undefined) pLEntityExists.activated = isPLEnabled;
if (isPLEnabledForAllModels !== undefined) pLEntityExists.enabledForAllModels = isPLEnabledForAllModels;
}