import {Entity} from "./entity"; import {DsProjectRoomBlock, DsProjectRoomData} from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class PersonMatcher implements Entity { private _first_name = ''; private _last_name = ''; private _emails: string[] = []; private _resumes: Resume[] = []; private _addresses: PersonMatcherAddress[] = []; private _social_url: string[] = []; private _phones: string[] = []; private _personUIServiceData: PersonUIService = new PersonUIService(); private _true_label_record: PersonMatcherRecords = new PersonMatcherRecords(); private _exampleEntityData: ExampleEntityData = new ExampleEntityData('person-matcher'); constructor(obj?) { if (obj) { if (obj.first_name) { this._first_name = obj.first_name; } if (obj.last_name) { this._last_name = obj.last_name; } if (obj.resumes) { for (const i in obj.resumes) { this._resumes.push(new Resume(obj.resumes[i])); } } if (obj.emails) { for (const i in obj.emails) { this._emails.push(obj.emails[i]); } } if (obj.social_url) { for (const i in obj.social_url) { this._social_url.push(obj.social_url[i]); } } if (obj.addresses) { for (const i in obj.addresses) { this._addresses.push(new PersonMatcherAddress(obj.addresses[i])); } } if (obj.true_label_record) { this._true_label_record = new PersonMatcherRecords(obj.true_label_record); } if (obj.phones) { for (const i in obj.phones) { this._phones.push(obj.phones[i]); } } if (obj.personUIServiceData) { this._personUIServiceData = new PersonUIService(obj.personUIServiceData); } } } get first_name(): string { return this._first_name; } set first_name(value: string) { this._first_name = value; } get last_name(): string { return this._last_name; } set last_name(value: string) { this._last_name = value; } get resumes(): Resume[] { return this._resumes; } set resumes(value: Resume[]) { this._resumes = value; } get emails(): string[] { return this._emails; } set emails(value: string[]) { this._emails = value; } get social_url(): string[] { return this._social_url; } set social_url(value: string[]) { this._social_url = value; } get addresses(): PersonMatcherAddress[] { return this._addresses; } set addresses(value: PersonMatcherAddress[]) { this._addresses = value; } get true_label_record(): PersonMatcherRecords { return this._true_label_record; } set true_label_record(value: PersonMatcherRecords) { this._true_label_record = value; } get phones(): string[] { return this._phones; } set phones(value: string[]) { this._phones = value; } get personUIServiceData(): PersonUIService { return this._personUIServiceData; } set personUIServiceData(value: PersonUIService) { this._personUIServiceData = value; } public toJSON() { return { first_name: this.first_name, last_name: this.last_name, resumes: this.resumes?.map((o) => new Resume(o).toJSON()), emails: this.emails, social_url: this.social_url, addresses: this.addresses?.map((o) => new PersonMatcherAddress(o).toJSON()), true_label_record: this._true_label_record, phones: this._phones }; } public toNerEntities(type = 1) { return { relationOptions: [], entities: { title: '', company_name: '', city: '', street: '', number: '' } }; } nerEntityTypeOptions(): any[] { return []; } public toDsProjectRoom() { const data: DsProjectRoomData = new DsProjectRoomData({ text: this._exampleEntityData.getExampleData(), url: '', showInIframe: false, }); const blocks = [ { blockName: 'Person Matcher', blockDesc: '', numColumns: 4, fields: [ {label: 'first_name', inputType: 'text'}, {label: 'last_name', inputType: 'text'}, ] }, { blockName: 'Candidate', blockDesc: '', numColumns: 4, fields: [ {label: 'reference_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 personMatcher = { text: data.text, true_label_record: {} }; let block: DsProjectRoomBlock; for (block of obj) { for (const field of block.fields) { if (field.label !== 'reference_id') { personMatcher[field.label] = field.value; } else { let i = 0; for (const candidateId of field.value) { const personMatcherRecord = {}; personMatcherRecord[field.label] = candidateId; personMatcher.true_label_record = personMatcherRecord; i++; } } } } return new PersonMatcher(personMatcher); } } export class PersonMatcherRecords { reference_id = ''; prob = -1; pred = false; constructor(obj?) { if (obj) { if (obj.reference_id) { this.reference_id = obj.reference_id; } if (obj.prob) { this.prob = obj.prob; } if (obj.pred) { this.pred = obj.pred; } } } public toJSON() { return { reference_id: this.reference_id, prob: this.prob, pred: this.pred } } } export class Resume { title = ''; company = ''; company_name = ''; constructor(obj?) { if (obj) { if (obj.title) { this.title = obj.title; } if (obj.company) { this.company = obj.company; } else if (obj.company_name) { this.company = `{name=${obj.company_name}}`; } } } public toJSON() { return { title: this.title, company: this.company } } } export class PersonMatcherAddress { city = ''; street = ''; country = ''; zip = ''; state = ''; constructor(obj?) { if (obj) { if (obj.city) { this.city = obj.city; } if (obj.street) { this.street = obj.street; } if (obj.country) { this.country = obj.country; } if (obj.zip) { this.zip = obj.zip; } if (obj.state) { this.state = obj.state; } } } public toJSON() { return { city: this.city, street: this.street, country: this.country, zip: this.zip, state: this.state } } } export class PersonUIService { id: ''; name = { last: '', first: ''} ; resume = { company: '', title: ''}; email = ''; constructor(obj?) { if (obj) { if (obj.id) { this.id = obj.id; } if (obj.name && obj.name.first) { this.name.first = obj.name.first; } if (obj.name && obj.name.last) { this.name.last = obj.name.last; } if (obj.resume) { if (Array.isArray(obj.resume) && obj.resume.length) { const resumeObj = obj.resume.filter( item => item.primary === true ); if (resumeObj[0].company && resumeObj[0].company.value) { this.resume.company = resumeObj[0].company.value; } if (resumeObj[0].title && resumeObj[0].title.value) { this.resume.title = resumeObj[0].title.value; } } } if (obj.primaryEmails && obj.primaryEmails[0]) { if (obj.primaryEmails[0].address) { this.email = obj.primaryEmails[0].address; } } } } }