UNPKG

ngx-annotate-text

Version:

This Angular component library is perfect for tasks like visualizing named entity recognition, part of speech tagging, or annotating text datasets. It allows for interactively highlighting and annotating parts of text.

101 lines (94 loc) 5.36 kB
import * as i0 from '@angular/core'; import { OnInit, OnChanges, Type, EventEmitter, SimpleChanges } from '@angular/core'; interface ISelection { startIndex: number; endIndex: number; } interface IAnnotation { text: string | undefined; label: string; color: string; } declare class Annotation implements IAnnotation, ISelection { startIndex: number; endIndex: number; text: string | undefined; label: string; color: string; /** * Represents an annotated part of the referenced text. * * @param startIndex The zero-based index number indicating the beginning of this annotation. * @param endIndex The zero-based index number indicating the end of the annotation. The annotation * includes the characters up to, but not including, the character indicated by the end. * @param label Arbitrary string displayed as label below the annotation, e. g. `City`. * @param color The color of the box which is displayed around the annotation, e. g. 'red' or 'rgb(220, 53, 69)'. */ constructor(startIndex: number, endIndex: number, label: string, color: string); toString(): string; } interface NgxAnnotationRendererComponentInterface { annotation: Annotation; removable: boolean; clickAnnotation: (annotation: Annotation) => void; removeAnnotation: (annotation: Annotation) => void; } declare class NgxAnnotateTextComponent implements OnInit, OnChanges { private elementRef; private tokenService; /** Represents the parts of the given text which shall be annotated. */ annotations: Annotation[]; /** An optional CSS class applied to all elements which wrap the annotated parts of the given text. */ annotationClass?: string; /** * An optional Angular component that shall be used for rendering the annotation. By default, it uses the provided `NgxAnnotationRendererComponent`. * You can implement your own annotation rendering component to customize the visualization of annotations. The custom component must implement the * interface `NgxAnnotationRendererComponentInterface`. */ annotationRendererComponent: Type<NgxAnnotationRendererComponentInterface>; /** * Determines whether annotations shall have a small button in the top right corner so that the user can * remove an annotation. */ removable: boolean; /** The text which shall be displayed and annotated. */ text: string; /** Emits the list of existing annotations after an element has been removed. */ annotationsChange: EventEmitter<Annotation[]>; /** Emits the selected annotation when the user clicks on an annotation's box, the label or text. */ clickAnnotation: EventEmitter<Annotation>; /** Emits the selected annotation when the user removes it by clicking the annotation's X button in the upper right corner. */ removeAnnotation: EventEmitter<Annotation>; private selectionStart?; private selectionEnd?; ngOnInit(): void; ngOnChanges(changes: SimpleChanges): void; /** * Provides start and end index of the currently selected text. * * @returns Returns the start index and end index of the currently selected text range. Returns `undefined` * if no text is currently selected. */ getCurrentTextSelection(): ISelection | undefined; /** * Checks whether the given text selection is overlapping with existing annotations. * * @param selection The current text selection. * @returns Returns `true` if the given text selection is (partially) overlapping with * an existing annotation. Returns `false` otherwise. */ isOverlappingWithExistingAnnotations(selection: ISelection): boolean; private updateTextSelection; static ɵfac: i0.ɵɵFactoryDeclaration<NgxAnnotateTextComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<NgxAnnotateTextComponent, "ngx-annotate-text", never, { "annotations": { "alias": "annotations"; "required": false; }; "annotationClass": { "alias": "annotationClass"; "required": false; }; "annotationRendererComponent": { "alias": "annotationRendererComponent"; "required": false; }; "removable": { "alias": "removable"; "required": false; }; "text": { "alias": "text"; "required": false; }; }, { "annotationsChange": "annotationsChange"; "clickAnnotation": "clickAnnotation"; "removeAnnotation": "removeAnnotation"; }, never, never, true, never>; } declare class NgxAnnotationRendererComponent implements NgxAnnotationRendererComponentInterface { annotation: Annotation; removable: boolean; clickAnnotation: (annotation: Annotation) => void; removeAnnotation: (annotation: Annotation) => void; static ɵfac: i0.ɵɵFactoryDeclaration<NgxAnnotationRendererComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<NgxAnnotationRendererComponent, "ngx-annotation-renderer", never, { "annotation": { "alias": "annotation"; "required": true; }; "removable": { "alias": "removable"; "required": false; }; "clickAnnotation": { "alias": "clickAnnotation"; "required": false; }; "removeAnnotation": { "alias": "removeAnnotation"; "required": false; }; }, {}, never, never, true, never>; } export { Annotation, NgxAnnotateTextComponent, NgxAnnotationRendererComponent }; export type { IAnnotation, NgxAnnotationRendererComponentInterface };