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

Commit 2c5897e

Browse files
authored
Merge pull request #197 from microsoft/vishwac/5.0.0
Update luis schema version to v5 based on content
2 parents 1aa1755 + c0955db commit 2c5897e

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
if (haveLUISContent(finalLUISJSON)) {
2626
await luisJSON.validateLUISBlob(finalLUISJSON)
2727
}
28+
checkAndUpdateVersion(finalLUISJSON)
2829
return finalLUISJSON
2930
} catch (err) {
3031
throw(err)
@@ -250,7 +251,31 @@ const mergeResults_closedlists = function (blob, finalCollection, type) {
250251
});
251252
}
252253
}
253-
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+
let v5DefFound = false;
262+
v5DefFound = (finalLUISJSON.entities || []).find(i => i.children || i.features) ||
263+
(finalLUISJSON.intents || []).find(i => i.features) ||
264+
(finalLUISJSON.composites || []).find(i => i.features);
265+
if (v5DefFound) {
266+
finalLUISJSON.luis_schema_version = "5.0.0";
267+
if (finalLUISJSON.model_features && finalLUISJSON.model_features.length !== 0) {
268+
finalLUISJSON.phraselists = [];
269+
finalLUISJSON.model_features.forEach(item => finalLUISJSON.phraselists.push(Object.assign({}, item)));
270+
delete finalLUISJSON.model_features;
271+
}
272+
(finalLUISJSON.composites || []).forEach(composite => {
273+
let children = composite.children;
274+
composite.children = [];
275+
children.forEach(c => composite.children.push({name : c}));
276+
})
277+
}
278+
}
254279
/**
255280
* Helper function to see if we have any luis content in the blob
256281
* @param {object} blob Contents of parsed luis blob

packages/luis/test/commands/luis/convert.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ describe('luis:convert', () => {
366366
})
367367
})
368368

369+
describe('luis:convert version 5 upgrade test', () => {
370+
test
371+
.stdout()
372+
.command(['luis:convert', '--in', `${path.join(__dirname, './../../fixtures/verified/v5UpgradeTest.lu')}`, '--out', 'root.json'])
373+
.it('luis:convert successfully reconstructs a markdown file from a LUIS input file with out of order entity references', async () => {
374+
expect(await compareLuFiles('./../../../root.json', './../../fixtures/verified/v5Upgrade.json')).to.be.true
375+
})
376+
})
377+
369378
describe('luis:convert negative tests', () => {
370379
test
371380
.stderr()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"intents": [],
3+
"entities": [
4+
{
5+
"name": "xyz1",
6+
"roles": [],
7+
"children": [
8+
{
9+
"name": "xyz",
10+
"instanceOf": "",
11+
"children": [],
12+
"features": ""
13+
}
14+
]
15+
}
16+
],
17+
"composites": [
18+
{
19+
"name": "1",
20+
"children": [
21+
{
22+
"name": "number"
23+
}
24+
],
25+
"roles": []
26+
}
27+
],
28+
"closedLists": [],
29+
"regex_entities": [],
30+
"regex_features": [],
31+
"utterances": [],
32+
"patterns": [],
33+
"patternAnyEntities": [],
34+
"prebuiltEntities": [
35+
{
36+
"name": "number",
37+
"roles": []
38+
}
39+
],
40+
"luis_schema_version": "5.0.0",
41+
"phraselists": [
42+
{
43+
"name": "abc",
44+
"words": "one,two,three",
45+
"mode": false,
46+
"activated": true
47+
}
48+
],
49+
"versionId": "0.1",
50+
"name": "",
51+
"desc": "",
52+
"culture": "en-us"
53+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@ml xyz1 =
2+
- @ ml xyz
3+
@ phraselist abc =
4+
- one
5+
- two
6+
- three
7+
@ prebuilt number
8+
@ composite 1 = [number]

0 commit comments

Comments
 (0)