import {Entity} from "./entity"; import { DsProjectRoomBlock, DsProjectRoomBlockField, DsProjectRoomData, DsProjectRooomListBlocks } from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class SigExtractor implements Entity { private _email = ''; private _threads: SigExtractorTread[] = []; private _exampleEntityData: ExampleEntityData = new ExampleEntityData('sig-extractor'); constructor(obj?) { if (obj) { if (obj.email) { this._email = obj.email; } if (obj.threads) { for (const i in obj.threads) { this._threads.push(new SigExtractorTread(obj.threads[i])); } } } } get email(): string { return this._email; } set email(value: string) { this._email = value; } get threads(): SigExtractorTread[] { return this._threads; } set threads(value: SigExtractorTread[]) { this._threads = value; } public toJSON() { return { email: this.email, threads: this.threads.map((o) => o.toJSON()), }; } public toNerEntities(type = 1) { return { relationOptions: [], entities: { header: '', signature: '', meeting: '' } }; } nerEntityTypeOptions(): any[] { return []; } public toDsProjectRoom() { const roomSettings: DsProjectRoomData = new DsProjectRoomData({ text: this.email, url: '', showInIframe: false, isList: true, listHeader: 'Threads', listItemDefaultHeader: 'Thread', listBlockIndex: 0, listBlockFieldFirstIndex: 0 }); if (!this.threads.length) { // this.threads.push(new SigExtractorTread()); } const finalBlocksList: any = []; for (const i in this.threads) { const blocks = [ { blockName: 'header', blockDesc: '', numColumns: 3, fields: [ { label: 'sender_name', inputType: 'text', value: this.threads[i]?.header.sender.name }, { label: 'sender_email', inputType: 'text', value: this.threads[i]?.header.sender.email }, { label: 'date', inputType: 'text', value: this.threads[i]?.header.date }, { label: 'to', inputType: 'text_list', // value: this.threads[i]?.header.to, listBlocks: [ {label: 'name', required: true, inputType: 'text'}, {label: 'email', required: true, inputType: 'text'} ], // value: [ // [ // { // label: 'name', // value: 'a' // }, // { // label: 'email', // value: 'email-a' // } // ], // [ // { // label: 'name', // value: 'a1' // }, // { // label: 'email', // value: 'email-a1' // } // ] // ], fullLine: true }, ] }, { blockName: '', blockDesc: '', numColumns: 2, fields: [ {label: 'signatures', inputType: 'text_list'} ] } ]; const tempBlocks = []; for (const j in blocks) { tempBlocks.push(new DsProjectRoomBlock(blocks[j])); } finalBlocksList.push(tempBlocks); } return {blocks: finalBlocksList, data: roomSettings}; } public fromDsProjectRoom(obj: DsProjectRoomBlock[], data: DsProjectRoomData) { const sigExtractor = { email: data.text, threads: [] }; let block: DsProjectRoomBlock; let item: any; if (obj && obj.length) { for (item of obj) { const sigExtractorThread = new SigExtractorTread().toJSON(); let field: DsProjectRoomBlockField; for (block of item) { for (field of block.fields) { let label = field.label; if (block.blockName) { if (label === 'to') { const to = field.value.map((o) => ({name: o[0].value, email: o[1].value})); sigExtractorThread[block.blockName][label] = to; } else if (label.indexOf('sender') > -1) { label = label.split('_')[1]; sigExtractorThread[block.blockName]['sender'][label] = field.value; } } else { sigExtractorThread[label] = field.value; } } } sigExtractor.threads.push(sigExtractorThread); } } return new SigExtractor(sigExtractor); } } export class SigExtractorTread { private _header: SigExtractorHeader = new SigExtractorHeader(); private _signatures: string[] = []; private _hints: SigExtractorHint[] = []; constructor(obj?) { if (obj) { if (obj.header) { this._header = new SigExtractorHeader(obj.header); } if (obj.signatures) { for (const i in obj.signatures) { this._signatures.push(obj.signatures[i]); } } if (obj.hints) { for (const i in obj.hints) { this._hints.push(new SigExtractorHint(obj.hints[i])); } } } } get header(): SigExtractorHeader { return this._header; } set header(value: SigExtractorHeader) { this._header = value; } get signatures(): string[] { return this._signatures; } set signatures(value: string[]) { this._signatures = value; } get hints(): SigExtractorHint[] { return this._hints; } set hints(value: SigExtractorHint[]) { this._hints = value; } public toJSON() { return { header: this.header.toJSON(), signatures: this.signatures, hints: this.hints.map((o) => o.toJSON()), }; } } export class SigExtractorHeader { private _dummy: boolean = false; private _sender: SigExtractorSender = new SigExtractorSender(); private _to: SigExtractorSender[] = []; private _date: string = ''; constructor(obj?) { if (obj) { if (typeof (obj.dummy) === 'boolean') { this._dummy = obj.dummy; } if (obj.sender) { this._sender = new SigExtractorSender(obj.sender); } if (obj.to) { for (const i in obj.to) { this._to.push(new SigExtractorSender(obj.to[i])); } } if (obj.date) { this._date = obj.date; } } } get dummy(): boolean { return this._dummy; } set dummy(value: boolean) { this._dummy = value; } get sender(): SigExtractorSender { return this._sender; } set sender(value: SigExtractorSender) { this._sender = value; } get to(): SigExtractorSender[] { return this._to; } set to(value: SigExtractorSender[]) { this._to = value; } get date(): string { return this._date; } set date(value: string) { this._date = value; } public toJSON() { return { dummy: this.dummy, sender: this.sender.toJSON(), to: this.to.map((o) => o.toJSON()), date: this.date }; } } export class SigExtractorSender { private _name: string = ''; private _email: string = ''; constructor(obj?) { if (obj) { if (obj.name) { this._name = obj.name; } if (obj.email) { this._email = obj.email; } } } get name(): string { return this._name; } set name(value: string) { this._name = value; } get email(): string { return this._email; } set email(value: string) { this._email = value; } public toJSON() { return { name: this.name, email: this.email, }; } } export class SigExtractorHint { private _firstName: string = ''; private _lastName: string = ''; private _email: string = ''; private _prob: number = 0; constructor(obj?) { if (obj) { if (obj.first_name) { this._firstName = obj.first_name; } if (obj.last_name) { this._lastName = obj.last_name; } if (obj.email) { this._email = obj.email; } if (obj.prob) { this._prob = obj.prob; } } } get firstName(): string { return this._firstName; } set firstName(value: string) { this._firstName = value; } get lastName(): string { return this._lastName; } set lastName(value: string) { this._lastName = value; } get email(): string { return this._email; } set email(value: string) { this._email = value; } get prob(): number { return this._prob; } set prob(value: number) { this._prob = value; } public toJSON() { return { firstName: this.firstName, lastName: this.lastName, email: this.email, prob: this.prob, }; } }