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

Commit da24593

Browse files
authored
fix lu build bug when training empty intents (#643)
* fix lu build bug when training empty intents * change warning message test
1 parent f5dea03 commit da24593

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ export class Builder {
258258
currentApp.name = `${botName}(${suffix})-${content.name}`
259259
}
260260

261+
// remove empty intents from current app to avoid fewLabels error when training
262+
this.filterEmptyIntents(currentApp)
263+
261264
return currentApp
262265
}
263266

@@ -352,4 +355,19 @@ export class Builder {
352355

353356
return new Content(settings.save(), new LUOptions(path.basename(settings.getSettingsPath()), true, '', settings.getSettingsPath()))
354357
}
358+
359+
filterEmptyIntents(app: any) {
360+
const intents = app.intents
361+
const utterances = app.utterances
362+
const patterns = app.patterns
363+
364+
const emptyIntents = intents.filter((intent: any) => !utterances.some((utterance: any) => utterance.intent === intent.name)
365+
&& !patterns.some((pattern: any) => pattern.intent === intent.name))
366+
367+
if (emptyIntents && emptyIntents.length > 0) {
368+
const filteredIntents = intents.filter((intent: any) => !emptyIntents.some((emptyIntent: any) => emptyIntent.name === intent.name))
369+
this.handler(`[WARN]: empty intent(s) ${emptyIntents.map((intent: any) => '# ' + intent.name).join(', ')} are filtered when handling luis application`)
370+
app.intents = filteredIntents
371+
}
372+
}
355373
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,11 @@ const parseAndHandleModelInfoSection = function (parsedContent, luResource, log)
18001800
if (modelInfos && modelInfos.length > 0) {
18011801
for (const modelInfo of modelInfos) {
18021802
let line = modelInfo.ModelInfo
1803-
let kvPair = line.split(/@(app|kb|intent|entity|enableMergeIntents|patternAnyEntity).(.*)=/g).map(item => item.trim());
1803+
let kvPair = line.split(/@(app|kb|intent|entity|enableSections|enableMergeIntents|patternAnyEntity).(.*)=/g).map(item => item.trim());
1804+
1805+
// avoid to throw invalid model info when meeting enableSections info which is handled in luParser.js
1806+
if (kvPair[1] === 'enableSections') continue
1807+
18041808
if (kvPair.length === 4) {
18051809
if (kvPair[1] === 'enableMergeIntents' && kvPair[3] === 'false') {
18061810
enableMergeIntents = false;

packages/luis/test/commands/luis/build.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ describe('luis:build update dialog assets successfully when dialog assets exist'
549549
expect(ctx.stdout).to.contain('foo.en-us.lu.dialog loaded')
550550
expect(ctx.stdout).to.contain('foo.fr-fr.lu.dialog loaded')
551551

552+
expect(ctx.stdout).to.contain('[WARN]: empty intent(s) # emptyIntent are filtered when handling luis application')
553+
552554
expect(ctx.stdout).to.contain('Creating LUIS.ai application')
553555
expect(ctx.stdout).to.contain('training version=0.1')
554556
expect(ctx.stdout).to.contain('waiting for training for version=0.1')

packages/luis/test/fixtures/testcases/lubuild/foo2/lufiles-and-dialog-assets/foo.lu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
- hey carlos!
33
- yo carlos!
44
- hello
5-
- hi
5+
- hi
6+
7+
# emptyIntent

0 commit comments

Comments
 (0)