fix(kb.gbapp): #276 use of NLP.js upgrade to v4.
This commit is contained in:
parent
5c48d39620
commit
ec1c38f378
4 changed files with 45 additions and 17 deletions
|
@ -223,7 +223,12 @@ 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.
|
||||
|
||||
const ubound = (array) => {return array.length};
|
||||
|
@ -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 });
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -866,7 +866,7 @@ export class KBService implements IGBKBService {
|
|||
let menu;
|
||||
|
||||
// Detect menu level by skipping blank cells on left.
|
||||
|
||||
|
||||
let level;
|
||||
for (level = 0; level < MAX_LEVEL; level++) {
|
||||
const cell = row._cells[level];
|
||||
|
@ -876,9 +876,9 @@ export class KBService implements IGBKBService {
|
|||
}
|
||||
}
|
||||
|
||||
// Tree hierarchy calculation.
|
||||
// Tree hierarchy calculation.
|
||||
|
||||
if (level > lastLevel) {
|
||||
if (level > lastLevel) {
|
||||
childrenNode = activeObj.children;
|
||||
} else if (level < lastLevel) {
|
||||
childrenNode = activeChildrenGivenLevel[level];
|
||||
|
@ -891,7 +891,7 @@ export class KBService implements IGBKBService {
|
|||
activeChildrenGivenLevel[level] = childrenNode;
|
||||
|
||||
// Insert the object into JSON.
|
||||
const description = row._cells[level + 1]?row._cells[level + 1].text: null;
|
||||
const description = row._cells[level + 1] ? row._cells[level + 1].text : null;
|
||||
activeObj = {
|
||||
title: menu,
|
||||
description: description,
|
||||
|
@ -959,10 +959,17 @@ 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];
|
||||
let name = nameReg[1];
|
||||
min['nerEngine'].addNamedEntityText(category, name, [contentLocale], [name]);
|
||||
|
||||
if (category === 'number') {
|
||||
min['nerEngine'].addRegexEntity('number','pt', '/d+/gi');
|
||||
}
|
||||
if (nameReg) {
|
||||
let name = nameReg[1];
|
||||
|
||||
min['nerEngine'].addNamedEntityText(category, name, [contentLocale], [name]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue