mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: correct entity data type
This commit is contained in:
parent
9f14e9ec19
commit
22c98f01ea
@ -16,7 +16,7 @@ import { CONSOLE_CHANNEL_NAME } from '@/extensions/channels/console/settings';
|
||||
import { NLU } from '@/helper/types';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { LanguageService } from '@/i18n/services/language.service';
|
||||
import { NlpCacheMapValues } from '@/nlp/schemas/types';
|
||||
import { NlpEntityFull } from '@/nlp/schemas/nlp-entity.schema';
|
||||
import { NlpEntityService } from '@/nlp/services/nlp-entity.service';
|
||||
import { PluginService } from '@/plugins/plugins.service';
|
||||
import { PluginType } from '@/plugins/types';
|
||||
@ -403,7 +403,6 @@ export class BlockService extends BaseService<
|
||||
const matchedEntity: NLU.ParseEntity | undefined = nlp.entities.find(
|
||||
(e) => this.matchesEntityData(e, pattern, entityData!),
|
||||
);
|
||||
|
||||
return this.computePatternScore(
|
||||
matchedEntity,
|
||||
pattern,
|
||||
@ -434,11 +433,11 @@ export class BlockService extends BaseService<
|
||||
private matchesEntityData(
|
||||
e: NLU.ParseEntity,
|
||||
pattern: NlpPattern,
|
||||
entityData: NlpCacheMapValues,
|
||||
entityData: NlpEntityFull,
|
||||
): boolean {
|
||||
return (
|
||||
e.entity === pattern.entity &&
|
||||
entityData?.values.some((v) => v === e.value) &&
|
||||
entityData.values?.some((v) => v.value === e.value) &&
|
||||
(pattern.match !== 'value' || e.value === pattern.value)
|
||||
);
|
||||
}
|
||||
@ -455,7 +454,7 @@ export class BlockService extends BaseService<
|
||||
private computePatternScore(
|
||||
entity: NLU.ParseEntity | undefined,
|
||||
pattern: NlpPattern,
|
||||
entityData: NlpCacheMapValues,
|
||||
entityData: NlpEntityFull,
|
||||
nlpPenaltyFactor: number,
|
||||
): number {
|
||||
if (!entity || !entity.confidence) return 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { NlpEntityStub } from './nlp-entity.schema';
|
||||
import { NlpEntityFull, NlpEntityStub } from './nlp-entity.schema';
|
||||
import { NlpValueStub } from './nlp-value.schema';
|
||||
|
||||
export interface NlpSampleEntityValue {
|
||||
@ -26,10 +26,4 @@ export enum NlpSampleState {
|
||||
inbox = 'inbox',
|
||||
}
|
||||
|
||||
export type NlpCacheMap = Map<string, NlpCacheMapValues>;
|
||||
|
||||
export type NlpCacheMapValues = {
|
||||
id: string;
|
||||
weight: number;
|
||||
values: string[];
|
||||
};
|
||||
export type NlpCacheMap = Map<string, NlpEntityFull>;
|
||||
|
@ -63,17 +63,74 @@ export const mockNlpCacheMap: NlpCacheMap = new Map([
|
||||
[
|
||||
'intent',
|
||||
{
|
||||
id: '67e3e41eff551ca5be70559c',
|
||||
id: '1',
|
||||
weight: 1,
|
||||
values: ['greeting', 'affirmation'],
|
||||
name: 'intent',
|
||||
values: [
|
||||
{
|
||||
id: '11',
|
||||
value: 'greeting',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
doc: '',
|
||||
entity: '1',
|
||||
builtin: false,
|
||||
metadata: {},
|
||||
expressions: [],
|
||||
},
|
||||
{
|
||||
id: '12',
|
||||
value: 'affirmation',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
doc: '',
|
||||
entity: '1',
|
||||
builtin: false,
|
||||
metadata: {},
|
||||
expressions: [],
|
||||
},
|
||||
],
|
||||
lookups: ['trait'],
|
||||
builtin: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
],
|
||||
[
|
||||
'firstname',
|
||||
|
||||
{
|
||||
id: '67e3e41eff551ca5be70559d',
|
||||
id: '2',
|
||||
weight: 1,
|
||||
values: ['jhon', 'doe'],
|
||||
name: 'firstname',
|
||||
values: [
|
||||
{
|
||||
id: '21',
|
||||
value: 'jhon',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
doc: '',
|
||||
entity: '2',
|
||||
builtin: false,
|
||||
metadata: {},
|
||||
expressions: [],
|
||||
},
|
||||
{
|
||||
id: '22',
|
||||
value: 'doe',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
doc: '',
|
||||
entity: '2',
|
||||
builtin: false,
|
||||
metadata: {},
|
||||
expressions: [],
|
||||
},
|
||||
],
|
||||
lookups: ['trait'],
|
||||
builtin: false,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user