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

Commit a942fc7

Browse files
authored
Merge pull request #172 from microsoft/vishwac/newEntityAndFeatures
.lu file update - Ability to tie features to a specific model
2 parents 959b607 + 5eb54c6 commit a942fc7

File tree

16 files changed

+1491
-308
lines changed

16 files changed

+1491
-308
lines changed

packages/luis/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/tmp
77
/yarn.lock
88
node_modules
9+
**/.antlr

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
187199
const parseLuis = async function(luisObject, src, sort){
188200
let LUISJSON = new helperClasses.readerObject()
189201
LUISJSON.model = await luisFile.parseLuisJson(luisObject)

packages/luis/src/parser/lufile/LUFileLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ HAS_FEATURES_LABEL
100100
;
101101

102102
NEW_ENTITY_TYPE_IDENTIFIER
103-
: 'simple'|'list'|'regex'|'prebuilt'|'composite'|'machine-learned'|'patternany'|'phraselist'
103+
: 'simple'|'list'|'regex'|'prebuilt'|'composite'|'machine-learned'|'patternany'|'phraselist'|'intent'
104104
;
105105

106106
NEW_ENTITY_IDENTIFIER

packages/luis/src/parser/lufile/classes/hclasses.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ const readerObj = {
130130
hasRole(value) {
131131
return this.roles.includes(value);
132132
}
133+
},
134+
intentFeature: class {
135+
constructor(name) {
136+
this.featureName = name ? name : '';
137+
}
133138
}
134139
};
135140

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
module.exports = {
6+
'simple': 'entities',
7+
'prebuilt': 'prebuiltEntities',
8+
'list': 'closedLists',
9+
'regex': 'regex_entities',
10+
'composite': 'composites',
11+
'machine-learned': 'entities',
12+
'patternany':'patternAnyEntities',
13+
'phraselist': 'model_features'
14+
};

packages/luis/src/parser/lufile/generated/LUFileLexer.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)