mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: remove async from block score calculation
This commit is contained in:
parent
5ead99c41d
commit
aeee39249c
@ -434,13 +434,13 @@ describe('BlockService', () => {
|
|||||||
describe('calculateBlockScore', () => {
|
describe('calculateBlockScore', () => {
|
||||||
const nlpPenaltyFactor = 0.9;
|
const nlpPenaltyFactor = 0.9;
|
||||||
it('should calculate the correct NLP score for a block', async () => {
|
it('should calculate the correct NLP score for a block', async () => {
|
||||||
const score = await blockService.calculateBlockScore(
|
const score = blockService.calculateBlockScore(
|
||||||
mockNlpPatternsSetOne,
|
mockNlpPatternsSetOne,
|
||||||
mockNlpEntitiesSetOne,
|
mockNlpEntitiesSetOne,
|
||||||
mockNlpCacheMap,
|
mockNlpCacheMap,
|
||||||
nlpPenaltyFactor,
|
nlpPenaltyFactor,
|
||||||
);
|
);
|
||||||
const score2 = await blockService.calculateBlockScore(
|
const score2 = blockService.calculateBlockScore(
|
||||||
mockNlpPatternsSetTwo,
|
mockNlpPatternsSetTwo,
|
||||||
mockNlpEntitiesSetOne,
|
mockNlpEntitiesSetOne,
|
||||||
mockNlpCacheMap,
|
mockNlpCacheMap,
|
||||||
@ -453,13 +453,13 @@ describe('BlockService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should calculate the correct NLP score for a block and apply penalties ', async () => {
|
it('should calculate the correct NLP score for a block and apply penalties ', async () => {
|
||||||
const score = await blockService.calculateBlockScore(
|
const score = blockService.calculateBlockScore(
|
||||||
mockNlpPatternsSetOne,
|
mockNlpPatternsSetOne,
|
||||||
mockNlpEntitiesSetOne,
|
mockNlpEntitiesSetOne,
|
||||||
mockNlpCacheMap,
|
mockNlpCacheMap,
|
||||||
nlpPenaltyFactor,
|
nlpPenaltyFactor,
|
||||||
);
|
);
|
||||||
const score2 = await blockService.calculateBlockScore(
|
const score2 = blockService.calculateBlockScore(
|
||||||
mockNlpPatternsSetThree,
|
mockNlpPatternsSetThree,
|
||||||
mockNlpEntitiesSetOne,
|
mockNlpEntitiesSetOne,
|
||||||
mockNlpCacheMap,
|
mockNlpCacheMap,
|
||||||
@ -473,7 +473,7 @@ describe('BlockService', () => {
|
|||||||
|
|
||||||
it('should return 0 if no matching entities are found', async () => {
|
it('should return 0 if no matching entities are found', async () => {
|
||||||
const nlpCacheMap: NlpCacheMap = new Map();
|
const nlpCacheMap: NlpCacheMap = new Map();
|
||||||
const score = await blockService.calculateBlockScore(
|
const score = blockService.calculateBlockScore(
|
||||||
mockNlpPatternsSetTwo,
|
mockNlpPatternsSetTwo,
|
||||||
mockNlpEntitiesSetOne,
|
mockNlpEntitiesSetOne,
|
||||||
nlpCacheMap,
|
nlpCacheMap,
|
||||||
|
@ -412,7 +412,7 @@ export class BlockService extends BaseService<
|
|||||||
const block = blocks[i];
|
const block = blocks[i];
|
||||||
const patterns = matchedPatterns[i];
|
const patterns = matchedPatterns[i];
|
||||||
// If compatible, calculate the NLP score for this block
|
// If compatible, calculate the NLP score for this block
|
||||||
const nlpScore: number = await this.calculateBlockScore(
|
const nlpScore: number = this.calculateBlockScore(
|
||||||
patterns,
|
patterns,
|
||||||
nlp,
|
nlp,
|
||||||
nlpCacheMap,
|
nlpCacheMap,
|
||||||
@ -445,12 +445,12 @@ export class BlockService extends BaseService<
|
|||||||
* @param nlpPenaltyFactor - A multiplier applied to scores when the pattern match type is 'entity'.
|
* @param nlpPenaltyFactor - A multiplier applied to scores when the pattern match type is 'entity'.
|
||||||
* @returns A numeric score representing how well the block matches the given NLP context.
|
* @returns A numeric score representing how well the block matches the given NLP context.
|
||||||
*/
|
*/
|
||||||
async calculateBlockScore(
|
calculateBlockScore(
|
||||||
patterns: NlpPattern[],
|
patterns: NlpPattern[],
|
||||||
nlp: NLU.ParseEntities,
|
nlp: NLU.ParseEntities,
|
||||||
nlpCacheMap: NlpCacheMap,
|
nlpCacheMap: NlpCacheMap,
|
||||||
nlpPenaltyFactor: number,
|
nlpPenaltyFactor: number,
|
||||||
): Promise<number> {
|
): number {
|
||||||
// Compute individual pattern scores using the cache
|
// Compute individual pattern scores using the cache
|
||||||
const patternScores: number[] = patterns.map((pattern) => {
|
const patternScores: number[] = patterns.map((pattern) => {
|
||||||
const entityData = nlpCacheMap.get(pattern.entity);
|
const entityData = nlpCacheMap.get(pattern.entity);
|
||||||
|
Loading…
Reference in New Issue
Block a user