* surface parsing error to bf cli users

* added tests

* fixed lint errors

* Update orchestratorhelper.ts

* Update orchestratorhelper.ts

fixed lint error
This commit is contained in:
Tien Suwandy 2021-09-16 17:00:06 -07:00 коммит произвёл GitHub
Родитель 7a936c1981
Коммит b68865298a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 195 добавлений и 28 удалений

2
.vscode/launch.json поставляемый
Просмотреть файл

@ -15,7 +15,7 @@
"999999",
"--colors",
"-g",
".*addAsync.*"
"Test.0600 OrchestratorHelper.parseLuFile()"
],
"cwd": "${workspaceFolder}/packages/orchestratorlib",
"internalConsoleOptions": "openOnSessionStart",

Просмотреть файл

@ -81,7 +81,7 @@ export default class OrchestratorCreate extends Command {
settings.SnapshotPath = snapshotFilePath;
settings.persist();
} catch (error) {
throw (new CLIError(error));
throw (new CLIError(error as Error));
}
}

Просмотреть файл

@ -352,7 +352,7 @@ export class OrchestratorHelper {
default: throw new Error(`Unknown file type ${ext}`);
}
} catch (error) {
} catch (error: any) {
throw new Error(`${error.message}${os.EOL}Failed to parse ${filePath}`);
}
}
@ -421,15 +421,15 @@ export class OrchestratorHelper {
if (!luContent || luContent.length === 0) {
return;
}
const luObject: any = {
content: luContent,
id: luFile,
};
const luisObject: any = await LuisBuilder.fromLUAsync([luObject], OrchestratorHelper.findLuFiles);
if (Utility.toPrintDetailedDebuggingLogToConsole) {
UtilityDispatcher.debuggingNamedLog1('OrchestratorHelper.parseLuContent(): calling getIntentsEntitiesUtterances()', luisObject, 'luisObject');
}
try {
const luObject: any = {
content: luContent,
id: luFile,
};
const luisObject: any = await LuisBuilder.fromLUAsync([luObject], OrchestratorHelper.findLuFiles);
if (Utility.toPrintDetailedDebuggingLogToConsole) {
UtilityDispatcher.debuggingNamedLog1('OrchestratorHelper.parseLuContent(): calling getIntentsEntitiesUtterances()', luisObject, 'luisObject');
}
const rvLu: boolean = OrchestratorHelper.getIntentsEntitiesUtterances(
luisObject,
hierarchicalLabel,
@ -440,9 +440,8 @@ export class OrchestratorHelper {
if (!rvLu) {
throw new Error('Failed to parse LUIS or JSON file on intent/entity labels');
}
} catch (error) {
Utility.debuggingLog(`EXCEPTION calling getIntentsEntitiesUtterances(), error=${error}`);
throw error;
} catch (error: any) {
throw new Error(`Failed parsing lu file ${luFile} ${error.text}`);
}
}
@ -602,20 +601,19 @@ export class OrchestratorHelper {
return;
}
const newlines: string[] = [];
lines.forEach((line: string) => {
if (line.toLowerCase().indexOf('@qna.pair.source =') < 0) {
newlines.push(line);
}
});
// Utility.debuggingLog('OrchestratorHelper.parseQnaFile() ready to call QnaMakerBuilder.fromContent()');
const qnaNormalized: string = Utility.cleanStringOnTabs(newlines.join('\n')); // ---- NOTE ---- QnaMakerBuilder does not like TAB
const qnaObject: any = await QnaMakerBuilder.fromContent(qnaNormalized);
if (qnaObject) {
try {
const newlines: string[] = [];
lines.forEach((line: string) => {
if (line.toLowerCase().indexOf('@qna.pair.source =') < 0) {
newlines.push(line);
}
});
// Utility.debuggingLog('OrchestratorHelper.parseQnaFile() ready to call QnaMakerBuilder.fromContent()');
const qnaNormalized: string = Utility.cleanStringOnTabs(newlines.join('\n')); // ---- NOTE ---- QnaMakerBuilder does not like TAB
const qnaObject: any = await QnaMakerBuilder.fromContent(qnaNormalized);
OrchestratorHelper.getQnaQuestionsAsUtterances(qnaObject, hierarchicalLabel, utteranceLabelsMap, utteranceLabelDuplicateMap);
} else {
throw new Error(`Failed parsing qna file ${qnaFile}`);
} catch (error: any) {
throw new Error(`Failed parsing qna file ${qnaFile} ${error.text}`);
}
}

17
packages/orchestratorlib/test/fixtures/parser/invalid.lu поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
> LUIS application information
> !# @app.name = Weather
> !# @app.desc = Weather LUIS application - Bot Builder Samples
> !# @app.versionId = 0.1
> !# @app.culture = en-us
> !# @app.luis_schema_version = 4.0.0
> # Intent definitions
- current weather ?
- do {@Location=florida} residents usually need ice
## Get Weather Forecast
- forecast in celcius
- get the forcast for me
- i want to know the temperature at {@Location=death valley}

10
packages/orchestratorlib/test/fixtures/parser/invalid.qna поставляемый Normal file
Просмотреть файл

@ -0,0 +1,10 @@
**Prompts:**
- [Files that CannotSync
](#1)
<a id = "1"/>
## ? Files that CannotSync
```
Files that cannot sync.
```

71
packages/orchestratorlib/test/fixtures/parser/valid.lu поставляемый Normal file
Просмотреть файл

@ -0,0 +1,71 @@
> LUIS application information
> !# @app.name = Weather
> !# @app.desc = Weather LUIS application - Bot Builder Samples
> !# @app.versionId = 0.1
> !# @app.culture = en-us
> !# @app.luis_schema_version = 4.0.0
> # Intent definitions
## Get Weather Condition
- current weather ?
- do {@Location=florida} residents usually need ice scrapers
- get {@Location=florence} temperature in september
- get for me the weather conditions in {@Location=sonoma county}
- get the daily temperature {@Location=greenwood indiana}
- get the weather at {@Location=saint george utah}
- how much rain does {@Location=chambersburg} get a year
- show average rainfall for {@Location=boise}
- temperature of {@Location=delhi} in celsius please
- was last year about this time as wet as it is now in the {@Location=south} ?
- what is the rain volume in {@Location=sonoma county} ?
- what to wear in march in {@Location=california}
- what's the weather like in {@Location=minneapolis}
- weather in {@Location_PatternAny}
- how's the weather in {@Location_PatternAny}
- current weather in {@Location_PatternAny}
## Get Weather Forecast
- forecast in celcius
- get the forcast for me
- i want to know the temperature at {@Location=death valley}
- provide me by {@Location=toronto} weather please
- show me the forecast at {@Location=alabama}
- soliciting today's weather
- what is the weather in {@Location=redmond} ?
- what is the weather today at 10 day {@Location=durham} ?
- what will the weather be tomorrow in {@Location=new york} ?
- what's the weather going to be like in {@Location=hawaii} ?
- will it be raining in {@Location=ranchi}
- will it rain this weekend
- will it snow today
- what's the forecast for next week in {@Location_PatternAny}
- show me the forecast for {@Location_PatternAny}
- what's the forecast for {@Location_PatternAny}
## None
> # Entity definitions
@ ml Location
> # PREBUILT Entity definitions
> # Phrase list definitions
> # List entities
> # RegEx entities
> # Pattern.Any entities
@ patternany Location_PatternAny

22
packages/orchestratorlib/test/fixtures/parser/valid.qna поставляемый Normal file
Просмотреть файл

@ -0,0 +1,22 @@
# ?store hours
```
Most our stores are open M-F 9AM-10PM.
```
**Prompts:**
- [Seattle store](#1)
- [Portland store](#2)
<a id = "1"></a>
# ?seattle
```
The Seattle store is open M-F 9AM-10PM.
```
<a id = "2"></a>
# ?when is the portland store open
- portland store hours
```
The Portland store is open 24/7.
```

Просмотреть файл

@ -425,7 +425,6 @@ describe('Test Suite - orchestratorhelper', () => {
assert.ok((utteranceEntityLabelsMap.get(utterance) as Label[]).length === 3,
`(utteranceEntityLabelsMap.get(utterance) as Label[]).length=${(utteranceEntityLabelsMap.get(utterance) as Label[]).length}`);
});
it('Test.0300 OrchestratorHelper.getJsonIntentEntityScoresUtterances()', function () {
Utility.resetFlagToPrintDebuggingLogToConsole(UnitTestHelper.getDefaultUnitTestDebuggingLogFlag());
this.timeout(UnitTestHelper.getDefaultUnitTestTimeout());
@ -588,4 +587,54 @@ describe('Test Suite - orchestratorhelper', () => {
assert.ok(result.has('Add item'), 'Incorrect result from getUtteranceLabelsMap, missing Add item utterance');
assert.ok(result.has('delete to do go shopping'), 'Incorrect result from getUtteranceLabelsMap, missing delete to do go shopping utterance');
});
it('Test.0600 OrchestratorHelper.parseQnaFile()', async () => {
const validFile: string = './test/fixtures/parser/valid.qna';
const inValidFile: string = './test/fixtures/parser/invalid.qna';
const utteranceLabelsMap: Map<string, Set<string>> = new Map<string, Set<string>>();
const utteranceLabelDuplicateMap: Map<string, Set<string>> = new Map<string, Set<string>>();
try {
await OrchestratorHelper.parseQnaFile(
inValidFile,
'',
utteranceLabelsMap,
utteranceLabelDuplicateMap);
assert.fail('Invalid syntax exception is not thrown.');
} catch {}
assert.ok(utteranceLabelsMap.size === 0);
await OrchestratorHelper.parseQnaFile(
validFile,
'',
utteranceLabelsMap,
utteranceLabelDuplicateMap);
assert.ok(utteranceLabelsMap.size > 0);
});
it('Test.0600 OrchestratorHelper.parseLuFile()', async () => {
const validFile: string = './test/fixtures/parser/valid.lu';
const inValidFile: string = './test/fixtures/parser/invalid.lu';
const utteranceLabelsMap: Map<string, Set<string>> = new Map<string, Set<string>>();
const utteranceLabelDuplicateMap: Map<string, Set<string>> = new Map<string, Set<string>>();
const utteranceEntityLabelsMap: Map<string, Label[]> = new Map<string, Label[]>();
const utteranceEntityLabelDuplicateMap: Map<string, Label[]> = new Map<string, Label[]>();
try {
await OrchestratorHelper.parseLuFile(
inValidFile,
'',
utteranceLabelsMap,
utteranceLabelDuplicateMap,
utteranceEntityLabelsMap,
utteranceEntityLabelDuplicateMap);
assert.fail('Invalid syntax exception is not thrown.');
} catch {}
assert.ok(utteranceLabelsMap.size === 0);
await OrchestratorHelper.parseLuFile(
validFile,
'',
utteranceLabelsMap,
utteranceLabelDuplicateMap,
utteranceEntityLabelsMap,
utteranceEntityLabelDuplicateMap);
assert.ok(utteranceLabelsMap.size > 0);
});
});