Skip to content

Commit

Permalink
[sc-11384] Display labels of the text blocks in the preview page (#1916)
Browse files Browse the repository at this point in the history
* [sc-11384] Display labels of the text blocks in the preview page

* Allow to filter paragraphs by label

* Fix translation

* Fix tests

* Fix

* Fix build
  • Loading branch information
operramon authored Jan 17, 2025
1 parent 5692f08 commit 787b792
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 197 deletions.
69 changes: 69 additions & 0 deletions libs/common/common.babel
Original file line number Diff line number Diff line change
Expand Up @@ -23068,6 +23068,29 @@
<folder_node>
<name>preview</name>
<children>
<concept_node>
<name>answers</name>
<description/>
<comment/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-FR</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>content</name>
<description/>
Expand Down Expand Up @@ -23114,6 +23137,29 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>labels</name>
<description/>
<comment/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-FR</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>open-viewer</name>
<description/>
Expand Down Expand Up @@ -23160,6 +23206,29 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>question</name>
<description/>
<comment/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-FR</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>questions-answers</name>
<description/>
Expand Down
3 changes: 3 additions & 0 deletions libs/common/src/assets/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,13 @@
"resource.pagination.downloading": "S’està baixant...",
"resource.pagination.filtered": "{{num}} recursos amagats per filtres",
"resource.pagination.rows-per-page": "Files per pàgina",
"resource.preview.answers": "Respostes",
"resource.preview.content": "Contingut del camp",
"resource.preview.general": "General",
"resource.preview.labels": "Etiquetes",
"resource.preview.open-viewer": "Visor obert",
"resource.preview.origin": "Origen",
"resource.preview.question": "Pregunta",
"resource.preview.questions-answers": "Preguntes i respostes",
"resource.processed": "Processat",
"resource.processing": "Processant",
Expand Down
3 changes: 3 additions & 0 deletions libs/common/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,13 @@
"resource.pagination.downloading": "Downloading…",
"resource.pagination.filtered": "{{num}} resources hidden by filters",
"resource.pagination.rows-per-page": "Rows per page",
"resource.preview.answers": "Answers",
"resource.preview.content": "Field content",
"resource.preview.general": "General",
"resource.preview.labels": "Labels",
"resource.preview.open-viewer": "Open viewer",
"resource.preview.origin": "Origin",
"resource.preview.question": "Question",
"resource.preview.questions-answers": "Questions & Answers",
"resource.processed": "Processed",
"resource.processing": "Processing",
Expand Down
3 changes: 3 additions & 0 deletions libs/common/src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,13 @@
"resource.pagination.downloading": "Descargando...",
"resource.pagination.filtered": "{{num}} recursos ocultos por filtros",
"resource.pagination.rows-per-page": "Filas por página",
"resource.preview.answers": "Respuestas",
"resource.preview.content": "Contenido del campo",
"resource.preview.general": "General",
"resource.preview.labels": "Etiquetas",
"resource.preview.open-viewer": "Visor abierto",
"resource.preview.origin": "Origen",
"resource.preview.question": "Pregunta",
"resource.preview.questions-answers": "Preguntas y respuestas",
"resource.processed": "Procesado",
"resource.processing": "Procesando",
Expand Down
3 changes: 3 additions & 0 deletions libs/common/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,13 @@
"resource.pagination.downloading": "Téléchargement...",
"resource.pagination.filtered": "{{num}}  ressources masquées par les filtres",
"resource.pagination.rows-per-page": "Lignes par page",
"resource.preview.answers": "Réponses",
"resource.preview.content": "Contenu du champ",
"resource.preview.general": "Général",
"resource.preview.labels": "Étiquettes",
"resource.preview.open-viewer": "Ouvrir la visionneuse",
"resource.preview.origin": "Origine",
"resource.preview.question": "Question",
"resource.preview.questions-answers": "Questions et réponses",
"resource.processed": "Traité",
"resource.processing": "Traitement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class ParagraphAnnotationComponent extends SelectFirstFieldDirective impl

combineLatest([this.fieldId, this.resource, this.entityFamilies])
.pipe(takeUntil(this.unsubscribeAll))
.subscribe(([fieldId, resource, families]) => this.annotationService.initParagraphs(fieldId, resource, families));
.subscribe(([fieldId, resource, families]) =>
this.annotationService.initParagraphsWithAnnotations(fieldId, resource, families),
);
}

override ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ParagraphAnnotationService extends ParagraphService {
super();
}

initParagraphs(fieldId: FieldId, resource: Resource, families: EntityGroup[]) {
initParagraphsWithAnnotations(fieldId: FieldId, resource: Resource, families: EntityGroup[]) {
const paragraphs: ParagraphWithTextAndAnnotations[] = this.getEnhancedParagraphs(fieldId, resource, families);
this.setupParagraphs(paragraphs);
}
Expand Down Expand Up @@ -72,11 +72,7 @@ export class ParagraphAnnotationService extends ParagraphService {
const highlightedAnnotations = getHighlightedAnnotations(paragraph.annotations);
return {
...paragraph,
annotatedText: getAnnotatedText(
paragraph.text,
highlightedAnnotations,
this.selectedFamilyValue,
),
annotatedText: getAnnotatedText(paragraph.text, highlightedAnnotations, this.selectedFamilyValue),
};
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './paragraph-classification.component';
export * from './paragraph-classification.service';
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { combineLatest, filter, forkJoin, map, Observable, Subject, switchMap, t
import { FieldId, LabelSets, Resource, Search } from '@nuclia/core';
import { LabelsService } from '@flaps/core';
import { ParagraphWithTextAndClassifications } from '../../edit-resource.helpers';
import { ParagraphClassificationService } from './paragraph-classification.service';
import { takeUntil } from 'rxjs/operators';
import { ParagraphService } from '../../paragraph.service';

@Component({
templateUrl: './paragraph-classification.component.html',
Expand All @@ -32,9 +32,9 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {

availableLabels: Observable<LabelSets | null> = this.labelsService.textBlockLabelSets;

paragraphs: Observable<ParagraphWithTextAndClassifications[]> = this.classificationService.paragraphs;
hasParagraph: Observable<boolean> = this.classificationService.hasParagraph;
paragraphLoaded: Observable<boolean> = this.classificationService.paragraphLoaded;
paragraphs = this.paragraphService.paragraphList as Observable<ParagraphWithTextAndClassifications[]>;
hasParagraph: Observable<boolean> = this.paragraphService.hasParagraph;
paragraphLoaded: Observable<boolean> = this.paragraphService.paragraphLoaded;

previousQuery?: string;
searchQuery = '';
Expand All @@ -45,7 +45,7 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {
constructor(
private route: ActivatedRoute,
private editResource: EditResourceService,
private classificationService: ParagraphClassificationService,
private paragraphService: ParagraphService,
private labelsService: LabelsService,
private cdr: ChangeDetectorRef,
) {}
Expand All @@ -55,13 +55,13 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {

combineLatest([this.fieldId, this.resource])
.pipe(takeUntil(this.unsubscribeAll))
.subscribe(([fieldId, resource]) => this.classificationService.initParagraphs(fieldId, resource));
.subscribe(([fieldId, resource]) => this.paragraphService.initParagraphs(fieldId, resource));
}

ngOnDestroy() {
this.unsubscribeAll.next();
this.unsubscribeAll.complete();
this.classificationService.cleanup();
this.paragraphService.cleanup();
}

triggerSearch() {
Expand All @@ -71,7 +71,7 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {
this.extendedResults = false;
}
this._triggerSearch(this.searchQuery).subscribe((results) => {
this.classificationService.setSearchResults(results);
this.paragraphService.setSearchResults(results);
this.updatePagination(results);
});
}
Expand All @@ -83,7 +83,7 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {
$event.stopPropagation();
$event.preventDefault();
this.searchQuery = '';
this.classificationService.setSearchResults(null);
this.paragraphService.setSearchResults(null);
this.hasMoreResults = false;
this.extendedResults = false;
this.cdr.markForCheck();
Expand All @@ -93,7 +93,7 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {
loadMore() {
if (this.hasMoreResults && !this.extendedResults && this.searchQuery) {
this._triggerSearch(this.searchQuery, true).subscribe((results) => {
this.classificationService.setSearchResults(results);
this.paragraphService.setSearchResults(results);
this.updatePagination(results);
this.extendedResults = true;
});
Expand All @@ -109,7 +109,7 @@ export class ParagraphClassificationComponent implements OnInit, OnDestroy {
private _triggerSearch(query: string, extendedResults = false) {
return forkJoin([this.fieldId.pipe(take(1)), this.resource.pipe(take(1))]).pipe(
switchMap(([field, resource]) =>
this.classificationService.searchInField(query, resource, field, extendedResults),
this.paragraphService.searchInField(query, resource, field, extendedResults),
),
);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Edit resource helpers', () => {
paragraphId: 'p1',
userClassifications: [{ labelset: 'heroes', label: 'batman' }],
generatedClassifications: [],
activeClassifications: [],
text: '',
},
],
Expand All @@ -36,18 +37,21 @@ describe('Edit resource helpers', () => {
{ labelset: 'heroes', label: 'catwoman' },
],
generatedClassifications: [],
activeClassifications: [],
text: '',
},
{
paragraphId: 'p2',
userClassifications: [{ labelset: 'heroes', label: 'catwoman' }],
generatedClassifications: [],
activeClassifications: [],
text: '',
},
{
paragraphId: 'p3',
userClassifications: [],
generatedClassifications: [],
activeClassifications: [],
text: '',
},
],
Expand Down
Loading

0 comments on commit 787b792

Please sign in to comment.