import {Entity} from "./Entity.interface"; import {ExampleEntityData} from "./example-entity-data"; export enum Pred { Change_but_not_a_promotion = 'change_but_not_a_promotion', Less_specific_title_but_not_a_promotion = 'less_specific_title_but_not_a_promotion', More_specific_title_but_not_promotion = 'more_specific_title_but_not_promotion', Promotion = 'promotion', Same = 'same', Unknown = 'unknown' } export class TrackPromotionChanges implements Entity { private _title_changes: TrackPromotionChangesInput[] = []; private _version: string = ''; private _pred = 'unknown'; private _class_results: ClassificationResObject = new ClassificationResObject(); constructor(obj?: any) { if (obj) { if (obj.title_changes) { if (obj.title_changes[0]) { this._title_changes.push(new TrackPromotionChangesInput(obj.title_changes[0])); } } if (obj.version) { this._version = obj.version; } if (obj.pred) { this._pred = obj.pred; } if (obj.class_results) { this._class_results = new ClassificationResObject(obj.class_results) } } } get title_changes(): TrackPromotionChangesInput[] { return this._title_changes; } set title_changes(value: TrackPromotionChangesInput[]) { this._title_changes = value; } get pred(): string { return this._pred; } set pred(value: string) { this._pred = value; } get version(): string { return this._version; } set version(value: string) { this._version = value; } get class_results(): ClassificationResObject { return this._class_results; } set class_results(value: ClassificationResObject) { this._class_results = value; } public toJSON() { return { title_changes: this.title_changes, class_results: this.class_results, pred: this.pred, }; } public toNerEntities(type = 1) { return { relationOptions: [], entities: { } }; } nerEntityTypeOptions(): any[] { return []; } public toDsProjectRoom() { const data: any = { text: '', url: '', showInIframe: false }; const blocks = [ { blockName: '', blockDesc: '', numColumns: 1, fields: [ { label: 'pred', inputType: 'select', selectOptions: ['0', '1'] }, ] }]; const final = []; for (const i in blocks) { final.push(blocks[i]); } return {blocks: final, data: data}; } public fromDsProjectRoom(obj: any[], data: any) { const titles = data.text.split('TO'); const historyTitle = []; for (const title of titles) { historyTitle.push({title: title}); } const trackPromotionChanges = { titles_history: historyTitle, pred: 'unknown' }; let block: any; for (block of obj) { trackPromotionChanges.pred = 'unknown'; let field: any; for (field of block.fields) { trackPromotionChanges.pred = field.value; } } return new TrackPromotionChanges(trackPromotionChanges); } public toShortInputOutput() { return { map_in: ['title_changes.0.BEFORE_TITLE', 'title_changes.0.AFTER_TITLE'], map_in_text: ['BEFORE_TITLE', 'AFTER_TITLE'], map_out: ['0.pred'], map_out_text: [''] }; } } export class ClassificationResObject { public change_but_not_a_promotion: ClassificationStruct = new ClassificationStruct(); public promotion: ClassificationStruct = new ClassificationStruct(); public less_specific_title_but_not_a_promotion: ClassificationStruct = new ClassificationStruct(); public more_specific_title_but_not_promotion: ClassificationStruct = new ClassificationStruct(); public same: ClassificationStruct = new ClassificationStruct(); constructor(obj?: any) { if (obj) { if (obj.change_but_not_a_promotion) { this.change_but_not_a_promotion = obj.change_but_not_a_promotion; } if (obj.promotion) { this.promotion = obj.promotion; } if (obj.less_specific_title_but_not_a_promotion) { this.less_specific_title_but_not_a_promotion = obj.less_specific_title_but_not_a_promotion; } if (obj.more_specific_title_but_not_promotion) { this.more_specific_title_but_not_promotion = obj.more_specific_title_but_not_promotion; } if (obj.same) { this.same = obj.same; } } } public toJSON() { return { change: this.change_but_not_a_promotion, promotion: this.promotion, less_specific_title: this.less_specific_title_but_not_a_promotion, more_specific_title: this.more_specific_title_but_not_promotion, same: this.same }; } } export class ClassificationStruct { public probability = -1; public threshold = -1; constructor(obj?: any) { if (obj) { if (obj.probability) { this.probability = obj.probability; } if (obj.threshold) { this.threshold = obj.threshold; } } } public toJSON() { return { probability: this.probability, threshold: this.threshold, }; } } export class TrackPromotionChangesInput { INDIVIDUAL_ID = ''; RAW_RECORD_ID = ''; TRANSACTION_ID = ''; PUBLISH_STATUS = 'PUBLISHABLE'; BEFORE_TITLE = ''; AFTER_TITLE = ''; constructor(obj?: any) { if (obj) { if (obj.INDIVIDUAL_ID) { this.INDIVIDUAL_ID = obj.INDIVIDUAL_ID; } if (obj.RAW_RECORD_ID) { this.RAW_RECORD_ID = obj.RAW_RECORD_ID; } if (obj.TRANSACTION_ID) { this.TRANSACTION_ID = obj.TRANSACTION_ID; } if (obj.PUBLISH_STATUS) { this.PUBLISH_STATUS = obj.PUBLISH_STATUS; } if (obj.BEFORE_TITLE) { this.BEFORE_TITLE = obj.BEFORE_TITLE; } if (obj.AFTER_TITLE) { this.AFTER_TITLE = obj.AFTER_TITLE; } } } }