UNPKG

@scribelabsai/amazon-trp

Version:

Amazon Textract Response Parser library for Node.

44 lines 1.55 kB
import { Geometry } from '../Geometry'; import { SelectionElement } from '../SelectionElement'; import { Word } from '../Word'; export class Cell { constructor(block, blockMap) { this.block = block; this.confidence = block.Confidence; this.rowIndex = block.RowIndex; this.columnIndex = block.ColumnIndex; this.rowSpan = block.RowSpan; this.columnSpan = block.ColumnSpan; this.geometry = new Geometry(block.Geometry); this.id = block.Id; this.content = []; const t = []; if (block.Relationships && blockMap) { block.Relationships.forEach((rs) => { if (rs.Type === 'CHILD') { rs.Ids.forEach((id) => { const b = blockMap[id]; if (b?.BlockType === 'WORD') { const w = new Word(b); this.content.push(w); t.push(w.text); } else if (b?.BlockType === 'SELECTION_ELEMENT') { const se = new SelectionElement(b); this.content.push(se); t.push(se.selectionStatus); } }); } }); } this.text = t.join(' '); } toString() { return this.text.trim(); } static fromCell(cell) { return Object.create(cell); } } //# sourceMappingURL=Cell.js.map