@@ -6,7 +6,7 @@ const luisFile = require('./../luisfile/parseLuisFile')
66const helperClasses = require ( './../lufile/classes/hclasses' )
77const exception = require ( './../lufile/classes/exception' )
88const retCode = require ( './../lufile/enums/CLI-errors' )
9-
9+ const EntityTypeEnum = require ( './../lufile/enums/luisEntityTypes' ) ;
1010module . exports = {
1111 parseLuisFileToLu : async function ( file , sort ) {
1212 let LUISFileContent = await openFileAndReadContent ( file )
@@ -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 ) {
@@ -90,21 +91,26 @@ module.exports = {
9091 if ( LUISJSON . entities && LUISJSON . entities . length >= 0 ) {
9192 fileContent += '> # Entity definitions' + NEWLINE + NEWLINE ;
9293 LUISJSON . entities . forEach ( function ( entity ) {
93- // Add inherits information if any
94- if ( entity . inherits !== undefined ) {
95- // > !# @intent.inherits = {name = Web.WebSearch; domain_name = Web; model_name = WebSearch}
96- fileContent += '> !# @entity.inherits = name : ' + entity . name ;
97- if ( entity . inherits . domain_name !== undefined ) {
98- fileContent += '; domain_name : ' + entity . inherits . domain_name ;
99- }
100- if ( entity . inherits . model_name !== undefined ) {
101- fileContent += '; model_name : ' + entity . inherits . model_name ;
94+ if ( ! entity . children || entity . children . length === 0 ) {
95+ // Add inherits information if any
96+ if ( entity . inherits !== undefined ) {
97+ // > !# @intent.inherits = {name = Web.WebSearch; domain_name = Web; model_name = WebSearch}
98+ fileContent += '> !# @entity.inherits = name : ' + entity . name ;
99+ if ( entity . inherits . domain_name !== undefined ) {
100+ fileContent += '; domain_name : ' + entity . inherits . domain_name ;
101+ }
102+ if ( entity . inherits . model_name !== undefined ) {
103+ fileContent += '; model_name : ' + entity . inherits . model_name ;
104+ }
105+ fileContent += NEWLINE + NEWLINE ;
102106 }
107+ fileContent += `@ ml ${ entity . name } ` ;
108+ fileContent += addRolesAndFeatures ( entity ) ;
103109 fileContent += NEWLINE + NEWLINE ;
110+ } else {
111+ // handle n-depth entity
112+ fileContent += handleNDepthEntity ( entity ) ;
104113 }
105- fileContent += `@ simple ${ entity . name } ` ;
106- fileContent += addRolesAndFeatures ( entity ) ;
107- fileContent += NEWLINE + NEWLINE ;
108114 } ) ;
109115 fileContent += NEWLINE ;
110116 }
@@ -170,15 +176,69 @@ module.exports = {
170176 fileContent += `@ composite ${ composite . name } ` ;
171177 fileContent += addRolesAndFeatures ( composite ) ;
172178 if ( composite . children . length > 0 ) {
173- fileContent += ` = [${ composite . children . join ( ', ' ) } ]` ;
179+ if ( typeof composite . children [ 0 ] == "object" ) {
180+ fileContent += ` = [${ composite . children . map ( item => item . name ) . join ( ', ' ) } ]` ;
181+ } else {
182+ fileContent += ` = [${ composite . children . join ( ', ' ) } ]` ;
183+ }
174184 }
175185 fileContent += NEWLINE ;
176186 } )
177187 }
178188 return fileContent ;
179189 }
180190}
181-
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+ }
204+ /**
205+ * Helper function to handle nDepth entity definition
206+ * @param {Object } entity
207+ */
208+ const handleNDepthEntity = function ( entity ) {
209+ let fileContent = '' ;
210+ const BASE_TAB_STOP = 1 ;
211+ fileContent += `@ ${ EntityTypeEnum . ML } ${ entity . name } ` ;
212+ fileContent += addRolesAndFeatures ( entity ) ;
213+ fileContent += NEWLINE ;
214+ fileContent += addNDepthChildDefinitions ( entity . children , BASE_TAB_STOP , fileContent ) + NEWLINE + NEWLINE
215+ return fileContent ;
216+ }
217+ /**
218+ * Recursive helper function to add child definitions.
219+ * @param {Object[] } childCollection
220+ * @param {number } tabStop
221+ * @param {string } fileContent
222+ */
223+ const addNDepthChildDefinitions = function ( childCollection , tabStop , fileContent ) {
224+ let myFileContent = '' ;
225+ ( childCollection || [ ] ) . forEach ( child => {
226+ myFileContent += "" . padStart ( tabStop * 4 , ' ' ) ;
227+ myFileContent += '- @ ' ;
228+ if ( child . instanceOf ) {
229+ myFileContent += child . instanceOf ;
230+ } else {
231+ myFileContent += EntityTypeEnum . ML ;
232+ }
233+ myFileContent += ` ${ child . name } ` ;
234+ myFileContent += addRolesAndFeatures ( child ) ;
235+ myFileContent += NEWLINE ;
236+ if ( child . children && child . children . length !== 0 ) {
237+ myFileContent += addNDepthChildDefinitions ( child . children , ++ tabStop , myFileContent ) ;
238+ }
239+ } ) ;
240+ return myFileContent ;
241+ }
182242/**
183243 * Helper to construt role and features list for an entity
184244 * @param {Object } entity
@@ -278,17 +338,6 @@ const objectSortByStartPos = function (objectArray) {
278338 return ObjectByStartPos ;
279339}
280340
281- constructModelDescFromLUISJSON = async function ( LUISJSON ) {
282- let modelDesc = NEWLINE ;
283- modelDesc += '> LUIS application information' + NEWLINE ;
284- modelDesc += '> !# @app.name = ' + LUISJSON . name + NEWLINE ;
285- modelDesc += '> !# @app.desc = ' + LUISJSON . desc + NEWLINE ;
286- modelDesc += '> !# @app.culture = ' + LUISJSON . culture + NEWLINE ;
287- modelDesc += '> !# @app.versionId = ' + LUISJSON . versionId + NEWLINE ;
288- modelDesc += '> !# @app.luis_schema_version = ' + LUISJSON . luis_schema_version + NEWLINE ;
289- return modelDesc ;
290- }
291-
292341/**
293342 * Helper function to return sorted LUIS JSON model
294343 * @param {Object } LUISJSON
0 commit comments