@@ -98,9 +98,7 @@ module.exports = {
9898 fileContent += NEWLINE + NEWLINE ;
9999 }
100100 fileContent += `@ simple ${ entity . name } ` ;
101- if ( entity . roles . length > 0 ) {
102- fileContent += ` ${ entity . roles . length > 1 ? `hasRoles` : `hasRole` } ${ entity . roles . join ( ',' ) } `
103- }
101+ fileContent += addRolesAndFeatures ( entity ) ;
104102 fileContent += NEWLINE + NEWLINE ;
105103 } ) ;
106104 fileContent += NEWLINE ;
@@ -110,9 +108,7 @@ module.exports = {
110108 fileContent += '> # PREBUILT Entity definitions' + NEWLINE + NEWLINE ;
111109 LUISJSON . prebuiltEntities . forEach ( function ( entity ) {
112110 fileContent += `@ prebuilt ${ entity . name } ` ;
113- if ( entity . roles . length > 0 ) {
114- fileContent += ` ${ entity . roles . length > 1 ? `hasRoles` : `hasRole` } ${ entity . roles . join ( ',' ) } ` ;
115- }
111+ fileContent += addRolesAndFeatures ( entity ) ;
116112 fileContent += NEWLINE + NEWLINE ;
117113 } ) ;
118114 fileContent += NEWLINE ;
@@ -122,7 +118,7 @@ module.exports = {
122118 fileContent += '> # Phrase list definitions' + NEWLINE + NEWLINE ;
123119 LUISJSON . model_features . forEach ( function ( entity ) {
124120 fileContent += `@ phraselist ${ entity . name } ${ ( entity . mode ? `(interchangeable)` : `` ) } ` ;
125- if ( entity . words !== '' ) {
121+ if ( entity . words && entity . words !== '' ) {
126122 fileContent += ` = ${ NEWLINE } \t- ${ entity . words } ` ;
127123 }
128124 fileContent += NEWLINE + NEWLINE ;
@@ -133,9 +129,7 @@ module.exports = {
133129 fileContent += '> # List entities' + NEWLINE + NEWLINE ;
134130 LUISJSON . closedLists . forEach ( function ( ListItem ) {
135131 fileContent += `@ list ${ ListItem . name } ` ;
136- if ( ListItem . roles . length > 0 ) {
137- fileContent += ` ${ ListItem . roles . length > 1 ? `hasRoles` : `hasRole` } ${ ListItem . roles . join ( ',' ) } ` ;
138- }
132+ fileContent += addRolesAndFeatures ( ListItem ) ;
139133 if ( ListItem . subLists . length !== 0 ) {
140134 fileContent += ` = ` ;
141135 fileContent += NEWLINE ;
@@ -155,9 +149,7 @@ module.exports = {
155149 fileContent += '> # RegEx entities' + NEWLINE + NEWLINE ;
156150 LUISJSON . regex_entities . forEach ( function ( regExEntity ) {
157151 fileContent += `@ regex ${ regExEntity . name } ` ;
158- if ( regExEntity . roles . length > 0 ) {
159- fileContent += ` ${ regExEntity . roles . length > 1 ? `hasRoles` : `hasRole` } ${ regExEntity . roles . join ( ',' ) } ` ;
160- }
152+ fileContent += addRolesAndFeatures ( regExEntity ) ;
161153 if ( regExEntity . regexPattern !== '' ) {
162154 fileContent += ` = /${ regExEntity . regexPattern } /` ;
163155 }
@@ -171,9 +163,7 @@ module.exports = {
171163 fileContent += '> # Composite entities' + NEWLINE + NEWLINE ;
172164 LUISJSON . composites . forEach ( composite => {
173165 fileContent += `@ composite ${ composite . name } ` ;
174- if ( composite . roles . length > 0 ) {
175- fileContent += ` ${ composite . roles . length > 1 ? `hasRoles` : `hasRole` } ${ composite . roles . join ( ',' ) } ` ;
176- }
166+ fileContent += addRolesAndFeatures ( composite ) ;
177167 if ( composite . children . length > 0 ) {
178168 fileContent += ` = [${ composite . children . join ( ', ' ) } ]` ;
179169 }
@@ -184,6 +174,28 @@ module.exports = {
184174 }
185175}
186176
177+ /**
178+ * Helper to construt role and features list for an entity
179+ * @param {Object } entity
180+ * @returns {String } file content to include.
181+ */
182+ const addRolesAndFeatures = function ( entity ) {
183+ let roleAndFeatureContent = ''
184+ if ( entity . roles && entity . roles . length > 0 ) {
185+ roleAndFeatureContent += ` ${ entity . roles . length > 1 ? `hasRoles` : `hasRole` } ${ entity . roles . join ( ',' ) } ` ;
186+ }
187+ if ( entity . features && entity . features . length > 0 ) {
188+ let featuresList = new Array ( ) ;
189+ entity . features . forEach ( item => {
190+ if ( item . featureName ) featuresList . push ( item . featureName ) ;
191+ if ( item . modelName ) featuresList . push ( item . modelName ) ;
192+ } )
193+ roleAndFeatureContent += ` ${ featuresList . length > 1 ? `usesFeatures` : `usesFeature` } ${ featuresList . join ( ',' ) } ` ;
194+ }
195+
196+ return roleAndFeatureContent
197+ }
198+
187199const parseLuis = async function ( luisObject , src , sort ) {
188200 let LUISJSON = new helperClasses . readerObject ( )
189201 LUISJSON . model = await luisFile . parseLuisJson ( luisObject )
0 commit comments