import {Entity} from "./Entity.interface"; import {ExampleEntityData} from "./example-entity-data"; export class SigParser implements Entity { private _signature = ''; private _segments: SigParserSegments = new SigParserSegments(); private _exampleEntityData: ExampleEntityData = new ExampleEntityData('sig-parser'); constructor(obj?: any) { 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: any = { text: this._exampleEntityData.getExampleData(), url: '', showInIframe: false }; const blocks = [ { blockName: '', blockDesc: '', numColumns: 4, fields: [ {label: 'not_a_signature', inputType: 'checkbox'}, {label: 'non_english_text', inputType: 'checkbox'}, {label: 'other', inputType: 'checkbox'}, {label: 'reason', inputType: 'text', depend: 'other', dependOnValue: 1} ] }, { blockName: 'name', blockDesc: '', numColumns: 4, fields: [ {label: 'prefix', inputType: 'text'}, {label: 'first', inputType: 'text'}, {label: 'middle', inputType: 'text'}, {label: 'last', inputType: 'text'}, {label: 'suffix', inputType: 'text'}, {label: 'credentials', inputType: 'text'}, {label: 'credentials_ids', inputType: 'text', description: 'this can be ignored'}, ] }, { blockName: 'title & company', blockDesc: '', numColumns: 4, fields: [ {label: 'title', inputType: 'text'}, {label: 'company', inputType: 'text'}, {label: 'company_ids', inputType: 'text'}, {label: 'copyrights', inputType: 'text'}, {label: 'department', inputType: 'text'}, {label: 'slogan', inputType: 'text'} ] }, { blockName: 'location', blockDesc: '', numColumns: 4, fields: [ {label: 'address', inputType: 'text'}, {label: 'city', inputType: 'text'}, {label: 'state', inputType: 'text'}, {label: 'zip', inputType: 'text'}, {label: 'department', inputType: 'text'}, {label: 'country', inputType: 'text'} ] }, { blockName: 'connections', blockDesc: '', numColumns: 4, fields: [ {label: 'phones', inputType: 'text_list'}, {label: 'faxes', inputType: 'text_list'}, {label: 'emails', inputType: 'text_list'}, {label: 'urls', inputType: 'text_list'}, {label: 'filtered_urls', inputType: 'text_list'}, {label: 'twitter', inputType: 'text_list'}, {label: 'skype', inputType: 'text_list'} ] } ]; const final = []; for (const i in blocks) { final.push(blocks[i]); } return {blocks: final, data: data}; } public fromDsProjectRoom(obj: any[], data: any) { const sig: any = { signature: data.text, segments: {} }; let block: any; for (block of obj) { if (block.blockName === 'title & company') { block.blockName = 'tc'; } sig.segments[block.blockName] = {}; let field: any; for (field of block.fields) { sig.segments[block.blockName][field.label] = field.value; } } return new SigParser(sig); } nerEntityTypeOptions(): any[] { return []; } toShortInputOutput() {} } export class SigParserSegments { 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?: any) { 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 []; } }