Skip to content

Commit

Permalink
Feat/new checklist (#133)
Browse files Browse the repository at this point in the history
* create new annotationReport type

* handle only new annotationReport

* save checklist only if not empty

* extract checklist rendering

* add viewer mode for checklist

* put chekclist in accordion

* make check clickable

* show lines of concerned selected check

* diplay context lines for checklist

* styling

* add checklist header

* eslint

* simplify annotationReportType

* fix test

* change 'label' to 'category' in nlp response

* update storage-example

* review changes

---------

Co-authored-by: Antoine Jeanneney <antoine.jeanneney@justice.fr>
  • Loading branch information
ajeanneney and Antoine Jeanneney authored Oct 22, 2024
1 parent a328728 commit dd89211
Show file tree
Hide file tree
Showing 29 changed files with 679 additions and 160 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { labelTreatmentsType } from 'sder';
import { documentType, settingsType } from '@label/core';
import { annotationReportType, documentType, settingsType } from '@label/core';

export type { nlpApiType, nlpResponseType, nlpLossType, nlpVersion };

Expand Down Expand Up @@ -29,7 +29,7 @@ type nlpVersion = {

type nlpResponseType = {
entities: nlpAnnotationType[];
checklist: string[];
checklist?: annotationReportType['checklist'];
newCategoriesToAnnotate?: string[];
newCategoriesToUnAnnotate?: string[];
additionalTermsToAnnotate?: string[];
Expand All @@ -42,7 +42,7 @@ type nlpAnnotationType = {
text: string;
start: number;
end: number;
label: string;
category: string;
source: string;
score: number;
entityId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function buildNlpLocalApi(): nlpApiType {
return {
...annotations,
entities: annotations.entities.filter((entity) =>
availableCategories.includes(entity.label),
availableCategories.includes(entity.category),
),
checklist: annotations.checklist,
newCategoriesToAnnotate: annotations.newCategoriesToAnnotate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const nlpAnnotations: nlpResponseType = {
text: 'ANNOTATION1',
start: 0,
end: 11,
label: 'LABEL1',
category: 'LABEL1',
source: 'NLP',
score: 0.5,
entityId: 'LABEL1_annotation1',
Expand All @@ -35,13 +35,13 @@ const nlpAnnotations: nlpResponseType = {
text: 'ANNOTATION2',
start: 12,
end: 23,
label: 'LABEL2',
category: 'LABEL2',
source: 'NLP',
score: 0.6,
entityId: 'LABEL2_annotation2',
},
],
checklist: ['CHECK 1', 'CHECK 2'],
checklist: [],
versions: nlpVersion,
};

Expand All @@ -51,7 +51,7 @@ const nlpAnnotationsWithAdditionalTerms: nlpResponseType = {
text: 'ANNOTATION1',
start: 0,
end: 11,
label: 'LABEL1',
category: 'LABEL1',
source: 'NLP',
score: 0.5,
entityId: 'LABEL1_annotation1',
Expand All @@ -60,13 +60,80 @@ const nlpAnnotationsWithAdditionalTerms: nlpResponseType = {
text: 'ANNOTATION2',
start: 12,
end: 23,
label: 'LABEL2',
category: 'LABEL2',
source: 'NLP',
score: 0.6,
entityId: 'LABEL2_annotation2',
},
],
checklist: ['CHECK 1', 'CHECK 2'],
checklist: [],
additionalTermsToUnAnnotate: ['blabla', 'toto'],
versions: nlpVersion,
};

const nlpAnnotationsWithChecklist: nlpResponseType = {
entities: [
{
text: 'ANNOTATION1',
start: 0,
end: 11,
category: 'LABEL1',
source: 'NLP',
score: 0.5,
entityId: 'LABEL1_annotation1',
},
],
checklist: [
{
checkType: 'missing_something',
message: "Label est-il un bon logiciel d'annotation ?",
entities: [
{
text: 'Label',
start: 0,
end: 5,
category: 'myCategory',
source: 'source1',
score: 0.85,
entityId: 'myCategory',
},
{
text: 'Application',
start: 10,
end: 15,
category: 'myCategory',
source: 'source2',
score: 0.9,
entityId: 'myCategory_application',
},
],
sentences: [
{
start: 0,
end: 50,
},
],
metadata_text: ['Label', 'Applcation'],
},
{
checkType: 'other',
message:
"L'annotation [Antoine] est présente dans les catégories [développeur, data scientist] est-ce une erreur ?",
entities: [
{
text: 'Antoine',
start: 20,
end: 25,
category: 'developpeur',
source: 'nlp',
score: 1,
entityId: 'developpeur_antoine',
},
],
sentences: undefined,
metadata_text: undefined,
},
],
additionalTermsToUnAnnotate: ['blabla', 'toto'],
versions: nlpVersion,
};
Expand Down Expand Up @@ -102,12 +169,62 @@ describe('nlpMapper', () => {
describe('mapNlpAnnotationstoReport', () => {
it('should convert the nlp annotations into an annotation report', () => {
const annotationReport = nlpMapper.mapNlpAnnotationstoReport(
nlpAnnotations,
nlpAnnotationsWithChecklist,
document,
);

expect(annotationReport).toEqual({
checklist: ['CHECK 1', 'CHECK 2'],
checklist: [
{
checkType: 'missing_something',
message: "Label est-il un bon logiciel d'annotation ?",
entities: [
{
text: 'Label',
start: 0,
end: 5,
category: 'myCategory',
source: 'source1',
score: 0.85,
entityId: 'myCategory',
},
{
text: 'Application',
start: 10,
end: 15,
category: 'myCategory',
source: 'source2',
score: 0.9,
entityId: 'myCategory_application',
},
],
sentences: [
{
start: 0,
end: 50,
},
],
metadata_text: ['Label', 'Applcation'],
},
{
checkType: 'other',
message:
"L'annotation [Antoine] est présente dans les catégories [développeur, data scientist] est-ce une erreur ?",
entities: [
{
text: 'Antoine',
start: 20,
end: 25,
category: 'developpeur',
source: 'nlp',
score: 1,
entityId: 'developpeur_antoine',
},
],
sentences: undefined,
metadata_text: undefined,
},
],
documentId: document._id,
_id: annotationReport._id,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function mapNlpAnnotationsToAnnotations(
): annotationType[] {
return nlpAnnotations.entities.map((nlpAnnotation) =>
annotationModule.lib.buildAnnotation({
category: nlpAnnotation.label,
category: nlpAnnotation.category,
entityId: nlpAnnotation.entityId,
start: nlpAnnotation.start,
certaintyScore: nlpAnnotation.score,
Expand All @@ -35,7 +35,7 @@ function mapNlpAnnotationstoReport(
document: documentType,
): annotationReportType {
return annotationReportModule.lib.buildAnnotationReport({
checklist: nlpAnnotations.checklist,
checklist: nlpAnnotations.checklist ?? [],
documentId: document._id,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('nlpFetcher', () => {
annotations.some(
(annotation) =>
annotation.start === nlpAnnotation.start &&
annotation.category === nlpAnnotation.label,
annotation.category === nlpAnnotation.category,
),
).toEqual(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function generateRandomNlpAnnotation() {
start: start,
end: start + random(8),
score: Math.random(),
label: `LABEL`,
category: `LABEL`,
source: `NLP`,
entityId: `LABEL_${text.toLowerCase()}`,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"entities": [],
"check_needed": false,
"checklist": []
}
Loading

0 comments on commit dd89211

Please sign in to comment.