import {Entity} from './entity'; import {DsProjectRoomBlock, DsProjectRoomBlockField, DsProjectRoomData} from "../dynamic-labeling-room/entities"; 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?) { 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: DsProjectRoomData = new DsProjectRoomData({ 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(new DsProjectRoomBlock(blocks[i])); } return {blocks: final, data: data}; } public fromDsProjectRoom(obj: DsProjectRoomBlock[], data: DsProjectRoomData) { const jobExtractor = { url: data.url, records: [] }; let block: DsProjectRoomBlock; let item: any; for (item of obj) { const jobsExtractorRecord = {}; for (block of item) { let field: DsProjectRoomBlockField; for (field of block.fields) { jobsExtractorRecord[field.label] = field.value; } } jobExtractor.records.push(jobsExtractorRecord); } return new JobsExtractor(jobExtractor); } } export class JobsExtractorRecord { title = ''; link = ''; location = ''; date = ''; text = ''; // Not included requsetd by Niv: // category = ''; // description = ''; constructor(obj?) { 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; } // if (obj.category) { // Not included requsetd by Niv // this.category = obj.category; // } // if (obj.description) { // Not included requsetd by Niv // this.description = obj.description; // } } } toJSON() { return { title: this.title, link: this.link, location: this.location, date: this.date, text : this.text, // category: this.category, // Not included requsetd by Niv // description: this.description, Not included requsetd by Niv } } public toNerEntities(type = 1) { return { relationOptions: [], entities: { job_id: '', job_title: '', job_link: '', job_location: '', job_date: '', // job_category: '', // Not included requsetd by Niv // job_description: '' // Not included requsetd by Niv } } } }