Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/lu/src/parser/lufile/parseFileContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ const parseAndHandleEntityV2 = function (parsedContent, luResource, log, locale)
for (const entity of entities) {
if (entity.Type !== INTENTTYPE) {
entity.Name = entity.Name.replace(/^[\'\"]|[\'\"]$/g, "");
let entityName = entity.Name;
let entityName = entity.Name.endsWith('=') ? entity.Name.slice(0, entity.Name.length - 1) : entity.Name;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity.Name.endsWith('=') [](start = 33, length = 25)

This will work, but isn't there a limited set of chars allowed in entity names for LUIS?

let entityType = !entity.Type ? getEntityType(entity.Name, entities) : entity.Type;
if (!entityType) {
let errorMsg = `No type definition found for entity "${entityName}". Supported types are ${Object.values(EntityTypeEnum).join(', ')}. Note: Type names are case sensitive.`;
Expand Down
14 changes: 14 additions & 0 deletions packages/lu/src/parser/luis/luisCollate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const collate = function(luisList) {
buildPatternAny(blob, luisObject)
}
helpers.checkAndUpdateVersion(luisObject)
cleanupEntities(luisObject)
return luisObject
}

Expand All @@ -60,6 +61,19 @@ module.exports = {
build
}

const cleanupEntities = function(luisObject) {
let consolidatedList = [];
luisObject.composites.forEach(item => consolidatedList.push(item));
luisObject.closedLists.forEach(item => consolidatedList.push(item));
luisObject.regex_entities.forEach(item => consolidatedList.push(item));
luisObject.prebuiltEntities.forEach(item => consolidatedList.push(item));
let idxToRemove = [];
luisObject.entities.forEach((item, idx) => {
if (consolidatedList.find(e => e.name == item.name) !== undefined) idxToRemove.push(idx);
})
idxToRemove.sort((a, b) => a-b).forEach(idx => luisObject.entities.splice(idx, 1))
}

const mergeResultsWithHash = function (blob, finalCollection, type, hashTable) {
if (blob[type].length === 0) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Licensed under the MIT License.
*/
const parseFile = require('../../../src/parser/lufile/parseFileContents');
const luObj = require('./../../../src/parser/lu/lu');
const luBuilder = require('./../../../src/parser/luis/luisBuilder');
var chai = require('chai');
var assert = chai.assert;
describe('V2 Entity definitions using @ notation', function () {
Expand Down Expand Up @@ -1080,6 +1082,21 @@ describe('V2 Entity definitions using @ notation', function () {
.then(res => done(res))
.catch(err => done())
});

it('BF CLI #653 - closed list definition', function(done){
let luFile = `
@ list blah=
- something:
`;

parseFile.parseFile(luFile)
.then(res => {
assert.equal(res.LUISJsonStructure.closedLists[0].name, "blah");
assert.equal(res.LUISJsonStructure.closedLists[0].subLists[0].canonicalForm, "something");
done()
})
.catch(err => done(err))
})
});

describe('Pattern.Any entity definition', function(){
Expand Down Expand Up @@ -1113,5 +1130,24 @@ describe('V2 Entity definitions using @ notation', function () {
.catch(err => done(err));
})
})

describe('multi-content', function(){
it('BF-CLI #652 - multi entity definition across docs is merged correctly', function(done){
let luContent1 = new luObj(`@ list blah=
- something:

@ composite foo = [blah]
`);
let luContent2 = new luObj(`# utterances
- @{foo= something}`);
luBuilder.fromLUAsync([luContent1, luContent2])
.then(res => {
assert.isTrue(res.entities.length === 0);
assert.equal(res.composites[0].name, "foo");
done()
})
.catch(err => done(err))
})
})

});
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ $test:/hrf-[0-9]{6}/`;

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