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

Commit 5eb54c6

Browse files
Vishwac Sena KannanVishwac Sena Kannan
authored andcommitted
Addressing PR feedback
1 parent 6b2516d commit 5eb54c6

File tree

1 file changed

+27
-55
lines changed

1 file changed

+27
-55
lines changed

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

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,7 @@ module.exports = {
9898
fileContent += NEWLINE + NEWLINE;
9999
}
100100
fileContent += `@ simple ${entity.name}`;
101-
if (entity.roles && entity.roles.length > 0) {
102-
fileContent += ` ${entity.roles.length > 1 ? `hasRoles` : `hasRole`} ${entity.roles.join(',')}`;
103-
}
104-
if (entity.features && entity.features.length > 0) {
105-
let featuresList = new Array();
106-
entity.features.forEach(item => {
107-
if (item.featureName) featuresList.push(item.featureName);
108-
if (item.modelName) featuresList.push(item.modelName);
109-
})
110-
fileContent += ` ${featuresList.length > 1 ? `usesFeatures` : `usesFeature`} ${featuresList.join(',')}`;
111-
}
101+
fileContent += addRolesAndFeatures(entity);
112102
fileContent += NEWLINE + NEWLINE;
113103
});
114104
fileContent += NEWLINE;
@@ -118,17 +108,7 @@ module.exports = {
118108
fileContent += '> # PREBUILT Entity definitions' + NEWLINE + NEWLINE;
119109
LUISJSON.prebuiltEntities.forEach(function(entity) {
120110
fileContent += `@ prebuilt ${entity.name}`;
121-
if (entity.roles && entity.roles.length > 0) {
122-
fileContent += ` ${entity.roles.length > 1 ? `hasRoles` : `hasRole`} ${entity.roles.join(',')}`;
123-
}
124-
if (entity.features && entity.features.length > 0) {
125-
let featuresList = new Array();
126-
entity.features.forEach(item => {
127-
if (item.featureName) featuresList.push(item.featureName);
128-
if (item.modelName) featuresList.push(item.modelName);
129-
})
130-
fileContent += ` ${featuresList.length > 1 ? `usesFeatures` : `usesFeature`} ${featuresList.join(',')}`;
131-
}
111+
fileContent += addRolesAndFeatures(entity);
132112
fileContent += NEWLINE + NEWLINE;
133113
});
134114
fileContent += NEWLINE;
@@ -149,17 +129,7 @@ module.exports = {
149129
fileContent += '> # List entities' + NEWLINE + NEWLINE;
150130
LUISJSON.closedLists.forEach(function(ListItem) {
151131
fileContent += `@ list ${ListItem.name}`;
152-
if (ListItem.roles && ListItem.roles.length > 0) {
153-
fileContent += ` ${ListItem.roles.length > 1 ? `hasRoles` : `hasRole`} ${ListItem.roles.join(',')}`;
154-
}
155-
if (ListItem.features && ListItem.features.length > 0) {
156-
let featuresList = new Array();
157-
ListItem.features.forEach(item => {
158-
if (item.featureName) featuresList.push(item.featureName);
159-
if (item.modelName) featuresList.push(item.modelName);
160-
})
161-
fileContent += ` ${featuresList.length > 1 ? `usesFeatures` : `usesFeature`} ${featuresList.join(',')}`;
162-
}
132+
fileContent += addRolesAndFeatures(ListItem);
163133
if (ListItem.subLists.length !== 0) {
164134
fileContent += ` = `;
165135
fileContent += NEWLINE;
@@ -179,17 +149,7 @@ module.exports = {
179149
fileContent += '> # RegEx entities' + NEWLINE + NEWLINE;
180150
LUISJSON.regex_entities.forEach(function(regExEntity) {
181151
fileContent += `@ regex ${regExEntity.name}`;
182-
if (regExEntity.roles && regExEntity.roles.length > 0) {
183-
fileContent += ` ${regExEntity.roles.length > 1 ? `hasRoles` : `hasRole`} ${regExEntity.roles.join(',')}`;
184-
}
185-
if (regExEntity.features && regExEntity.features.length > 0) {
186-
let featuresList = new Array();
187-
regExEntity.features.forEach(item => {
188-
if (item.featureName) featuresList.push(item.featureName);
189-
if (item.modelName) featuresList.push(item.modelName);
190-
})
191-
fileContent += ` ${featuresList.length > 1 ? `usesFeatures` : `usesFeature`} ${featuresList.join(',')}`;
192-
}
152+
fileContent += addRolesAndFeatures(regExEntity);
193153
if (regExEntity.regexPattern !== '') {
194154
fileContent += ` = /${regExEntity.regexPattern}/`;
195155
}
@@ -203,17 +163,7 @@ module.exports = {
203163
fileContent += '> # Composite entities' + NEWLINE + NEWLINE;
204164
LUISJSON.composites.forEach(composite => {
205165
fileContent += `@ composite ${composite.name}`;
206-
if (composite.roles && composite.roles.length > 0) {
207-
fileContent += ` ${composite.roles.length > 1 ? `hasRoles` : `hasRole`} ${composite.roles.join(',')}`;
208-
}
209-
if (composite.features && composite.features.length > 0) {
210-
let featuresList = new Array();
211-
composite.features.forEach(item => {
212-
if (item.featureName) featuresList.push(item.featureName);
213-
if (item.modelName) featuresList.push(item.modelName);
214-
})
215-
fileContent += ` ${featuresList.length > 1 ? `usesFeatures` : `usesFeature`} ${featuresList.join(',')}`;
216-
}
166+
fileContent += addRolesAndFeatures(composite);
217167
if (composite.children.length > 0) {
218168
fileContent += ` = [${composite.children.join(', ')}]`;
219169
}
@@ -224,6 +174,28 @@ module.exports = {
224174
}
225175
}
226176

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+
227199
const parseLuis = async function(luisObject, src, sort){
228200
let LUISJSON = new helperClasses.readerObject()
229201
LUISJSON.model = await luisFile.parseLuisJson(luisObject)

0 commit comments

Comments
 (0)