fix(kb.gbapp): #276 use of NLP.js upgrade to v4.

This commit is contained in:
rodrigorodriguez 2023-02-27 19:17:52 -03:00
parent 5c48d39620
commit ec1c38f378
4 changed files with 45 additions and 17 deletions

View file

@ -223,6 +223,11 @@ export class GBVMService extends GBService {
let httpPs = this.httpPs;
let page = null;
for(i in this.variables) {
global[i] = this.variables[i];
}
debugger;
// Local functions.
@ -345,13 +350,14 @@ export class GBVMService extends GBService {
// Auto-NLP generates BASIC variables related to entities.
if (text && min['nerEngine']) {
const result = await min['nerEngine'].process(text);
let variables = [];
if (step ? step.context.activity.originalText : null && min['nerEngine']) {
const result = await min['nerEngine'].process(step.context.activity.originalText);
for (let i = 0; i < result.entities.length; i++) {
const v = result.entities[i];
const variableName = `${v.entity}`;
sandbox[variableName] = v.option;
variables[variableName] = v.option ? v.option : v.sourceText;
}
}
@ -368,6 +374,7 @@ export class GBVMService extends GBService {
instanceId: min.instance.instanceId
};
sandbox['variables'] = variables;
sandbox['id'] = dk.sys().getRandomId();
sandbox['username'] = await dk.userName({ pid });
sandbox['mobile'] = await dk.userMobile({ pid });

View file

@ -720,6 +720,8 @@ export class GBDeployer implements IGBDeployer {
GBLogEx.info(instance.instanceId, `Acquiring rebuildIndex mutex...`);
release = await GBServer.globals.indexSemaphore.acquire();
GBLogEx.info(instance.instanceId, `Acquire rebuildIndex done.`);
// Prepares search.
const search = new AzureSearch(
instance.searchKey,
instance.searchHost,
@ -728,12 +730,15 @@ export class GBDeployer implements IGBDeployer {
);
const connectionString = GBDeployer.getConnectionStringFromInstance(instance);
const dsName = 'gb';
// Removes any previous index.
try {
await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString);
await search.deleteDataSource(dsName);
} catch (err) {
// If it is a 404 there is nothing to delete as it is the first creation.
if (err.code !== 400 && err.message.indexOf('already exists') !==-1) {
if (err.code !== 404) {
throw err;
}
}
@ -741,16 +746,25 @@ export class GBDeployer implements IGBDeployer {
// Removes the index.
try {
await search.createIndex(searchSchema, dsName);
await search.deleteIndex();
} catch (err) {
// If it is a 404 there is nothing to delete as it is the first creation.
if (err.code !== 'ResourceNameAlreadyInUse') {
if (err.code !== 404 && err.code !== 'OperationNotAllowed') {
throw err;
}
}
await search.rebuildIndex(instance.searchIndexer);
// Creates the data source and index on the cloud.
try {
await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString);
} catch (err) {
GBLog.error(err);
throw err;
}
await search.createIndex(searchSchema, dsName);
release();
GBLogEx.info(instance.instanceId, `Released rebuildIndex mutex.`);
} catch {

View file

@ -667,7 +667,7 @@ export class GBMinService {
// NLP Manager.
const manager = new NlpManager({ languages: ['en'], forceNER: true });
const manager = new NlpManager({ languages: ['pt'], forceNER: true });
min['nerEngine'] = manager;
if (GBServer.globals.minBoot === undefined) {

View file

@ -959,11 +959,18 @@ export class KBService implements IGBKBService {
const categoryReg = /.*\((.*)\).*/gi.exec(text);
const nameReg = /(\w+)\(.*\).*/gi.exec(text);
if (categoryReg && nameReg) {
if (categoryReg) {
let category = categoryReg[1];
if (category === 'number') {
min['nerEngine'].addRegexEntity('number','pt', '/d+/gi');
}
if (nameReg) {
let name = nameReg[1];
min['nerEngine'].addNamedEntityText(category, name, [contentLocale], [name]);
}
}
});
}