import {Entity} from "./Entity.interface"; import {ExampleEntityData} from "./example-entity-data"; export class JobsExtractor implements Entity { private _hints: any[] = []; private _url = ''; private _html = ''; private _helper_url_list: string[] = []; private _helper_html_list: string[] = []; private _records: JobsExtractorRecord[] = []; private _exampleEntityData: ExampleEntityData = new ExampleEntityData('job-extractor'); constructor(obj?: any) { if (obj) { if (obj.hints) { for (const i in obj.hints) { this._hints.push(obj.hints[i]); } } if (obj.url) { this._url = obj.url; } if (obj.html) { this._html = obj.html; } if (obj.html_content) { this._html = obj.html_content; } if (obj.helper_url_list) { for (const i in obj.helper_url_list) { this._helper_url_list.push(obj.helper_url_list[i]); } } if (obj.helper_html_list) { for (const i in obj.helper_html_list) { this._helper_html_list.push(obj.helper_html_list[i]); } } if (obj.records) { for (const i in obj.records) { this._records.push(new JobsExtractorRecord(obj.records[i])); } } } } get hints(): any[] { return this._hints; } set hints(value: any[]) { this._hints = value; } get url(): string { return this._url; } set url(value: string) { this._url = value; } get html(): string { return this._html; } set html(value: string) { this._html = value; } get helper_url_list(): string[] { return this._helper_url_list; } set helper_url_list(value: string[]) { this._helper_url_list = value; } get helper_html_list(): string[] { return this._helper_html_list; } set helper_html_list(value: string[]) { this._helper_html_list = value; } get records(): JobsExtractorRecord[] { return this._records; } set records(value: JobsExtractorRecord[]) { this._records = value; } toJSON() { return { hints: this.hints, url: this.url, html: this.html, helper_url_list: this.helper_url_list, helper_html_list: this.helper_html_list, records: this.records.map((o) => o.toJSON()) } } nerEntityTypeOptions(): any[] { return []; } public toNerEntities(): any { } public toDsProjectRoom() { const data: any = { text: '', url: this._exampleEntityData.getExampleData(), showInIframe: true, isList: true, listHeader: 'Records', listItemDefaultHeader: 'Record', listObjIndex: 0, listFirstItemIndex: 2 }; const blocks = [ { blockName: 'record', blockDesc: '', numColumns: 4, fields: [ {label: 'link', inputType: 'text'}, {label: 'location', inputType: 'text'}, {label: 'text', inputType: 'text'}, {label: 'title', inputType: 'text'}, {label: 'description', inputType: 'text'}, {label: 'category', inputType: 'text'}, ] } ]; const final = []; for (const i in blocks) { final.push(blocks[i]); } return {blocks: final, data: data}; } public fromDsProjectRoom(obj: any[], data: any) { const jobExtractor: any = { url: data.url, records: [] }; let block: any; let item: any; for (item of obj) { const jobsExtractorRecord: any = {}; for (block of item) { let field: any; for (field of block.fields) { jobsExtractorRecord[field.label] = field.value; } } jobExtractor.records.push(jobsExtractorRecord); } return new JobsExtractor(jobExtractor); } public toShortInputOutput() { return { }; } } export class JobsExtractorRecord { title = ''; link = ''; location = ''; date = ''; text = ''; constructor(obj?: any) { if (obj) { if (obj.title) { this.title = obj.title; } if (obj.link) { this.link = obj.link; } if (obj.location) { this.location = obj.location; } if (obj.date_text) { this.date = obj.date_text; } if (obj.text) { this.text = obj.text; } } } toJSON() { return { title: this.title, link: this.link, location: this.location, date: this.date, text : this.text, } } public toNerEntities(type = 1) { return { relationOptions: [], entities: { job_id: '', job_title: '', job_link: '', job_location: '', job_date: '', } } } nerEntityTypeOptions(): any[] { return []; } }