updateModelBasedOnNDepthEntities = function(utterances, entities) {
    // filter to all utterances that have a labelled entity
    let utterancesWithLabels = utterances.filter(utterance => utterance.entities && utterance.entities.length !== 0);
    utterancesWithLabels.forEach(utterance => {
        utterance.entities.forEach(entityInUtterance => {
            // find this entity's root. There can be multiple and if there are, we need to delete the one that does not have children.
            let entityFoundInMaster = [];
            entities.forEach((entity, idx) => {
                if (entity.name == entityInUtterance.entity) {
                    entityFoundInMaster.push({id: idx, entityRoot: entity, path: '/'});
                }
                let entityPath = findEntityPath(entity, entityInUtterance.entity, "");
                if (entityPath !== "") { 
                    entityFoundInMaster.push({id: idx, entityRoot: entity, path: entityPath});
                }
            });
            let isParentLabelled = false;
            entityFoundInMaster.forEach(entityInMaster => {
                let splitPath = entityInMaster.path.split("/").filter(item => item.trim() !== "");
                if (entityFoundInMaster.length > 1 && splitPath.length === 0 && (!entityInMaster.entityRoot.children || entityInMaster.entityRoot.children.length === 0)) {
                    // this child needs to be removed. Note: There can only be at most one more entity due to utterance validation rules.
                    entities.splice(entityInMaster.id, 1);
                } else { 
                    if (isParentLabelled === false) {
                        let rSplitPath = splitPath.reverse();
                        rSplitPath.splice(0, 1);
                        rSplitPath.forEach(parent => {
                            // Ensure each parent is also labelled in this utterance
                            let parentLabelled = utterance.entities.find(entityUtt => entityUtt.entity == parent);
                            if (!parentLabelled) {
                                const errorMsg = `Every child entity labelled in an utterance must have its parent labelled in that utterance. Parent "${parent}" for child "${entityInUtterance.entity}" is not labelled in utterance "${utterance.text}" for intent "${utterance.intent}".`;
                                const error = BuildDiagnostic({
                                    message: errorMsg
                                });
                                throw (new exception(retCode.errorCode.INVALID_INPUT, error.toString(), [error]));
                            } else {
                                isParentLabelled = true;
                            }
                        })
                    }
                }
            })
        })
    })
}
Helper to update final LUIS model based on labelled nDepth entities.
@param {Object []} utterances 
@param {Object []} entities