import {Entity} from "./entity"; import {DsProjectRoomBlock, DsProjectRoomBlockField, DsProjectRoomData} from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class BioParser implements Entity { private _date = ''; private _url = ''; private _section_idx = -1; private _section_type = ''; private _orig_text = ''; private _text = ''; private _page_id = ''; private _batch_id = -1; private _record: BioParserRecord = new BioParserRecord(); private _exampleEntityData: ExampleEntityData = new ExampleEntityData('bio-parser'); constructor(obj?) { if (obj) { if (obj.date) { this._date = obj.date; } if (obj.url) { this._url = obj.url; } if (obj.section_idx) { this._section_idx = obj.section_idx; } if (obj.section_type) { this._section_type = obj.section_type; } if (obj.orig_text) { this._orig_text = obj.orig_text; } if (obj.text) { this._text = obj.text; } if (obj.page_id) { this._page_id = obj.page_id; } if (obj.batch_id) { this._batch_id = obj.batch_id; } if (obj.record) { this._record = new BioParserRecord(obj.record); } } } get date(): string { return this._date; } set date(value: string) { this._date = value; } get url(): string { return this._url; } set url(value: string) { this._url = value; } get section_idx(): number { return this._section_idx; } set section_idx(value: number) { this._section_idx = value; } get section_type(): string { return this._section_type; } set section_type(value: string) { this._section_type = value; } get orig_text(): string { return this._orig_text; } set orig_text(value: string) { this._orig_text = value; } get text(): string { return this._text; } set text(value: string) { this._text = value; } get page_id(): string { return this._page_id; } set page_id(value: string) { this._page_id = value; } get batch_id(): number { return this._batch_id; } set batch_id(value: number) { this._batch_id = value; } get record(): BioParserRecord { return this._record; } set record(value: BioParserRecord) { this._record = value; } public toJSON() { return { date: this._date, url: this._url, section_idx: this._section_idx, section_type: this._section_type, orig_text: this._orig_text, text: this._text, page_id: this._page_id, batch_id: this._batch_id, record: this._record.toJSON }; } public toNerEntities() { } nerEntityTypeOptions(): any[] { return []; } public toDsProjectRoom() { const data: DsProjectRoomData = new DsProjectRoomData({ text: '', url: this._exampleEntityData.getExampleData(), showInIframe: true }); const blocks = [ { blockName: 'person', blockDesc: '', numColumns: 4, fields: [ {label: 'name', inputType: 'text'}, {label: 'job_title', inputType: 'text'}, {label: 'company', inputType: 'text'}, {label: 'resume', inputType: 'text_list', listObj: [{label: 'organization', inputType: 'text'}, {label: 'title', inputType: 'text'}, {label: 'date_from', inputType: 'text'}, {label: 'date_to', inputType: 'text'}], fullLine: true}, {label: 'education', inputType: 'text_list', listObj: [{label: 'organization', inputType: 'text'}, {label: 'title', inputType: 'text'}, {label: 'date_from', inputType: 'text'}, {label: 'date_to', inputType: 'text'}], fullLine: true}, ] }]; 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 bioParser = { url: data.url, record: {} }; let block: DsProjectRoomBlock; for (block of obj) { bioParser.record = {}; let field: DsProjectRoomBlockField; for (field of block.fields) { bioParser.record[field.label] = field.value; } } return new BioParser(bioParser); } } export class BioParserRecord implements Entity { name = ''; job_title = ''; company = ''; resume: OrgDetails[] = []; education: OrgDetails[] = []; constructor(obj?) { if (obj) { if (obj.name) { this.name = obj.name; } if (obj.job_title) { this.job_title = obj.job_title; } if (obj.company) { this.company = obj.company; } if (obj.resume) { for (const i in obj.resume) { this.resume.push(obj.resume[i]); } } if (obj.education) { for (const i in obj.education) { this.education.push(obj.education[i]); } } } } public toJSON() { return { name: this.name, job_title: this.job_title, company: this.company, resume: this.resume, education: this.resume, }; } public toNerEntities(type = 1) { return { relationOptions: ['per_employee_of', 'per_school_attended', 'per_title', 'per_start_employment_date', 'per_end_employment_date', 'per_academic_degree', 'title_organization', 'title_education'], entities: { person: '', organization: '', job_title: '', date: '', academic_title: '', credentials: '', } }; } nerEntityTypeOptions(): any[] { return []; } } export class OrgDetails implements Entity { organization = ''; title = ''; date_from = ''; date_to = ''; constructor(obj?) { if (obj) { if (obj.organization) { this.organization = obj.organization; } if (obj.title) { this.title = obj.title; } if (obj.date_from) { this.date_from = obj.date_from; } if (obj.date_to) { this.date_to = obj.date_to; } } } public toJSON() { return { organization: this.organization, title: this.title, date_from: this.date_from, date_to: this.date_to }; } public toNerEntities(type = 1) { } nerEntityTypeOptions(): any[] { return []; } }