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

Commit dd9dad4

Browse files
vishwacsenaVishwac Sena Kannan
andauthored
LU fixes (#657)
* bug fixes * fixing tests Co-authored-by: Vishwac Sena Kannan <vishwacsenakannan@WIN-9GFQV4IK7VB.redmond.corp.microsoft.com>
1 parent eef8841 commit dd9dad4

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

packages/lu/src/parser/lufile/parseFileContents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ const parseAndHandleEntityV2 = function (parsedContent, luResource, log, locale)
10341034
for (const entity of entities) {
10351035
if (entity.Type !== INTENTTYPE) {
10361036
entity.Name = entity.Name.replace(/^[\'\"]|[\'\"]$/g, "");
1037-
let entityName = entity.Name;
1037+
let entityName = entity.Name.endsWith('=') ? entity.Name.slice(0, entity.Name.length - 1) : entity.Name;
10381038
let entityType = !entity.Type ? getEntityType(entity.Name, entities) : entity.Type;
10391039
if (!entityType) {
10401040
let errorMsg = `No type definition found for entity "${entityName}". Supported types are ${Object.values(EntityTypeEnum).join(', ')}. Note: Type names are case sensitive.`;

packages/lu/src/parser/luis/luisCollate.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const collate = function(luisList) {
5252
buildPatternAny(blob, luisObject)
5353
}
5454
helpers.checkAndUpdateVersion(luisObject)
55+
cleanupEntities(luisObject)
5556
return luisObject
5657
}
5758

@@ -60,6 +61,19 @@ module.exports = {
6061
build
6162
}
6263

64+
const cleanupEntities = function(luisObject) {
65+
let consolidatedList = [];
66+
luisObject.composites.forEach(item => consolidatedList.push(item));
67+
luisObject.closedLists.forEach(item => consolidatedList.push(item));
68+
luisObject.regex_entities.forEach(item => consolidatedList.push(item));
69+
luisObject.prebuiltEntities.forEach(item => consolidatedList.push(item));
70+
let idxToRemove = [];
71+
luisObject.entities.forEach((item, idx) => {
72+
if (consolidatedList.find(e => e.name == item.name) !== undefined) idxToRemove.push(idx);
73+
})
74+
idxToRemove.sort((a, b) => a-b).forEach(idx => luisObject.entities.splice(idx, 1))
75+
}
76+
6377
const mergeResultsWithHash = function (blob, finalCollection, type, hashTable) {
6478
if (blob[type].length === 0) {
6579
return

packages/lu/test/parser/lufile/parseFileContents.NewEntityDefinition.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License.
44
*/
55
const parseFile = require('../../../src/parser/lufile/parseFileContents');
6+
const luObj = require('./../../../src/parser/lu/lu');
7+
const luBuilder = require('./../../../src/parser/luis/luisBuilder');
68
var chai = require('chai');
79
var assert = chai.assert;
810
describe('V2 Entity definitions using @ notation', function () {
@@ -1080,6 +1082,21 @@ describe('V2 Entity definitions using @ notation', function () {
10801082
.then(res => done(res))
10811083
.catch(err => done())
10821084
});
1085+
1086+
it('BF CLI #653 - closed list definition', function(done){
1087+
let luFile = `
1088+
@ list blah=
1089+
- something:
1090+
`;
1091+
1092+
parseFile.parseFile(luFile)
1093+
.then(res => {
1094+
assert.equal(res.LUISJsonStructure.closedLists[0].name, "blah");
1095+
assert.equal(res.LUISJsonStructure.closedLists[0].subLists[0].canonicalForm, "something");
1096+
done()
1097+
})
1098+
.catch(err => done(err))
1099+
})
10831100
});
10841101

10851102
describe('Pattern.Any entity definition', function(){
@@ -1113,5 +1130,24 @@ describe('V2 Entity definitions using @ notation', function () {
11131130
.catch(err => done(err));
11141131
})
11151132
})
1133+
1134+
describe('multi-content', function(){
1135+
it('BF-CLI #652 - multi entity definition across docs is merged correctly', function(done){
1136+
let luContent1 = new luObj(`@ list blah=
1137+
- something:
1138+
1139+
@ composite foo = [blah]
1140+
`);
1141+
let luContent2 = new luObj(`# utterances
1142+
- @{foo= something}`);
1143+
luBuilder.fromLUAsync([luContent1, luContent2])
1144+
.then(res => {
1145+
assert.isTrue(res.entities.length === 0);
1146+
assert.equal(res.composites[0].name, "foo");
1147+
done()
1148+
})
1149+
.catch(err => done(err))
1150+
})
1151+
})
11161152

11171153
});

packages/lu/test/parser/lufile/parseFileContents.regexEntity.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ $test:/hrf-[0-9]{6}/`;
137137

138138
it('throws when duplicate regex entities with different patterns are found across lu files', function(done) {
139139
let luFile1 = `$test:/hrf-[0-9]{6}/`;
140-
let luFile2 = `# test
141-
- this is a {test=one} utterance`;
140+
let luFile2 = `$test:/bpg-[0-9]{5}/`;
142141
parseFile(luFile1, false)
143142
.then(res1 => {
144143
parseFile(luFile2, false)

0 commit comments

Comments
 (0)