Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port: Make Multi-language recognizer case-insensitive #3893

Merged
merged 3 commits into from
Aug 4, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ describe('MultiLanguageRecognizerTests', function () {
await TestUtils.runTestScript(resourceExplorer, 'MultiLanguageRecognizerTest_LocaleCaseInsensitivity');
});

it('Recognizer case insensitivity', async () => {
await TestUtils.runTestScript(resourceExplorer, 'MultiLanguageRecognizerTest_RecognizerCaseInsensitivity');
});

describe('Telemetry', () => {
const recognizer = createRecognizer();
let spy;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"recognizer": {
"$kind": "Microsoft.MultiLanguageRecognizer",
"recognizers": {
"en-us": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"pattern": "(?i)howdy"
},
{
"intent": "Goodbye",
"pattern": "(?i)bye"
}
]
},
"": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"pattern": "(?i)salve"
},
{
"intent": "Goodbye",
"pattern": "(?i)vale dicere"
}
]
}
}
},
"triggers": [
{
"$kind": "Microsoft.OnIntent",
"intent": "Greeting",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "greeting intent"
}
]
},
{
"$kind": "Microsoft.OnIntent",
"intent": "Goodbye",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "goodbye intent"
}
]
},
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "default rule"
}
]
}
],
"defaultResultProperty": "dialog.result"
},
"locale": "",
"languagePolicy": {
"": [ "en-US"]
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "howdy"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "greeting intent"
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "bye"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "goodbye intent"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,23 @@ export class MultiLanguageRecognizer extends AdaptiveRecognizer implements Multi
const locale = (activity.locale ?? '').toLowerCase();
const policy: string[] = [];
if (languagepolicy.has(locale)) {
languagepolicy.get(locale).forEach((u: string): number => policy.push(u));
policy.push(...languagepolicy.get(locale));
}

if (locale !== '' && languagepolicy.has('')) {
// we now explictly add defaultPolicy instead of coding that into target's policy
languagepolicy.get('').forEach((u: string): number => policy.push(u));
policy.push(...languagepolicy.get(''));
}

for (let i = 0; i < policy.length; i++) {
const option = policy[i];
if (this.recognizers.hasOwnProperty(option)) {
const recognizer = this.recognizers[option];
const lowercaseRecognizerKeyLookup = Object.keys(this.recognizers).reduce((acc, key) => {
acc[key.toLowerCase()] = key;
return acc;
}, {});

for (const option of policy) {
const recognizerKey = lowercaseRecognizerKeyLookup[option.toLowerCase()];
if (recognizerKey !== undefined) {
const recognizer = this.recognizers[recognizerKey];
const result = await recognizer.recognize(
dialogContext,
activity,
Expand Down