fix(core.gbapp): Fix in NLP handling of acents.
This commit is contained in:
parent
e7d7a1a4b2
commit
2a5ecd487f
8 changed files with 70 additions and 52 deletions
|
@ -1,34 +1,9 @@
|
||||||
|
|
||||||
export const Messages = {
|
export const Messages = {
|
||||||
global_quit: /^(sair|sai|chega|exit|quit|finish|end|ausfahrt|verlassen)/i,
|
|
||||||
'en-US': {
|
'en-US': {
|
||||||
show_video: 'I will show you a video, please wait...',
|
|
||||||
good_morning: 'good morning',
|
|
||||||
good_evening: 'good evening',
|
|
||||||
good_night: 'good night',
|
|
||||||
hi: (msg) => `Hello, ${msg}.`,
|
|
||||||
very_sorry_about_error: `I'm sorry to inform that there was an error which was recorded to be solved.`,
|
|
||||||
canceled: 'Canceled. If I can be useful, let me know how',
|
|
||||||
whats_email: 'What\'s your E-mail address?',
|
|
||||||
which_language: 'Please, type the language name you would like to talk through.',
|
|
||||||
validation_enter_valid_email: 'Please enter a valid e-mail.' ,
|
|
||||||
language_chosen: 'Very good, so let\'s go...' ,
|
|
||||||
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum|si|y|yes|sure)/i
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'pt-BR': {
|
'pt-BR': {
|
||||||
show_video: 'Vou te mostrar um vídeo. Por favor, aguarde...',
|
|
||||||
good_morning: 'bom dia',
|
|
||||||
good_evening: 'boa tarde',
|
|
||||||
good_night: 'boa noite',
|
|
||||||
hi: (msg) => `Oi, ${msg}.`,
|
|
||||||
very_sorry_about_error: `Lamento, ocorreu um erro que já foi registrado para ser tratado.`,
|
|
||||||
canceled: 'Cancelado, avise como posso ser útil novamente.',
|
|
||||||
whats_email: 'Qual seu e-mail?',
|
|
||||||
which_language: 'Por favor, digite o idioma que você gostaria de usar para conversarmos.',
|
|
||||||
validation_enter_valid_email: 'Por favor digite um email válido.',
|
|
||||||
language_chosen: 'Muito bem, então vamos lá...' ,
|
|
||||||
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum|si|y|yes|sure)/i
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,10 +46,10 @@ import { SecService } from '../../security.gbapp/services/SecService';
|
||||||
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService';
|
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService';
|
||||||
import { MicrosoftAppCredentials } from 'botframework-connector';
|
import { MicrosoftAppCredentials } from 'botframework-connector';
|
||||||
import { GBConfigService } from './GBConfigService';
|
import { GBConfigService } from './GBConfigService';
|
||||||
|
import { CollectionUtil, AzureText } from 'pragmatismo-io-framework';
|
||||||
const urlJoin = require('url-join');
|
const urlJoin = require('url-join');
|
||||||
const PasswordGenerator = require('strict-password-generator').default;
|
const PasswordGenerator = require('strict-password-generator').default;
|
||||||
const Nexmo = require('nexmo');
|
const Nexmo = require('nexmo');
|
||||||
import { CollectionUtil, AzureText } from 'pragmatismo-io-framework';
|
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
const shell = require('any-shell-escape');
|
const shell = require('any-shell-escape');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
@ -60,23 +60,25 @@ const fs = require('fs');
|
||||||
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
|
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
|
||||||
const { IamAuthenticator } = require('ibm-watson/auth');
|
const { IamAuthenticator } = require('ibm-watson/auth');
|
||||||
|
|
||||||
export interface LanguagePickerSettings {
|
|
||||||
defaultLocale?: string;
|
|
||||||
supportedLocales?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides basic services for handling messages and dispatching to back-end
|
* Provides basic services for handling messages and dispatching to back-end
|
||||||
* services like NLP or Search.
|
* services like NLP or Search.
|
||||||
*/
|
*/
|
||||||
export class GBConversationalService {
|
export class GBConversationalService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the core service.
|
||||||
|
*/
|
||||||
public coreService: IGBCoreService;
|
public coreService: IGBCoreService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param coreService
|
||||||
|
*/
|
||||||
constructor(coreService: IGBCoreService) {
|
constructor(coreService: IGBCoreService) {
|
||||||
this.coreService = coreService;
|
this.coreService = coreService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static defaultDiacriticsRemovalMap = [
|
static defaultDiacriticsRemovalMap = [
|
||||||
{ 'base': 'A', 'letters': '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F' },
|
{ 'base': 'A', 'letters': '\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F' },
|
||||||
{ 'base': 'AA', 'letters': '\uA732' },
|
{ 'base': 'AA', 'letters': '\uA732' },
|
||||||
|
|
|
@ -100,7 +100,7 @@ export class GBCoreService implements IGBCoreService {
|
||||||
private dialect: string;
|
private dialect: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor retrieves default values.
|
*
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.adminService = new GBAdminService(this);
|
this.adminService = new GBAdminService(this);
|
||||||
|
|
|
@ -800,6 +800,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
'whatsapp.gblib',
|
'whatsapp.gblib',
|
||||||
'sharepoint.gblib',
|
'sharepoint.gblib',
|
||||||
'core.gbapp',
|
'core.gbapp',
|
||||||
|
'basic.gblib',
|
||||||
'admin.gbapp',
|
'admin.gbapp',
|
||||||
'azuredeployer.gbapp',
|
'azuredeployer.gbapp',
|
||||||
'customer-satisfaction.gbapp',
|
'customer-satisfaction.gbapp',
|
||||||
|
|
|
@ -62,7 +62,7 @@ import {
|
||||||
IGBInstance,
|
IGBInstance,
|
||||||
IGBPackage
|
IGBPackage
|
||||||
} from 'botlib';
|
} from 'botlib';
|
||||||
import { AzureText, CollectionUtil } from 'pragmatismo-io-framework';
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
|
|
||||||
import { MicrosoftAppCredentials } from 'botframework-connector';
|
import { MicrosoftAppCredentials } from 'botframework-connector';
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
|
@ -112,8 +112,6 @@ export class GBMinService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static initialization of minimal instance.
|
* Static initialization of minimal instance.
|
||||||
*
|
|
||||||
* @param core Basic database services to identify instance, for example.
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
core: IGBCoreService,
|
core: IGBCoreService,
|
||||||
|
@ -984,18 +982,36 @@ export class GBMinService {
|
||||||
keepTextList = keepTextList.concat(result);
|
keepTextList = keepTextList.concat(result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let textProcessed = GBConversationalService.removeDiacritics(text);
|
|
||||||
|
const getNormalizedRegExp = (value) => {
|
||||||
|
var chars = [
|
||||||
|
{ letter: 'a', reg: '[aáàãäâ]' },
|
||||||
|
{ letter: 'e', reg: '[eéèëê]' },
|
||||||
|
{ letter: 'i', reg: '[iíìïî]' },
|
||||||
|
{ letter: 'o', reg: '[oóòõöô]' },
|
||||||
|
{ letter: 'u', reg: '[uúùüû]' },
|
||||||
|
{ letter: 'c', reg: '[cç]' }
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var i in chars) {
|
||||||
|
value = value.replace(new RegExp(chars[i].letter, 'gi'), chars[i].reg);
|
||||||
|
};
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
let textProcessed = text;
|
||||||
if (keepTextList) {
|
if (keepTextList) {
|
||||||
keepTextList = keepTextList.filter(p => p.trim() !== '');
|
keepTextList = keepTextList.filter(p => p.trim() !== '');
|
||||||
let i = 0;
|
let i = 0;
|
||||||
await CollectionUtil.asyncForEach(keepTextList, item => {
|
await CollectionUtil.asyncForEach(keepTextList, item => {
|
||||||
const it = GBConversationalService.removeDiacritics(item);
|
const it = GBConversationalService.removeDiacritics(item);
|
||||||
|
const noAccentText = GBConversationalService.removeDiacritics(textProcessed);
|
||||||
|
|
||||||
if (textProcessed.toLowerCase().indexOf(it.toLowerCase()) != -1) {
|
if (noAccentText.toLowerCase().indexOf(it.toLowerCase()) != -1) {
|
||||||
const replacementToken = 'X' + GBAdminService.getNumberIdentifier().substr(0, 4);
|
const replacementToken = 'X' + GBAdminService.getNumberIdentifier().substr(0, 4);
|
||||||
replacements[i] = { text: item, replacementToken: replacementToken };
|
replacements[i] = { text: item, replacementToken: replacementToken };
|
||||||
i++;
|
i++;
|
||||||
textProcessed = textProcessed.replace(new RegExp(`\\b${it.trim()}\\b`, 'gi'), `${replacementToken}`);
|
textProcessed = textProcessed.replace(new RegExp(`\\b${getNormalizedRegExp(it.trim())}\\b`, 'gi'), `${replacementToken}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,33 @@
|
||||||
export const Messages = {
|
export const Messages = {
|
||||||
global_quit: /^(sair|sai|chega|exit|quit|finish|end|ausfahrt|verlassen)/i,
|
global_quit: /^(sair|sai|chega|exit|quit|finish|end|ausfahrt|verlassen)/i,
|
||||||
'en-US': {
|
'en-US': {
|
||||||
|
show_video: 'I will show you a video, please wait...',
|
||||||
|
good_morning: 'good morning',
|
||||||
|
good_evening: 'good evening',
|
||||||
|
good_night: 'good night',
|
||||||
|
hi: (msg) => `Hello, ${msg}.`,
|
||||||
|
very_sorry_about_error: `I'm sorry to inform that there was an error which was recorded to be solved.`,
|
||||||
|
canceled: 'Canceled. If I can be useful, let me know how',
|
||||||
|
whats_email: 'What\'s your E-mail address?',
|
||||||
|
which_language: 'Please, type the language name you would like to talk through.',
|
||||||
|
validation_enter_valid_email: 'Please enter a valid e-mail.',
|
||||||
|
language_chosen: 'Very good, so let\'s go...',
|
||||||
|
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum|si|y|yes|sure)/i
|
||||||
|
|
||||||
},
|
},
|
||||||
'pt-BR': {
|
'pt-BR': {
|
||||||
|
show_video: 'Vou te mostrar um vídeo. Por favor, aguarde...',
|
||||||
|
good_morning: 'bom dia',
|
||||||
|
good_evening: 'boa tarde',
|
||||||
|
good_night: 'boa noite',
|
||||||
|
hi: (msg) => `Oi, ${msg}.`,
|
||||||
|
very_sorry_about_error: `Lamento, ocorreu um erro que já foi registrado para ser tratado.`,
|
||||||
|
canceled: 'Cancelado, avise como posso ser útil novamente.',
|
||||||
|
whats_email: 'Qual seu e-mail?',
|
||||||
|
which_language: 'Por favor, digite o idioma que você gostaria de usar para conversarmos.',
|
||||||
|
validation_enter_valid_email: 'Por favor digite um email válido.',
|
||||||
|
language_chosen: 'Muito bem, então vamos lá...',
|
||||||
|
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum|si|y|yes|sure)/i
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
BIN
packages/default.gbtest/first-test.xlsx
Normal file
BIN
packages/default.gbtest/first-test.xlsx
Normal file
Binary file not shown.
|
@ -116,9 +116,11 @@ export class AskDialog extends IGBDialog {
|
||||||
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);
|
||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
|
let nextDialog = null;
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
await CollectionUtil.asyncForEach(min.appPackages, async (e: IGBPackage) => {
|
||||||
if (
|
if (
|
||||||
await e.onExchangeData(min, 'handleAnswer', {
|
nextDialog = await e.onExchangeData(min, 'handleAnswer', {
|
||||||
query: text,
|
query: text,
|
||||||
step: step,
|
step: step,
|
||||||
message: text,
|
message: text,
|
||||||
|
@ -129,16 +131,14 @@ export class AskDialog extends IGBDialog {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!handled) {
|
await step.beginDialog(nextDialog ? nextDialog : '/answer', {
|
||||||
return await step.beginDialog('/answer', {
|
query: text,
|
||||||
query: text
|
user: user ? user['dataValues'] : null,
|
||||||
|
message: text
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return await step.next();
|
return await step.next();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return await step.next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue