import {Entity} from './entity'; import {DsProjectRoomBlock, DsProjectRoomData} from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class CompanyMatcher implements Entity { private _names: string[] = []; private _domains: string[] = []; private _addresses: Address[] = []; private _phones: string[] = []; private _maximum_matches: number = -1; private _match_threshold: number = -1; private _records: CompanyMatcherRecord[] = []; private _exampleEntityData: ExampleEntityData = new ExampleEntityData('company-matcher'); constructor(obj?) { if (obj) { if (obj.names) { for (const i in obj.names) { this._names.push(obj.names[i]); } } if (obj.domains) { for (const i in obj.domains) { this._domains.push(obj.domains[i]); } } if (obj.addresses) { for (const i in obj.addresses) { this._addresses.push(new Address(obj.addresses[i])); } } if (obj.phones) { for (const i in obj.phones) { this._phones.push(obj.phones[i]); } } if (obj.maximum_matches) { this._maximum_matches = obj.maximum_matches; } if (obj.match_threshold) { this._match_threshold = obj.match_threshold; } if (obj.records) { for (const i in obj.records) { this._records.push(obj.records[i]); } } } } get names(): string[] { return this._names; } set names(value: string[]) { this._names = value; } get domains(): string[] { return this._domains; } set domains(value: string[]) { this._domains = value; } get addresses(): Address[] { return this._addresses; } set addresses(value: Address[]) { this._addresses = value; } get phones(): string[] { return this._phones; } set phones(value: string[]) { this._phones = value; } get maximum_matches(): number { return this._maximum_matches; } set maximum_matches(value: number) { this._maximum_matches = value; } get match_threshold(): number { return this._match_threshold; } set match_threshold(value: number) { this._match_threshold = value; } get records(): CompanyMatcherRecord[] { return this._records; } set records(value: CompanyMatcherRecord[]) { this._records = value; } public toJSON() { return { names: this._names, domains: this._domains, addresses: this.addresses.map((o) => new Address(o).toJSON()), phones: this._phones, maximum_matches: this._maximum_matches, match_threshold: this._match_threshold, records: this.records.map((o) => new CompanyMatcherRecord(o).toJSON()), }; } public toNerEntities(type = 1) { return { relationOptions: [], entities: { } } } nerEntityTypeOptions(): any[] { return []; } public toDsProjectRoom() { const data: DsProjectRoomData = new DsProjectRoomData({ text: this._exampleEntityData.getExampleData(), url: '', showInIframe: false, }); const blocks = [ { blockName: 'Company Matcher', blockDesc: '', numColumns: 4, fields: [ {label: 'company_name', inputType: 'text'}, ] }, { blockName: 'Companu', blockDesc: '', numColumns: 4, fields: [ {label: 'company_id', inputType: 'text_list'}, ] } ]; 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 companyMatcher = { text: data.text, records: [] }; let block: DsProjectRoomBlock; for (block of obj) { for (const field of block.fields) { if (field.label !== 'company_id') { companyMatcher[field.label] = field.value; } else { let i = 0; for (const candidateId of field.value) { const companyMatcherRecord = {}; companyMatcherRecord[field.label] = candidateId; companyMatcher.records.push(companyMatcherRecord); i++; } } } } return new CompanyMatcher(companyMatcher); } } export class Address { street: string = ''; city: string = ''; state: string = ''; country: string = ''; zip: string = ''; constructor(obj?) { if (obj) { if (obj.street) { this.street = obj.street; } if (obj.city) { this.city = obj.city; } if (obj.state) { this.city = obj.city; } if (obj.country) { this.country = obj.country; } if (obj.zip) { this.zip = obj.zip; } } } public toJSON() { return { street: this.street, city: this.city, state: this.state, country: this.country, zip: this.zip }; } } export class CompanyMatcherRecord { company_id = ''; score = -1; display_name: ''; constructor(obj?) { if (obj) { if (obj.company_id) { this.company_id = obj.company_id; } if (obj.score) { this.score = obj.score; } if (obj.display_name) { this.display_name = obj.display_name; } } } public toJSON() { return { company_id: this.company_id, score: this.score, display_name: this.display_name }; } }