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

Commit 1e93770

Browse files
authored
Merge branch 'master' into vishwac/docs-samples
2 parents 340cbe3 + 2058206 commit 1e93770

File tree

15 files changed

+192
-31
lines changed

15 files changed

+192
-31
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
updateUtterancesList(LUISJSON.patterns, luisObj.intents, 'pattern');
3434
if(luisObj.intents.length >= 0) {
3535
fileContent += NEWLINE;
36+
fileContent += addAppMetaData(LUISJSON);
3637
fileContent += '> # Intent definitions' + NEWLINE + NEWLINE;
3738
// write out intents and utterances..
3839
luisObj.intents.forEach(function(intent) {
@@ -187,6 +188,19 @@ module.exports = {
187188
return fileContent;
188189
}
189190
}
191+
/**
192+
* Helper to add application inforamtion metadata
193+
* @param {Object} LUISJSON
194+
*/
195+
const addAppMetaData = function(LUISJSON) {
196+
let fileContent = '';
197+
if (LUISJSON.name) fileContent += `> !# @app.name = ${LUISJSON.name}` + NEWLINE;
198+
if (LUISJSON.desc) fileContent += `> !# @app.desc = ${LUISJSON.desc}` + NEWLINE;
199+
if (LUISJSON.versionId) fileContent += `> !# @app.versionId = ${LUISJSON.versionId}` + NEWLINE;
200+
if (LUISJSON.culture) fileContent += `> !# @app.culture = ${LUISJSON.culture}` + NEWLINE;
201+
if (LUISJSON.luis_schema_version) fileContent += `> !# @app.luis_schema_version = ${LUISJSON.luis_schema_version}` + NEWLINE;
202+
return fileContent === '' ? fileContent : `> LUIS application information` + NEWLINE + fileContent + NEWLINE + NEWLINE;
203+
}
190204
/**
191205
* Helper function to handle nDepth entity definition
192206
* @param {Object} entity
@@ -324,17 +338,6 @@ const objectSortByStartPos = function (objectArray) {
324338
return ObjectByStartPos;
325339
}
326340

327-
constructModelDescFromLUISJSON = async function(LUISJSON) {
328-
let modelDesc = NEWLINE;
329-
modelDesc += '> LUIS application information' + NEWLINE;
330-
modelDesc += '> !# @app.name = ' + LUISJSON.name + NEWLINE;
331-
modelDesc += '> !# @app.desc = ' + LUISJSON.desc + NEWLINE;
332-
modelDesc += '> !# @app.culture = ' + LUISJSON.culture + NEWLINE;
333-
modelDesc += '> !# @app.versionId = ' + LUISJSON.versionId + NEWLINE;
334-
modelDesc += '> !# @app.luis_schema_version = ' + LUISJSON.luis_schema_version + NEWLINE;
335-
return modelDesc;
336-
}
337-
338341
/**
339342
* Helper function to return sorted LUIS JSON model
340343
* @param {Object} LUISJSON

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()

packages/luis/test/fixtures/translation/fr/root.luis.json

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,67 +73,67 @@
7373
"entities": []
7474
},
7575
{
76-
"text": "calendrier pour novembre 1948",
76+
"text": "dites-moi les détails de l'événement",
7777
"intent": "Calendar.Find",
7878
"entities": []
7979
},
8080
{
81-
"text": "afficher les plans de week-end",
81+
"text": "voix activée lecture des rendez-vous cette semaine",
8282
"intent": "Calendar.Find",
8383
"entities": []
8484
},
8585
{
86-
"text": "ai-je quelque chose le mercredi?",
86+
"text": "suis-je libre d'être avec des amis samedi ?",
8787
"intent": "Calendar.Find",
8888
"entities": []
8989
},
9090
{
91-
"text": "Combien de jours y a-t-il entre le 13 mars 2015 et aujourd'hui ?",
91+
"text": "rendez-vous avec Johnson doit être la semaine prochaine",
9292
"intent": "Calendar.Find",
9393
"entities": []
9494
},
9595
{
96-
"text": "tirer vers le haut de mon rendez-vous savoir combien de temps j'ai avant mon prochain rendez-vous",
96+
"text": "appeler papa mike",
9797
"intent": "Calendar.Find",
9898
"entities": []
9999
},
100100
{
101-
"text": "recherche de rencontres avec Chris",
101+
"text": "changer la réunion avec Chris à 9: 00 h",
102102
"intent": "Calendar.Find",
103103
"entities": []
104104
},
105105
{
106-
"text": "montrez-moi l'heure de la fête de mariage de demain",
106+
"text": "email cloney john",
107107
"intent": "Calendar.Find",
108108
"entities": []
109109
},
110110
{
111-
"text": "dites-moi les détails de l'événement",
111+
"text": "prolonger la réunion du déjeuner 30 minutes de plus",
112112
"intent": "Calendar.Find",
113113
"entities": []
114114
},
115115
{
116-
"text": "voix activée lecture des rendez-vous cette semaine",
116+
"text": "Je veux reprogrammer la réuni on au club de l'armée de l'air",
117117
"intent": "Calendar.Find",
118118
"entities": []
119119
},
120120
{
121-
"text": "suis-je libre d'être avec des amis samedi ?",
121+
"text": "réunions de marketing le mardi sera maintenant tous les mercredis s'il vous plaît changer sur mon calendrier",
122122
"intent": "None",
123123
"entities": []
124124
},
125125
{
126-
"text": "rendez-vous avec Johnson doit être la semaine prochaine",
126+
"text": "déplacer la fête bbq à vendredi",
127127
"intent": "None",
128128
"entities": []
129129
},
130130
{
131-
"text": "appeler papa mike",
131+
"text": "l'atelier durera 10 heures",
132132
"intent": "None",
133133
"entities": []
134134
},
135135
{
136-
"text": "changer la réunion avec Chris à 9: 00 h",
136+
"text": "change the meeting with chris to 9 : 00 am",
137137
"intent": "None",
138138
"entities": []
139139
},
@@ -143,32 +143,36 @@
143143
"entities": []
144144
},
145145
{
146-
"text": "prolonger la réunion du déjeuner 30 minutes de plus",
146+
"text": "extend lunch meeting 30 minutes extra",
147147
"intent": "None",
148148
"entities": []
149149
},
150150
{
151-
"text": "Je veux reprogrammer la réuni on au club de l'armée de l'air",
151+
"text": "i want to reschedule the meeting at the air force club",
152152
"intent": "None",
153153
"entities": []
154154
},
155155
{
156-
"text": "réunions de marketing le mardi sera maintenant tous les mercredis s'il vous plaît changer sur mon calendrier",
156+
"text": "marketing meetings on tuesdays will now be every wednesday please change on my calendar",
157157
"intent": "None",
158158
"entities": []
159159
},
160160
{
161-
"text": "déplacer la fête bbq à vendredi",
161+
"text": "move the bbq party to friday",
162162
"intent": "None",
163163
"entities": []
164164
},
165165
{
166-
"text": "l'atelier durera 10 heures",
166+
"text": "the workshop will last for 10 hours",
167167
"intent": "None",
168168
"entities": []
169169
}
170170
],
171171
"patterns": [],
172172
"patternAnyEntities": [],
173-
"prebuiltEntities": []
173+
"prebuiltEntities": [],
174+
"name": "file",
175+
"versionId": "0.1",
176+
"culture": "en-us",
177+
"luis_schema_version": "3.2.0"
174178
}

packages/luis/test/fixtures/verified/allGen.lu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
> LUIS application information
3+
> !# @app.name = all
4+
> !# @app.versionId = 0.1
5+
> !# @app.culture = en-us
6+
> !# @app.luis_schema_version = 3.2.0
7+
8+
29
> # Intent definitions
310

411
## Greeting

packages/luis/test/fixtures/verified/luis_sorted.lu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
> LUIS application information
3+
> !# @app.name = all
4+
> !# @app.versionId = 0.1
5+
> !# @app.culture = en-us
6+
> !# @app.luis_schema_version = 3.2.0
7+
8+
29
> # Intent definitions
310

411
## AskForUserName

packages/luis/test/fixtures/verified/modelAsFeatureGen.lu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
> LUIS application information
3+
> !# @app.versionId = 0.1
4+
> !# @app.culture = en-us
5+
> !# @app.luis_schema_version = 3.2.0
6+
7+
28
> # Intent definitions
39

410
## test1

packages/luis/test/fixtures/verified/nDepthEntityInUtterance.lu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
> LUIS application information
3+
> !# @app.versionId = 0.1
4+
> !# @app.culture = en-us
5+
> !# @app.luis_schema_version = 3.2.0
6+
7+
28
> # Intent definitions
39

410
## None

packages/luis/test/fixtures/verified/newEntity1.lu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
> LUIS application information
3+
> !# @app.versionId = 0.1
4+
> !# @app.culture = en-us
5+
> !# @app.luis_schema_version = 3.2.0
6+
7+
28
> # Intent definitions
39

410
> # Entity definitions

packages/luis/test/fixtures/verified/newEntity2.lu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
> LUIS application information
3+
> !# @app.versionId = 0.1
4+
> !# @app.culture = en-us
5+
> !# @app.luis_schema_version = 3.2.0
6+
7+
28
> # Intent definitions
39

410
> # Entity definitions

0 commit comments

Comments
 (0)