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

Commit 33a1588

Browse files
Vishwac Sena KannanVishwac Sena Kannan
authored andcommitted
Updates based on PR comments
1 parent ef56b13 commit 33a1588

File tree

2 files changed

+33
-46
lines changed

2 files changed

+33
-46
lines changed

packages/luis/src/parser/converters/luistoluconverter.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ const addNDepthChildDefinitions = function(childCollection, tabStop, fileContent
213213
myFileContent += '- @ ';
214214
if (child.instanceOf) {
215215
myFileContent += child.instanceOf;
216-
} else if (child.children && child.children.length !== 0){
217-
myFileContent += EntityTypeEnum.ML;
218216
} else {
219217
myFileContent += EntityTypeEnum.ML;
220218
}

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

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,11 @@ const validateNDepthEntities = function(collection, entitiesAndRoles, intentsCol
204204
if (intentFeatureExists) {
205205
child.features[idx] = new helperClass.modelToFeature(feature);
206206
featureHandled = true;
207+
} else {
208+
let errorMsg = `[Error] line ${child.context.line}: Invalid child entity definition found. No definition found for "${feature}" in child entity definition "${child.context.definition}". Features must be defined before they can be added to a child.`;
209+
throw (new exception(retCode.errorCode.INVALID_INPUT, errorMsg));
207210
}
208211
}
209-
if (!featureHandled) {
210-
let errorMsg = `[Error] line ${child.context.line}: Invalid child entity definition found. No definition found for "${feature}" in child entity definition "${child.context.definition}". Features must be defined before they can be added to a child.`;
211-
throw (new exception(retCode.errorCode.INVALID_INPUT, errorMsg));
212-
}
213212
})
214213
}
215214

@@ -974,7 +973,7 @@ const handleNDepthEntity = function(parsedContent, entityName, entityRoles, enti
974973
let childEntityType = groupsFound.groups.instanceOf.trim();
975974
let childFeatures = groupsFound.groups.features ? groupsFound.groups.features.trim().split(/[,;]/g).map(item => item.trim()) : undefined;
976975
// Verify that the entity name is unique
977-
let entityIsUnique = verifyUniqueEntityName(parsedContent, childEntityName, childEntityType, line, true);
976+
verifyUniqueEntityName(parsedContent, childEntityName, childEntityType, line, true);
978977

979978
// Get current tab level
980979
let tabLevel = Math.ceil(groupsFound.groups.leadingSpaces !== undefined ? groupsFound.groups.leadingSpaces.length / SPACEASTABS : 0) || (groupsFound.groups.leadingTabs !== undefined ? groupsFound.groups.leadingTabs.length : 0);
@@ -992,47 +991,38 @@ const handleNDepthEntity = function(parsedContent, entityName, entityRoles, enti
992991
throw (new exception(retCode.errorCode.INVALID_INPUT, errorMsg));
993992
}
994993
let context = {line : defLine, definition: child.trim()};
995-
switch(groupsFound.groups.instanceOf.toLowerCase().trim()) {
996-
case EntityTypeEnum.SIMPLE:
997-
if (!currentParentEntity.entity.children) {
998-
currentParentEntity.entity.children = new Array(new helperClass.childEntity(childEntityName,"", context, [], childFeatures));
999-
} else {
1000-
// de-dupe and push this child entity
1001-
let childExists = (currentParentEntity.entity.children || []).find(item => item.name == childEntityName);
1002-
if (!childExists) {
1003-
currentParentEntity.entity.children.push(new helperClass.childEntity(childEntityName,"", context, [], childFeatures));
1004-
}
1005-
}
1006-
break;
1007-
case EntityTypeEnum.ML:
1008-
if (!currentParentEntity.entity.children) {
1009-
currentParentEntity.entity.children = new Array(new helperClass.childEntity(childEntityName,"", context, [], childFeatures));
1010-
} else {
1011-
// de-dupe and push this child entity
1012-
let childExists = (currentParentEntity.entity.children || []).find(item => item.name == childEntityName);
1013-
if (!childExists) {
1014-
currentParentEntity.entity.children.push(new helperClass.childEntity(childEntityName,"", context, [], childFeatures));
1015-
}
1016-
}
1017-
let newParent = currentParentEntity.entity.children.find(item => item.name == childEntityName);
1018-
// Push the ID of the parent since we are proessing the first child entity
1019-
entityIdxByLevel.push({level : tabLevel - baseTabLevel + 1, entity : newParent});
1020-
break;
1021-
default:
1022-
if (!currentParentEntity.entity.children) {
1023-
currentParentEntity.entity.children = new Array(new helperClass.childEntity(childEntityName, childEntityType, context, [], childFeatures));
1024-
} else {
1025-
// de-dupe and push this child entity
1026-
let childExists = (currentParentEntity.entity.children || []).find(item => item.name == childEntityName);
1027-
if (!childExists) {
1028-
currentParentEntity.entity.children.push(new helperClass.childEntity(childEntityName, childEntityType, context, [], childFeatures));
1029-
}
1030-
}
1031-
break;
994+
if (groupsFound.groups.instanceOf.toLowerCase().trim() === EntityTypeEnum.SIMPLE) {
995+
pushNDepthChild(currentParentEntity.entity, childEntityName, context, childFeatures);
996+
} else if (groupsFound.groups.instanceOf.toLowerCase().trim() === EntityTypeEnum.ML) {
997+
pushNDepthChild(currentParentEntity.entity, childEntityName, context, childFeatures);
998+
let newParent = currentParentEntity.entity.children.find(item => item.name == childEntityName);
999+
// Push the ID of the parent since we are proessing the first child entity
1000+
entityIdxByLevel.push({level : tabLevel - baseTabLevel + 1, entity : newParent});
1001+
} else {
1002+
pushNDepthChild(currentParentEntity.entity, childEntityName, context, childFeatures, childEntityType);
10321003
}
1033-
10341004
});
10351005
};
1006+
/**
1007+
* Helper to add an nDepth child entity to the collection.
1008+
* @param {Object} entity
1009+
* @param {String} childEntityName
1010+
* @param {Object} context
1011+
* @param {String []} childFeatures
1012+
* @param {String} childEntityType
1013+
* @param {Object []} children
1014+
*/
1015+
const pushNDepthChild = function(entity, childEntityName, context, childFeatures, childEntityType = "", children = []) {
1016+
if (!entity.children) {
1017+
entity.children = new Array(new helperClass.childEntity(childEntityName,childEntityType, context, children, childFeatures));
1018+
} else {
1019+
// de-dupe and push this child entity
1020+
let childExists = (entity.children || []).find(item => item.name == childEntityName);
1021+
if (!childExists) {
1022+
entity.children.push(new helperClass.childEntity(childEntityName, childEntityType, context, children, childFeatures));
1023+
}
1024+
}
1025+
}
10361026
/**
10371027
* Helper function to verify that the requested entity is unique.
10381028
* @param {Object} parsedContent
@@ -1067,7 +1057,6 @@ const verifyUniqueEntityName = function(parsedContent, entityName, entityType, l
10671057
})
10681058
throw (new exception(retCode.errorCode.INVALID_INPUT, error.toString()));
10691059
}
1070-
return {matchType, entityFound}
10711060
}
10721061
/**
10731062
* Helper function to handle pattern.any entity

0 commit comments

Comments
 (0)