fix(kb.gbapp): Spelling set before translation.
This commit is contained in:
parent
4927959a5c
commit
bfbbf69690
1 changed files with 25 additions and 14 deletions
|
@ -114,7 +114,7 @@ export class AskDialog extends IGBDialog {
|
||||||
return false;
|
return false;
|
||||||
}; // TODO: Encapsulate.
|
}; // TODO: Encapsulate.
|
||||||
|
|
||||||
let query = step.result;
|
let text = step.result;
|
||||||
|
|
||||||
let locale = 'en';
|
let locale = 'en';
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
|
@ -124,34 +124,45 @@ export class AskDialog extends IGBDialog {
|
||||||
minBoot.instance.textAnalyticsEndpoint
|
minBoot.instance.textAnalyticsEndpoint
|
||||||
? minBoot.instance.textAnalyticsEndpoint
|
? minBoot.instance.textAnalyticsEndpoint
|
||||||
: minBoot.instance.textAnalyticsEndpoint,
|
: minBoot.instance.textAnalyticsEndpoint,
|
||||||
query
|
text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
const member = step.context.activity.from;
|
const member = step.context.activity.from;
|
||||||
|
|
||||||
|
// Spells check the input text before translating.
|
||||||
|
|
||||||
|
const key = min.instance.spellcheckerKey ? min.instance.spellcheckerKey : min.instance.spellcheckerKey;
|
||||||
|
if (key) {
|
||||||
|
const data = await AzureText.getSpelledText(min.instance.spellcheckerKey, text);
|
||||||
|
if (data !== text) {
|
||||||
|
GBLog.info(`Spelling corrected (3): ${data}`);
|
||||||
|
text = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
const user = await sec.ensureUser(min.instance.instanceId, member.id, member.name, '', 'web', member.name);
|
||||||
user.locale = locale;
|
user.locale = locale;
|
||||||
await user.save();
|
await user.save();
|
||||||
const notTranslatedQuery = query;
|
const notTranslatedQuery = text;
|
||||||
query = await min.conversationalService.translate(
|
text = await min.conversationalService.translate(
|
||||||
min,
|
min,
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
query,
|
text,
|
||||||
'en'
|
'en'
|
||||||
);
|
);
|
||||||
GBLog.info(`Translated text (3): ${query}.`);
|
GBLog.info(`Translated text (3): ${text}.`);
|
||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||||
if (
|
if (
|
||||||
await e.onExchangeData(min, 'handleAnswer', {
|
await e.onExchangeData(min, 'handleAnswer', {
|
||||||
query: query,
|
query: text,
|
||||||
step: step,
|
step: step,
|
||||||
notTranslatedQuery: notTranslatedQuery,
|
notTranslatedQuery: notTranslatedQuery,
|
||||||
message: query,
|
message: text,
|
||||||
user: user ? user['dataValues'] : null
|
user: user ? user['dataValues'] : null
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
|
@ -161,7 +172,7 @@ export class AskDialog extends IGBDialog {
|
||||||
|
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
return await step.beginDialog('/answer', {
|
return await step.beginDialog('/answer', {
|
||||||
query: query
|
query: text
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return await step.next();
|
return await step.next();
|
||||||
|
@ -194,18 +205,18 @@ export class AskDialog extends IGBDialog {
|
||||||
text = data;
|
text = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translates text before sending Search or NLP.
|
// Translates text before sending Search or NLP.
|
||||||
|
|
||||||
text = await min.conversationalService.translate(
|
text = await min.conversationalService.translate(
|
||||||
min,
|
min,
|
||||||
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
|
||||||
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
|
||||||
text,
|
text,
|
||||||
userDb.locale ? userDb.locale : 'en'
|
userDb.locale ? userDb.locale : 'en'
|
||||||
);
|
);
|
||||||
|
|
||||||
GBLog.info(`Translated text (2): ${text}`);
|
GBLog.info(`Translated text (2): ${text}`);
|
||||||
|
|
||||||
if (!text) {
|
if (!text) {
|
||||||
throw new Error(`/answer being called with no args query text.`);
|
throw new Error(`/answer being called with no args query text.`);
|
||||||
|
@ -255,7 +266,7 @@ export class AskDialog extends IGBDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Put braces in this IF statment.
|
// TODO: Put braces in this IF statment.
|
||||||
|
|
||||||
if (resultsB.answer)
|
if (resultsB.answer)
|
||||||
// Sends the answer to all outputs, including projector.
|
// Sends the answer to all outputs, including projector.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue