import {Entity} from "./entity"; import {DsProjectRoomBlock, DsProjectRoomBlockField, DsProjectRoomData} from "../dynamic-labeling-room/entities"; import {ExampleEntityData} from "./example-entity-data"; export class Trex implements Entity { private _url = ''; private _helper_url_list = ''; private _domain = ''; private _page_title = ''; private _page_description = ''; private _page_keywords = ''; private _page_type = ''; private _exampleEntityData: ExampleEntityData = new ExampleEntityData('trex'); private _records: TrexRecord[] = []; constructor(obj?) { if (obj) { if (obj.url) { this._url = obj.url; } if (obj.helper_url_list) { this._helper_url_list = obj.helper_url_list; } if (obj.records) { for (const i in obj.records) { this._records.push(new TrexRecord(obj.records[i])); } } } } get url(): string { return this._url; } set url(value: string) { this._url = value; } get records(): any[] { return this._records; } set records(value: any[]) { this._records = value; } get helper_url_list(): string { return this._helper_url_list; } set helper_url_list(value: string) { this._helper_url_list = value; } get page_type(): string { return this._page_type; } set page_type(value: string) { this._page_type = value; } get page_keywords(): string { return this._page_keywords; } set page_keywords(value: string) { this._page_keywords = value; } get page_description(): string { return this._page_description; } set page_description(value: string) { this._page_description = value; } get page_title(): string { return this._page_title; } set page_title(value: string) { this._page_title = value; } get domain(): string { return this._domain; } set domain(value: string) { this._domain = value; } public toJSON() { return { url: this.url, helper_url_list: this.helper_url_list, records: this.records.map((o) => o.toJSON()) }; } nerEntityTypeOptions(): any[] { return []; } public toNerEntities(): any {} public toDsProjectRoom() { const data: DsProjectRoomData = new DsProjectRoomData({ url: this._exampleEntityData.getExampleData(), showInIframe: false, isList: true, listHeader: 'Records', listItemDefaultHeader: 'Person', listObjIndex: 0, listFirstItemIndex: 2, listSecondItemIndex: 4 }); const blocks = [ { blockName: 'person', blockDesc: '', numColumns: 4, fields: [ {label: 'bio', inputType: 'text'}, {label: 'prefix', inputType: 'text'}, {label: 'first', inputType: 'text'}, {label: 'middle', inputType: 'text'}, {label: 'last', inputType: 'text'}, {label: 'suffix', inputType: 'text'}, {label: 'credentials', inputType: 'text'}, {label: 'job_title', inputType: 'text'}, {label: 'company', inputType: 'text'}, ] }, { blockName: 'connections', blockDesc: '', numColumns: 3, fields: [ {label: 'images', inputType: 'text_list'}, {label: 'links', inputType: 'text_list'}, {label: 'phones', inputType: 'text_list'}, {label: 'mobiles', inputType: 'text_list'}, {label: 'faxes', inputType: 'text_list'}, {label: 'urls', inputType: 'text_list'}, {label: 'emails', 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 trex = { domain: data.url, records: [] }; let block: DsProjectRoomBlock; let item: any; for (item of obj) { const trexRecord = {}; for (block of item) { let field: DsProjectRoomBlockField; for (field of block.fields) { trexRecord[field.label] = field.value; } } trex.records.push(trexRecord); } return new Trex(trex); } } export class TrexRecord implements Entity { valid = true; section_type = ''; section_idx = 0; n_sections = 0; section_valid = false; section_headline = ''; bio = ''; prefix = ''; first = ''; middle = ''; last = ''; suffix = ''; credentials = ''; job_title = ''; company = ''; images: string[] = []; links: string[] = []; phones: string[] = []; mobiles: string[] = []; faxes: string[] = []; urls: string[] = []; emails: string[] = []; text: ''; constructor(obj?) { if (obj) { if (obj.valid) { this.valid = obj.valid; } if (obj.section_type) { this.section_type = obj.section_type; } if (obj.section_idx) { this.section_idx = obj.section_idx; } if (obj.n_sections) { this.n_sections = obj.n_sections; } if (obj.section_valid) { this.section_valid = obj.section_valid; } if (obj.section_headline) { this.section_headline = obj.section_headline; } if (obj.bio) { this.bio = obj.bio; } if (obj.prefix) { this.prefix = obj.prefix; } if (obj.first) { this.first = obj.first; } if (obj.middle) { this.middle = obj.middle; } if (obj.last) { this.last = obj.last; } if (obj.suffix) { this.suffix = obj.suffix; } if (obj.credentials) { this.credentials = obj.credentials; } if (obj.job_title) { this.job_title = obj.job_title; } if (obj.company) { this.company = obj.company; } if (obj.text) { this.text = obj.text; } if (obj.images) { for (const i in obj.images) { this.images.push(obj.images[i]); } } if (obj.links) { for (const i in obj.links) { this.links.push(obj.links[i]); } } if (obj.phones) { for (const i in obj.phones) { this.phones.push(obj.phones[i]); } } if (obj.mobiles) { for (const i in obj.mobiles) { this.mobiles.push(obj.mobiles[i]); } } if (obj.faxes) { for (const i in obj.faxes) { this.faxes.push(obj.faxes[i]); } } if (obj.urls) { for (const i in obj.urls) { this.urls.push(obj.urls[i]); } } if (obj.emails) { for (const i in obj.emails) { this.emails.push(obj.emails[i]); } } } } toJSON() { return { valid: this.valid, section_type: this.section_type, section_idx: this.section_idx, n_sections: this.n_sections, section_valid: this.section_valid, section_headline: this.section_headline, bio: this.bio, prefix: this.prefix, first: this.first, middle: this.middle, last: this.last, suffix: this.suffix, credentials: this.credentials, job_title: this.job_title, company: this.company, images: this.images, links: this.links, phones: this.phones, mobiles: this.mobiles, faxes: this.faxes, urls: this.urls, emails: this.emails, // text: this.text }; } public toNerEntities(type = 1) { let obj: any = { relationOptions: ['per:employee_of', 'per:schools_attended', 'per:title', 'no_relation'], entities: { // valid: '', // section_type: '', // section_idx: '', // n_sections: '', // section_valid: '', section_headline: '', section_mteam: '', section_oteam: '', section_bod: '', section_obod: '', section_directory: '', person: '', bio: '', prefix: '', first: '', middle: '', last: '', suffix: '', credentials: '', job_title: '', company: '', image: '', link: '', phone: '', mobile: '', fax: '', urls: '', email: '', text: '' } }; return obj; } // example of nerEntityTypeOptions [{key: 1, name: 'name a'}, {key: 2, name: 'name b'}]; nerEntityTypeOptions(): any[] { return []; } }