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

Commit 0c9c038

Browse files
vishwacsenamunozemilio
authored andcommitted
Fix to do v6upgrade with parseFile api (#277)
1 parent 4b0678c commit 0c9c038

File tree

7 files changed

+131
-124
lines changed

7 files changed

+131
-124
lines changed

packages/lu/src/parser/converters/lutoluisconverter.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
if (haveLUISContent(finalLUISJSON)) {
2626
await luisJSON.validateLUISBlob(finalLUISJSON)
2727
}
28-
checkAndUpdateVersion(finalLUISJSON)
28+
helpers.checkAndUpdateVersion(finalLUISJSON)
2929
return finalLUISJSON
3030
} catch (err) {
3131
throw(err)
@@ -251,34 +251,7 @@ const mergeResults_closedlists = function (blob, finalCollection, type) {
251251
});
252252
}
253253
}
254-
/**
255-
* Helper to detect luis schema version based on content and update the final payload as needed.
256-
* @param {LUIS} finalLUISJSON
257-
*/
258-
const checkAndUpdateVersion = function(finalLUISJSON) {
259-
// Detect if there is content specific to 5.0.0 schema
260-
// any entity with children
261-
if (!finalLUISJSON) {
262-
return
263-
}
264-
let v5DefFound = false;
265-
v5DefFound = (finalLUISJSON.entities || []).find(i => i.children || i.features) ||
266-
(finalLUISJSON.intents || []).find(i => i.features) ||
267-
(finalLUISJSON.composites || []).find(i => i.features);
268-
if (v5DefFound) {
269-
finalLUISJSON.luis_schema_version = "6.0.0";
270-
if (finalLUISJSON.model_features && finalLUISJSON.model_features.length !== 0) {
271-
finalLUISJSON.phraselists = [];
272-
finalLUISJSON.model_features.forEach(item => finalLUISJSON.phraselists.push(Object.assign({}, item)));
273-
delete finalLUISJSON.model_features;
274-
}
275-
(finalLUISJSON.composites || []).forEach(composite => {
276-
let children = composite.children;
277-
composite.children = [];
278-
children.forEach(c => composite.children.push({name : c}));
279-
})
280-
}
281-
}
254+
282255
/**
283256
* Helper function to see if we have any luis content in the blob
284257
* @param {object} blob Contents of parsed luis blob

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,37 @@ const helpers = {
148148
// patterns must have at least one [optional] and or one (group | text)
149149
let detectPatternRegex = /(\[.*?\])|(\(.*?(\|.*?)+\))/gi;
150150
return detectPatternRegex.test(utterance);
151+
},
152+
/**
153+
* Helper to detect luis schema version based on content and update the final payload as needed.
154+
* @param {LUIS} finalLUISJSON
155+
*/
156+
checkAndUpdateVersion : function(finalLUISJSON) {
157+
if (!finalLUISJSON) return;
158+
// clean up house keeping
159+
if (finalLUISJSON.flatListOfEntityAndRoles) delete finalLUISJSON.flatListOfEntityAndRoles
160+
// Detect if there is content specific to 5.0.0 schema
161+
// any entity with children
162+
if (!finalLUISJSON) {
163+
return
164+
}
165+
let v5DefFound = false;
166+
v5DefFound = (finalLUISJSON.entities || []).find(i => i.children || i.features) ||
167+
(finalLUISJSON.intents || []).find(i => i.features) ||
168+
(finalLUISJSON.composites || []).find(i => i.features);
169+
if (v5DefFound) {
170+
finalLUISJSON.luis_schema_version = "6.0.0";
171+
if (finalLUISJSON.model_features && finalLUISJSON.model_features.length !== 0) {
172+
finalLUISJSON.phraselists = [];
173+
finalLUISJSON.model_features.forEach(item => finalLUISJSON.phraselists.push(Object.assign({}, item)));
174+
delete finalLUISJSON.model_features;
175+
}
176+
(finalLUISJSON.composites || []).forEach(composite => {
177+
let children = composite.children;
178+
composite.children = [];
179+
children.forEach(c => composite.children.push({name : c}));
180+
})
181+
}
151182
}
152183
}
153184

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const parseLuAndQnaWithAntlr = async function (parsedContent, fileContent, log,
171171
// If utterances have this child, then all parents must be included in the label
172172
updateModelBasedOnNDepthEntities(parsedContent.LUISJsonStructure.utterances, parsedContent.LUISJsonStructure.entities);
173173

174-
if (parsedContent.LUISJsonStructure.flatListOfEntityAndRoles) delete parsedContent.LUISJsonStructure.flatListOfEntityAndRoles
174+
helpers.checkAndUpdateVersion(parsedContent.LUISJsonStructure);
175175

176176
}
177177

packages/lu/src/parser/luisfile/parseLuisFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ module.exports = {
139139

140140
// composite entity definitions must have valid child entity type definitions.
141141
composite.children.forEach(child => {
142+
if (child instanceof Object) child = child.name;
142143
// Fix for #1165
143144
// Current implementation does not account for explicit role included in a child
144145
let childEntityName = child;

packages/lu/test/fixtures/verified/v5Upgrade.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"name": "1",
1919
"children": [
2020
{
21-
"name": "number"
21+
"name": {
22+
"name": "number"
23+
}
2224
}
2325
],
2426
"roles": []

0 commit comments

Comments
 (0)