import {Entity} from './entity'; import {DsProjectRoomBlock, DsProjectRoomBlockField, DsProjectRoomData} from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class SigParser implements Entity { private _signature = ''; private _segments: SigParserSegments = new SigParserSegments(); constructor(obj?) { if (obj) { if (obj.signature) { this._signature = obj.signature; } if (obj.segments) { this._segments = new SigParserSegments(obj.segments); } } } get signature(): string { return this._signature; } set signature(value: string) { this._signature = value; } get segments(): SigParserSegments { return this._segments; } set segments(value: SigParserSegments) { this._segments = value; } public toJSON() { return { signature: this.signature, segments: this.segments.toJSON() }; } public toNerEntities(): any { } public toDsProjectRoom() { const data: DsProjectRoomData = new DsProjectRoomData({ text: this._signature, url: '', showInIframe: false }); const blocks = [ { blockName: '', blockDesc: '', numColumns: 4, fields: [ { label: 'not_a_signature', inputType: 'checkbox', value: this._segments?.not_a_signature }, { label: 'non_english_text', inputType: 'checkbox', value: this._segments?.non_english_text }, { label: 'other', inputType: 'checkbox', value: this._segments?.other }, { label: 'reason', inputType: 'text', depend: 'other', dependOnValue: 1, value: this._segments?.reason } ] }, { blockName: 'name', blockDesc: '', numColumns: 4, fields: [ { label: 'prefix', inputType: 'text', value: this._segments.name?.prefix }, { label: 'first', inputType: 'text', value: this._segments.name?.first }, { label: 'middle', inputType: 'text', value: this._segments.name?.middle }, { label: 'last', inputType: 'text', value: this._segments.name?.last }, { label: 'suffix', inputType: 'text', value: this._segments.name?.suffix }, { label: 'credentials', inputType: 'text', value: this._segments.name?.credentials }, { label: 'credentials_ids', inputType: 'text', description: 'this can be ignored', value: this._segments.name?.credentials_ids }, ] }, { blockName: 'title & company', blockDesc: '', numColumns: 4, fields: [ { label: 'title', inputType: 'text', value: this._segments.tc?.title }, { label: 'company', inputType: 'text', value: this._segments.tc?.company }, { label: 'company_ids', inputType: 'text', value: this._segments.tc?.company_ids }, { label: 'copyrights', inputType: 'text', value: this._segments.tc?.copyrights }, { label: 'department', inputType: 'text', value: this._segments.tc?.department }, { label: 'slogan', inputType: 'text', value: this._segments.tc?.slogan } ] }, { blockName: 'location', blockDesc: '', numColumns: 4, fields: [ { label: 'address', inputType: 'text', value: this._segments.location?.address }, { label: 'city', inputType: 'text', value: this._segments.location?.city }, { label: 'state', inputType: 'text', value: this._segments.location?.state }, { label: 'zip', inputType: 'text', value: this._segments.location?.zip }, { label: 'country', inputType: 'text', value: this._segments.location?.country } ] }, { blockName: 'connections', blockDesc: '', numColumns: 4, fields: [ { label: 'phones', inputType: 'text_list', value: this._segments.connections?.phones }, { label: 'faxes', inputType: 'text_list', value: this._segments.connections?.faxes }, { label: 'emails', inputType: 'text_list', value: this._segments.connections?.emails }, { label: 'urls', inputType: 'text_list', value: this._segments.connections?.urls }, { label: 'filtered_urls', inputType: 'text_list', value: this._segments.connections?.filtered_urls }, { label: 'twitter', inputType: 'text_list', value: this._segments.connections?.twitter }, { label: 'skype', inputType: 'text_list', value: this._segments.connections?.skype } ] } ]; const final = []; for (const i in blocks) { final.push(new DsProjectRoomBlock(blocks[i])); } console.log('final-sigparser', final); return {blocks: [final], data: data}; } public fromDsProjectRoom(obj: DsProjectRoomBlock[], data: DsProjectRoomData) { const sig = { signature: data.text, segments: {} }; let block: DsProjectRoomBlock; if (obj && obj.length) { for (block of obj) { if (block.blockName === '') { let field: DsProjectRoomBlockField; for (field of block.fields) { sig.segments[field.label] = field.value; } } else if (block.blockName === 'title & company') { sig.segments['tc'] = {}; let field: DsProjectRoomBlockField; for (field of block.fields) { sig.segments['tc'][field.label] = field.value; } } else { sig.segments[block.blockName] = {}; let field: DsProjectRoomBlockField; for (field of block.fields) { sig.segments[block.blockName][field.label] = field.value; } } } } return new SigParser(sig); } nerEntityTypeOptions(): any[] { return []; } } export class SigParserSegments implements Entity { private _not_a_signature = 0; private _non_english_text = 0; private _other = 0; private _reason = ''; private _name: any = { prefix: '', first: '', middle: '', last: '', suffix: '', credentials: '', credentials_ids: '', }; private _tc: any = { title: '', company: '', company_ids: '', copyrights: '', department: '', slogan: '' }; private _location: any = { address: '', city: '', state: '', zip: '', country: '' }; private _connections: any = { phones: [], mobiles: [], faxes: [], emails: [], urls: [], filtered_urls: [], twitter: [], skype: [] }; constructor(obj?) { let key; if (obj) { if (obj.not_a_signature) { this._not_a_signature = obj.not_a_signature; } if (obj.non_english_text) { this._non_english_text = obj.non_english_text; } if (obj.other) { this._other = obj.other; } if (obj.reason) { this._reason = obj.reason; } if (obj.name) { for (key in this._name) { if (obj.name[key]) { this._name[key] = obj.name[key]; } } } if (obj.tc) { for (key in this._tc) { if (obj.tc[key]) { this._tc[key] = obj.tc[key]; } } } if (obj.location) { for (key in this._location) { if (obj.location[key]) { this._location[key] = obj.location[key]; } } } if (obj.connections) { for (key in this._connections) { if (obj.connections[key]) { if (Array.isArray(obj.connections[key])) { for (const i in obj.connections[key]) { if (typeof obj.connections[key][i] === 'string') { this._connections[key].push(obj.connections[key][i]); } } } else { this._connections[key].push(obj.connections[key]); } } } } } } get not_a_signature(): number { return this._not_a_signature; } set not_a_signature(value: number) { this._not_a_signature = value; } get non_english_text(): number { return this._non_english_text; } set non_english_text(value: number) { this._non_english_text = value; } get name(): any { return this._name; } set name(value: any) { this._name = value; } get tc(): any { return this._tc; } set tc(value: any) { this._tc = value; } get location(): any { return this._location; } set location(value: any) { this._location = value; } get connections(): any { return this._connections; } set connections(value: any) { this._connections = value; } get other(): number { return this._other; } set other(value: number) { this._other = value; } get reason(): string { return this._reason; } set reason(value: string) { this._reason = value; } public toJSON() { return { not_a_signature: this.not_a_signature, non_english_text: this.non_english_text, other: this.other, reason: this.reason, name: this.name, tc: this.tc, location: this.location, connections: this.connections, }; } public toNerEntities(type = 1) { return { relationOptions: [], entities: { name: this.name, tc: this.tc, location: this.location, connections: this.connections, } }; } nerEntityTypeOptions(): any[] { return []; } }