Skip to content

Commit

Permalink
Fix/motivation entity (#131)
Browse files Browse the repository at this point in the history
* customize entityId for motivations

* clean

---------

Co-authored-by: Antoine Jeanneney <[email protected]>
  • Loading branch information
ajeanneney and Antoine Jeanneney authored Oct 2, 2024
1 parent bc0a6ce commit a989a10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/generic/backend/src/lib/annotator/buildAnnotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
settingsType,
treatmentModule,
annotationModule,
settingsModule,
} from '@label/core';
import { buildAnnotationReportRepository } from '../../modules/annotationReport';
import { documentService } from '../../modules/document';
Expand Down Expand Up @@ -253,7 +254,6 @@ function buildAnnotator(
documentId,
document.zoning.zones.motivations,
document.text,
document.documentNumber,
annotations,
);
} else {
Expand Down Expand Up @@ -424,11 +424,10 @@ function buildAnnotator(
documentId: documentType['_id'],
motivations: { start: number; end: number }[],
documentText: string,
documentNumber: number,
previousAnnotations: annotationType[],
) {
const motivationAnnotations: annotationType[] = [];
motivations.forEach((motivation, index) => {
motivations.forEach((motivation) => {
const motivationText = documentText.substring(
motivation.start,
motivation.end,
Expand All @@ -450,9 +449,8 @@ function buildAnnotator(
annotationModule.lib.buildAnnotation({
start: motivation.start + removedCharactersAtStart,
text: trimmedMotivation,
category: 'motivations',
category: settingsModule.lib.motivationCategoryHandler.getCategoryName(),
certaintyScore: 1,
entityId: `motivations${index}_${documentNumber}`,
}),
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { annotationType } from '../annotationType';
import { normalizeString } from '../../../lib/stringComparator/normalizeString';
import { motivationCategoryHandler } from '../../../modules/settings/lib';

export { entityIdHandler };

Expand All @@ -10,6 +11,9 @@ const entityIdHandler = {
};

function compute(category: string, text: string) {
if (category === motivationCategoryHandler.getCategoryName()) {
return `${category}_${text.length}`;
}
return `${category}_${normalizeString(text.toLocaleLowerCase())}`;
}

Expand Down

0 comments on commit a989a10

Please sign in to comment.