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

Commit b688652

Browse files
authored
Surface lu parser error (#1291)
* surface parsing error to bf cli users * added tests * fixed lint errors * Update orchestratorhelper.ts * Update orchestratorhelper.ts fixed lint error
1 parent 7a936c1 commit b688652

File tree

8 files changed

+195
-28
lines changed

8 files changed

+195
-28
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"999999",
1616
"--colors",
1717
"-g",
18-
".*addAsync.*"
18+
"Test.0600 OrchestratorHelper.parseLuFile()"
1919
],
2020
"cwd": "${workspaceFolder}/packages/orchestratorlib",
2121
"internalConsoleOptions": "openOnSessionStart",

packages/orchestrator/src/commands/orchestrator/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class OrchestratorCreate extends Command {
8181
settings.SnapshotPath = snapshotFilePath;
8282
settings.persist();
8383
} catch (error) {
84-
throw (new CLIError(error));
84+
throw (new CLIError(error as Error));
8585
}
8686
}
8787

packages/orchestratorlib/src/orchestratorhelper.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class OrchestratorHelper {
352352

353353
default: throw new Error(`Unknown file type ${ext}`);
354354
}
355-
} catch (error) {
355+
} catch (error: any) {
356356
throw new Error(`${error.message}${os.EOL}Failed to parse ${filePath}`);
357357
}
358358
}
@@ -421,15 +421,15 @@ export class OrchestratorHelper {
421421
if (!luContent || luContent.length === 0) {
422422
return;
423423
}
424-
const luObject: any = {
425-
content: luContent,
426-
id: luFile,
427-
};
428-
const luisObject: any = await LuisBuilder.fromLUAsync([luObject], OrchestratorHelper.findLuFiles);
429-
if (Utility.toPrintDetailedDebuggingLogToConsole) {
430-
UtilityDispatcher.debuggingNamedLog1('OrchestratorHelper.parseLuContent(): calling getIntentsEntitiesUtterances()', luisObject, 'luisObject');
431-
}
432424
try {
425+
const luObject: any = {
426+
content: luContent,
427+
id: luFile,
428+
};
429+
const luisObject: any = await LuisBuilder.fromLUAsync([luObject], OrchestratorHelper.findLuFiles);
430+
if (Utility.toPrintDetailedDebuggingLogToConsole) {
431+
UtilityDispatcher.debuggingNamedLog1('OrchestratorHelper.parseLuContent(): calling getIntentsEntitiesUtterances()', luisObject, 'luisObject');
432+
}
433433
const rvLu: boolean = OrchestratorHelper.getIntentsEntitiesUtterances(
434434
luisObject,
435435
hierarchicalLabel,
@@ -440,9 +440,8 @@ export class OrchestratorHelper {
440440
if (!rvLu) {
441441
throw new Error('Failed to parse LUIS or JSON file on intent/entity labels');
442442
}
443-
} catch (error) {
444-
Utility.debuggingLog(`EXCEPTION calling getIntentsEntitiesUtterances(), error=${error}`);
445-
throw error;
443+
} catch (error: any) {
444+
throw new Error(`Failed parsing lu file ${luFile} ${error.text}`);
446445
}
447446
}
448447

@@ -602,20 +601,19 @@ export class OrchestratorHelper {
602601
return;
603602
}
604603

605-
const newlines: string[] = [];
606-
lines.forEach((line: string) => {
607-
if (line.toLowerCase().indexOf('@qna.pair.source =') < 0) {
608-
newlines.push(line);
609-
}
610-
});
611-
612-
// Utility.debuggingLog('OrchestratorHelper.parseQnaFile() ready to call QnaMakerBuilder.fromContent()');
613-
const qnaNormalized: string = Utility.cleanStringOnTabs(newlines.join('\n')); // ---- NOTE ---- QnaMakerBuilder does not like TAB
614-
const qnaObject: any = await QnaMakerBuilder.fromContent(qnaNormalized);
615-
if (qnaObject) {
604+
try {
605+
const newlines: string[] = [];
606+
lines.forEach((line: string) => {
607+
if (line.toLowerCase().indexOf('@qna.pair.source =') < 0) {
608+
newlines.push(line);
609+
}
610+
});
611+
// Utility.debuggingLog('OrchestratorHelper.parseQnaFile() ready to call QnaMakerBuilder.fromContent()');
612+
const qnaNormalized: string = Utility.cleanStringOnTabs(newlines.join('\n')); // ---- NOTE ---- QnaMakerBuilder does not like TAB
613+
const qnaObject: any = await QnaMakerBuilder.fromContent(qnaNormalized);
616614
OrchestratorHelper.getQnaQuestionsAsUtterances(qnaObject, hierarchicalLabel, utteranceLabelsMap, utteranceLabelDuplicateMap);
617-
} else {
618-
throw new Error(`Failed parsing qna file ${qnaFile}`);
615+
} catch (error: any) {
616+
throw new Error(`Failed parsing qna file ${qnaFile} ${error.text}`);
619617
}
620618
}
621619

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
> LUIS application information
3+
> !# @app.name = Weather
4+
> !# @app.desc = Weather LUIS application - Bot Builder Samples
5+
> !# @app.versionId = 0.1
6+
> !# @app.culture = en-us
7+
> !# @app.luis_schema_version = 4.0.0
8+
9+
10+
> # Intent definitions
11+
- current weather ?
12+
- do {@Location=florida} residents usually need ice
13+
14+
## Get Weather Forecast
15+
- forecast in celcius
16+
- get the forcast for me
17+
- i want to know the temperature at {@Location=death valley}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
**Prompts:**
2+
- [Files that Cannot Sync
3+
](#1)
4+
5+
<a id = "1"/>
6+
7+
## ? Files that Cannot Sync
8+
```
9+
Files that cannot sync.
10+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
> LUIS application information
3+
> !# @app.name = Weather
4+
> !# @app.desc = Weather LUIS application - Bot Builder Samples
5+
> !# @app.versionId = 0.1
6+
> !# @app.culture = en-us
7+
> !# @app.luis_schema_version = 4.0.0
8+
9+
10+
> # Intent definitions
11+
12+
## Get Weather Condition
13+
- current weather ?
14+
- do {@Location=florida} residents usually need ice scrapers
15+
- get {@Location=florence} temperature in september
16+
- get for me the weather conditions in {@Location=sonoma county}
17+
- get the daily temperature {@Location=greenwood indiana}
18+
- get the weather at {@Location=saint george utah}
19+
- how much rain does {@Location=chambersburg} get a year
20+
- show average rainfall for {@Location=boise}
21+
- temperature of {@Location=delhi} in celsius please
22+
- was last year about this time as wet as it is now in the {@Location=south} ?
23+
- what is the rain volume in {@Location=sonoma county} ?
24+
- what to wear in march in {@Location=california}
25+
- what's the weather like in {@Location=minneapolis}
26+
- weather in {@Location_PatternAny}
27+
- how's the weather in {@Location_PatternAny}
28+
- current weather in {@Location_PatternAny}
29+
30+
31+
## Get Weather Forecast
32+
- forecast in celcius
33+
- get the forcast for me
34+
- i want to know the temperature at {@Location=death valley}
35+
- provide me by {@Location=toronto} weather please
36+
- show me the forecast at {@Location=alabama}
37+
- soliciting today's weather
38+
- what is the weather in {@Location=redmond} ?
39+
- what is the weather today at 10 day {@Location=durham} ?
40+
- what will the weather be tomorrow in {@Location=new york} ?
41+
- what's the weather going to be like in {@Location=hawaii} ?
42+
- will it be raining in {@Location=ranchi}
43+
- will it rain this weekend
44+
- will it snow today
45+
- what's the forecast for next week in {@Location_PatternAny}
46+
- show me the forecast for {@Location_PatternAny}
47+
- what's the forecast for {@Location_PatternAny}
48+
49+
50+
## None
51+
52+
53+
> # Entity definitions
54+
55+
@ ml Location
56+
57+
58+
> # PREBUILT Entity definitions
59+
60+
61+
> # Phrase list definitions
62+
63+
64+
> # List entities
65+
66+
> # RegEx entities
67+
68+
69+
> # Pattern.Any entities
70+
71+
@ patternany Location_PatternAny
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ?store hours
2+
```
3+
Most our stores are open M-F 9AM-10PM.
4+
```
5+
**Prompts:**
6+
- [Seattle store](#1)
7+
- [Portland store](#2)
8+
9+
<a id = "1"></a>
10+
11+
# ?seattle
12+
```
13+
The Seattle store is open M-F 9AM-10PM.
14+
```
15+
16+
<a id = "2"></a>
17+
18+
# ?when is the portland store open
19+
- portland store hours
20+
```
21+
The Portland store is open 24/7.
22+
```

packages/orchestratorlib/test/orchestratorhelper.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ describe('Test Suite - orchestratorhelper', () => {
425425
assert.ok((utteranceEntityLabelsMap.get(utterance) as Label[]).length === 3,
426426
`(utteranceEntityLabelsMap.get(utterance) as Label[]).length=${(utteranceEntityLabelsMap.get(utterance) as Label[]).length}`);
427427
});
428-
429428
it('Test.0300 OrchestratorHelper.getJsonIntentEntityScoresUtterances()', function () {
430429
Utility.resetFlagToPrintDebuggingLogToConsole(UnitTestHelper.getDefaultUnitTestDebuggingLogFlag());
431430
this.timeout(UnitTestHelper.getDefaultUnitTestTimeout());
@@ -588,4 +587,54 @@ describe('Test Suite - orchestratorhelper', () => {
588587
assert.ok(result.has('Add item'), 'Incorrect result from getUtteranceLabelsMap, missing Add item utterance');
589588
assert.ok(result.has('delete to do go shopping'), 'Incorrect result from getUtteranceLabelsMap, missing delete to do go shopping utterance');
590589
});
590+
it('Test.0600 OrchestratorHelper.parseQnaFile()', async () => {
591+
const validFile: string = './test/fixtures/parser/valid.qna';
592+
const inValidFile: string = './test/fixtures/parser/invalid.qna';
593+
const utteranceLabelsMap: Map<string, Set<string>> = new Map<string, Set<string>>();
594+
const utteranceLabelDuplicateMap: Map<string, Set<string>> = new Map<string, Set<string>>();
595+
try {
596+
await OrchestratorHelper.parseQnaFile(
597+
inValidFile,
598+
'',
599+
utteranceLabelsMap,
600+
utteranceLabelDuplicateMap);
601+
assert.fail('Invalid syntax exception is not thrown.');
602+
} catch {}
603+
assert.ok(utteranceLabelsMap.size === 0);
604+
await OrchestratorHelper.parseQnaFile(
605+
validFile,
606+
'',
607+
utteranceLabelsMap,
608+
utteranceLabelDuplicateMap);
609+
assert.ok(utteranceLabelsMap.size > 0);
610+
});
611+
it('Test.0600 OrchestratorHelper.parseLuFile()', async () => {
612+
const validFile: string = './test/fixtures/parser/valid.lu';
613+
const inValidFile: string = './test/fixtures/parser/invalid.lu';
614+
const utteranceLabelsMap: Map<string, Set<string>> = new Map<string, Set<string>>();
615+
const utteranceLabelDuplicateMap: Map<string, Set<string>> = new Map<string, Set<string>>();
616+
const utteranceEntityLabelsMap: Map<string, Label[]> = new Map<string, Label[]>();
617+
const utteranceEntityLabelDuplicateMap: Map<string, Label[]> = new Map<string, Label[]>();
618+
619+
try {
620+
await OrchestratorHelper.parseLuFile(
621+
inValidFile,
622+
'',
623+
utteranceLabelsMap,
624+
utteranceLabelDuplicateMap,
625+
utteranceEntityLabelsMap,
626+
utteranceEntityLabelDuplicateMap);
627+
assert.fail('Invalid syntax exception is not thrown.');
628+
} catch {}
629+
assert.ok(utteranceLabelsMap.size === 0);
630+
631+
await OrchestratorHelper.parseLuFile(
632+
validFile,
633+
'',
634+
utteranceLabelsMap,
635+
utteranceLabelDuplicateMap,
636+
utteranceEntityLabelsMap,
637+
utteranceEntityLabelDuplicateMap);
638+
assert.ok(utteranceLabelsMap.size > 0);
639+
});
591640
});

0 commit comments

Comments
 (0)