import {Entity} from "./entity"; import {DsProjectRoomBlock, DsProjectRoomBlockField, DsProjectRoomData} from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class Scoops implements Entity { private _pred: number = -1; private _prob: number = -1; private _source: string = ''; private _title: string = ''; private _text: string = ''; private _queue_name: string = ''; private _internal_notes: string = ''; private _exampleEntityData: ExampleEntityData = new ExampleEntityData('scoops'); constructor(obj?) { if (obj) { if ( (typeof (obj?.pred) === 'number') && ((obj?.pred) === 1 || (obj?.pred) === 0 || (obj?.pred) === -1 ) ) { this._pred = obj.pred; } if ( typeof (obj?.prob) === 'number' ) { this._prob = obj.prob; } if (obj.source) { this._source = obj.source; } if (obj.title) { this._title = obj.title; } if (obj.text) { this._text = obj.text; } // text is also called html_content if (obj.html_content) { this._text = obj.html_content; } if (obj.queue_name) { this._queue_name = obj.queue_name; } if (obj.internal_notes) { this._internal_notes = obj.internal_notes; } } } nerEntityTypeOptions(): any[] { return []; } get pred(): number { return this._pred; } set pred(value: number) { this._pred = value; } get prob(): number { return this._prob; } set prob(value: number) { this._prob = value; } get source(): string { return this._source; } set source(value: string) { this._source = value; } get title(): string { return this._title; } set title(value: string) { this._title = value; } get text(): string { return this._text; } set text(value: string) { this._text = value; } get queue_name(): string { return this._queue_name; } set queue_name(value: string) { this._queue_name = value; } get internal_notes(): string { return this._internal_notes; } set internal_notes(value: string) { this._internal_notes = value; } public toJSON() { return { pred: this.pred, prob: this.prob, source: this.source, title: this.title, text: this.text, queue_name: this.queue_name, internal_notes: this.internal_notes }; } public toNerEntities(type = 1) { return { relationOptions: [], entities: { pred: this.pred, title: this.title, text: this.text, } }; } public toDsProjectRoom() { const data: DsProjectRoomData = new DsProjectRoomData({ text: '', url: this._exampleEntityData.getExampleData(), showInIframe: true }); const blocks = [ { blockName: 'scoop', blockDesc: '', numColumns: 1, fields: [ {label: 'pred', inputType: 'select', selectOptions: ['Not a scoop!', 'Scoop!', 'Unknown!']}, ] }]; const final = []; for (const i in blocks) { final.push(new DsProjectRoomBlock(blocks[i])); } return {blocks: final, data: data}; } public fromDsProjectRoom(obj: DsProjectRoomBlock[], data: DsProjectRoomData) { const scoop = { source: data.url, pred: 0 }; let block: DsProjectRoomBlock; for (block of obj) { if (block.fields[0].value === 'Not a scoop!') { scoop.pred = -1; } else if (block.fields[0].value === 'Scoop!') { scoop.pred = 0; } else { scoop.pred = 1; } } return new Scoops(scoop); } }