in parsers/LU/JS/packages/lu/src/parser/luis/luisCollate.js [134:178]
const recursivelyMergeChildrenAndFeatures = function(srcChildren, tgtChildren) {
if (tgtChildren === undefined || !Array.isArray(tgtChildren) || tgtChildren.length === 0) {
tgtChildren = srcChildren;
return;
}
(srcChildren || []).forEach(item => {
// find child in tgt
let itemExistsInFinal = (tgtChildren || []).find(x => x.name == item.name);
if (itemExistsInFinal === undefined) {
tgtChildren.push(item);
} else {
// merge features
if (item.features !== undefined && item.features.length !== 0) {
// merge and verify type
let typeForFinalItem = (itemExistsInFinal.features || []).find(t => t.isRequired == true);
let typeForItem = (item.features || []).find(t1 => t1.isRequired == true);
if (typeForFinalItem !== undefined) {
if (typeForItem !== undefined) {
if (typeForFinalItem.modelName !== typeForItem.modelName) {
throw new exception(retCode.errorCode.INVALID_REGEX_ENTITY, `Child entity ${item.name} does not have consistent type definition. Please verify all definitions for this entity.`)
}
}
}
item.features.forEach(f => {
let featureInFinal = (itemExistsInFinal.features || []).find(itFea => {
return ((itFea.featureName !== undefined && itFea.featureName == f.featureName) ||
(itFea.modelName !== undefined && itFea.modelName == f.modelName))
});
if (featureInFinal === undefined) {
itemExistsInFinal.features.push(f);
} else {
// throw if isRequired is not the same.
if (featureInFinal.isRequired !== f.isRequired) {
throw new exception(retCode.errorCode.INVALID_REGEX_ENTITY, `Feature ${f.featureName} does not have consistent definition for entity ${item.name}. Please verify all definitions for this feature for this entity.`)
}
}
})
}
// de-dupe and merge children
if (item.children !== undefined && Array.isArray(item.children) && item.children.length !== 0) {
recursivelyMergeChildrenAndFeatures(item.children, itemExistsInFinal.children)
}
}
})
}