/** * TRP classes for (generic document) table objects */ import { ApiBlockType, ApiRelationshipType } from "./api-models/base"; import { ApiBlock } from "./api-models/document"; import { ApiCellBlock, ApiMergedCellBlock, ApiTableBlock, ApiTableCellEntityType, ApiTableEntityType, ApiTableFooterBlock, ApiTableTitleBlock } from "./api-models/table"; import { AggregationMethod, IBlockManager, IBlockTypeFilterOpts, IHostedApiBlockWrapper, IRenderable, IRenderOpts, PageHostedApiBlockWrapper } from "./base"; import { IWithContent, SelectionElement, Signature, Word } from "./content"; import { Geometry } from "./geometry"; /** * Generic base class for a table cell, which may be merged or not * * (Because mixins can't implement constructor logic) */ declare class CellBaseGeneric extends PageHostedApiBlockWrapper implements IHostedApiBlockWrapper { _geometry: Geometry>; _parentTable: TableGeneric; constructor(block: TBlock, parentTable: TableGeneric); /** * Position of the cell on the input image / page */ get geometry(): Geometry>; /** * Parsed `Table` to which this cell belongs */ get parentTable(): TableGeneric; } /** * Properties that a table cell should implement regardless whether it's merged or classic */ export interface ICellBaseProps { /** * 1-based index for which column this cell starts at in the table */ get columnIndex(): number; /** * How many columns of the table this cell spans (if merged - otherwise always =1) */ get columnSpan(): number; /** * Confidence score of the table cell structure detection * * This score reflects the confidence of the model detecting the table cell structure itself. For * the text OCR confidence, see the `.getOcrConfidence()` method instead. */ get confidence(): number; set confidence(newVal: number); /** * 1-based index for which row this cell starts at in the table */ get rowIndex(): number; /** * How many rows of the table this cell spans (if merged - otherwise always =1) */ get rowSpan(): number; /** * Aggregate OCR confidence score of the text (and selection elements) in this cell * * This score reflects the aggregated OCR confidence of all the text content detected in the * cell. For the model's confidence on the table structure itself, see `.confidence`. * * @param {AggregationMethod} aggMethod How to combine individual word OCR confidences together * @returns Aggregated confidence, or null if this cell contains no content/text */ getOcrConfidence(aggMethod?: AggregationMethod): number | null; /** * Check if this cell is tagged with any of the given EntityType(s) e.g. COLUMN_HEADER, etc. * * For more information on table cell entity types returnable by Amazon Textract, see: * https://docs.aws.amazon.com/textract/latest/dg/how-it-works-tables.html * * @param entityType The type to check for, or an array of multiple types to allow. * @returns true if the EntityType is set, null if block EntityTypes is undefined, false otherwise. */ hasEntityTypes(entityType: ApiTableCellEntityType | ApiTableCellEntityType[]): boolean | null; } declare const CellGeneric_base: { new (...args: any[]): { readonly columnIndex: number; readonly columnSpan: number; /** * 0-100 based confidence score of the table cell structure detection * * This score reflects the confidence of the model detecting the table cell structure itself. For * the text OCR confidence, see the `.getOcrConfidence()` method instead. */ confidence: number; readonly rowIndex: number; readonly rowSpan: number; /** * Aggregate OCR confidence score of the text (and selection elements) in this cell * * This score reflects the aggregated OCR confidence of all the text content detected in the * cell. For the model's confidence on the table structure itself, see `.confidence`. * * @param {AggregationMethod} aggMethod How to combine individual word OCR confidences together * @returns Aggregated confidence, or null if this cell contains no content/text */ getOcrConfidence(aggMethod?: AggregationMethod): number | null; /** * Check if this cell is tagged with any of the given EntityType(s) e.g. COLUMN_HEADER, etc. * * For more information on table cell entity types returnable by Amazon Textract, see: * https://docs.aws.amazon.com/textract/latest/dg/how-it-works-tables.html * * @param entityType The type to check for, or an array of multiple types to allow. * @returns true if the EntityType is set, null if block EntityTypes is undefined, false otherwise. */ hasEntityTypes(entityType: ApiTableCellEntityType | ApiTableCellEntityType[]): boolean | null; /** * Get semantic HTML of the cell as a `` (if header/title EntityType) or `` element */ html(opts?: IRenderOpts | undefined): string; /** * The basic human-readable `str()` representation for a table cell is just the cell's text. */ str(): string; readonly id: string; readonly blockType: ApiBlockType; readonly childBlockIds: string[]; relatedBlockIdsByRelType(relType: ApiRelationshipType | ApiRelationshipType[]): string[]; _dict: ApiCellBlock | ApiMergedCellBlock; readonly dict: ApiCellBlock | ApiMergedCellBlock; parentPage: IBlockManager; iterRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): Iterable>; listRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): import("./base").IApiBlockWrapper[]; readonly nContentItems: number; getText(opts?: IBlockTypeFilterOpts | undefined): string; iterContent(opts?: IBlockTypeFilterOpts | undefined): Iterable; listContent(opts?: IBlockTypeFilterOpts | undefined): (Word | SelectionElement | Signature)[]; get text(): string; }; } & { new (...args: any[]): { getText(opts?: IBlockTypeFilterOpts | undefined): string; iterContent({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): Iterable; listContent({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): (Word | SelectionElement | Signature)[]; readonly nContentItems: number; get text(): string; readonly id: string; readonly blockType: ApiBlockType; readonly childBlockIds: string[]; relatedBlockIdsByRelType(relType: ApiRelationshipType | ApiRelationshipType[]): string[]; _dict: ApiBlock; readonly dict: ApiBlock; parentPage: IBlockManager; iterRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): Iterable>; listRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): import("./base").IApiBlockWrapper[]; }; } & typeof CellBaseGeneric; /** * Generic base class for a non-merged table cell (or sub-cell of a merged cell) * * If you're consuming this library, you probably just want to use `document.ts/Cell`. */ export declare class CellGeneric extends CellGeneric_base implements IWithContent { constructor(block: ApiCellBlock, parentTable: TableGeneric); } declare const MergedCellGeneric_base: { new (...args: any[]): { readonly columnIndex: number; readonly columnSpan: number; /** * 0-100 based confidence score of the table cell structure detection * * This score reflects the confidence of the model detecting the table cell structure itself. For * the text OCR confidence, see the `.getOcrConfidence()` method instead. */ confidence: number; readonly rowIndex: number; readonly rowSpan: number; /** * Aggregate OCR confidence score of the text (and selection elements) in this cell * * This score reflects the aggregated OCR confidence of all the text content detected in the * cell. For the model's confidence on the table structure itself, see `.confidence`. * * @param {AggregationMethod} aggMethod How to combine individual word OCR confidences together * @returns Aggregated confidence, or null if this cell contains no content/text */ getOcrConfidence(aggMethod?: AggregationMethod): number | null; /** * Check if this cell is tagged with any of the given EntityType(s) e.g. COLUMN_HEADER, etc. * * For more information on table cell entity types returnable by Amazon Textract, see: * https://docs.aws.amazon.com/textract/latest/dg/how-it-works-tables.html * * @param entityType The type to check for, or an array of multiple types to allow. * @returns true if the EntityType is set, null if block EntityTypes is undefined, false otherwise. */ hasEntityTypes(entityType: ApiTableCellEntityType | ApiTableCellEntityType[]): boolean | null; /** * Get semantic HTML of the cell as a `` (if header/title EntityType) or `` element */ html(opts?: IRenderOpts | undefined): string; /** * The basic human-readable `str()` representation for a table cell is just the cell's text. */ str(): string; readonly id: string; readonly blockType: ApiBlockType; readonly childBlockIds: string[]; relatedBlockIdsByRelType(relType: ApiRelationshipType | ApiRelationshipType[]): string[]; _dict: ApiCellBlock | ApiMergedCellBlock; readonly dict: ApiCellBlock | ApiMergedCellBlock; parentPage: IBlockManager; iterRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): Iterable>; listRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): import("./base").IApiBlockWrapper[]; readonly nContentItems: number; getText(opts?: IBlockTypeFilterOpts | undefined): string; iterContent(opts?: IBlockTypeFilterOpts | undefined): Iterable; listContent(opts?: IBlockTypeFilterOpts | undefined): (Word | SelectionElement | Signature)[]; get text(): string; }; } & { new (...args: any[]): { getText(opts?: IBlockTypeFilterOpts | undefined): string; iterContent({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): Iterable; listContent({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): (Word | SelectionElement | Signature)[]; readonly nContentItems: number; get text(): string; readonly id: string; readonly blockType: ApiBlockType; readonly childBlockIds: string[]; relatedBlockIdsByRelType(relType: ApiRelationshipType | ApiRelationshipType[]): string[]; _dict: ApiBlock; readonly dict: ApiBlock; parentPage: IBlockManager; iterRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): Iterable>; listRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): import("./base").IApiBlockWrapper[]; }; } & typeof CellBaseGeneric; /** * Generic base class for a merged table cell (Spanning more than one row or column of the table) * * If you're consuming this library, you probably just want to use `document.ts/MergedCell`. */ export declare class MergedCellGeneric extends MergedCellGeneric_base { constructor(block: ApiMergedCellBlock, parentTable: TableGeneric); /** * Number of underlying (un-merged) sub-cells spanned by this merged cell */ get nSubCells(): number; /** * Fetch a list of the underlying (un-merged) sub-`Cell`s spanned by this merged cell * * The returned list is a shallow-copied snapshot */ listSubCells(): CellGeneric[]; iterContent(opts?: IBlockTypeFilterOpts): Iterable; /** * List the content items in this object * * Concatenates content across all sub-cells */ listContent(opts?: IBlockTypeFilterOpts): Array; /** * Iterate through the sub-cells of this merged cell * @example * for (const subCell of merged.iterCells()) { * console.log(subCell.str()); * } * @example * const subCells = [...merged.iterCells()]; */ iterSubCells(): Iterable>; } /** * Generic base class for a table row * * If you're consuming this library, you probably just want to use `document.ts/Row`. */ export declare class RowGeneric { _cells: Array | MergedCellGeneric>; _parentTable: TableGeneric; constructor(cells: (CellGeneric | MergedCellGeneric)[] | undefined, parentTable: TableGeneric); /** * Number of cells in this table row */ get nCells(): number; /** * Parsed `Table` to which this row belongs */ get parentTable(): TableGeneric; /** * Tab-separated text from each cell in this row */ get text(): string; /** * Aggregate table structure confidence score of the cells in this row * * This score reflects the overall confidence of the table cell structure in this row. For the * actual OCR confidence of cell contents, see `.getOcrConfidence()`. * * @param {AggregationMethod} aggMethod How to combine individual cell confidences together * @returns Aggregated confidence, or null if this row contains no content/text */ getConfidence(aggMethod?: AggregationMethod): number | null; /** * Aggregate OCR confidence score of the text (and selection elements) in this row * * This score reflects the aggregated OCR confidence of all the text content detected in this * row's cells. For the model's confidence on the table structure itself, see `.getConfidence()`. * * @param {AggregationMethod} aggMethod How to combine individual word OCR confidences together * @returns Aggregated confidence, or null if this row contains no content/text */ getOcrConfidence(aggMethod?: AggregationMethod): number | null; /** * Iterate through the cells in this row * @example * for (const cell of row.iterCells()) { * console.log(cell.text); * } * @example * [...row.iterCells()].forEach( * (cell) => console.log(cell.text) * ); */ iterCells(): Iterable | MergedCellGeneric>; /** * Create a snapshot list of the cells in this row */ listCells(): Array | MergedCellGeneric>; /** * The human-readable `str()` representation of a table row uses `[]` to wrap each cell's content */ str(): string; } /** * Configuration options for listing merged & multi-spanned table cells */ export interface IGetCellOptions { /** * Set `true` to ignore merged cells, returning specific sub-cells. (Default `false`) */ ignoreMerged?: boolean; } /** * Configuration options for listing table rows */ export interface IGetRowOptions { /** * Set `true` to ignore merged cells, returning specific sub-cells. (Default `false`) */ ignoreMerged?: boolean; /** * Set `true` to include rowspan>1 cells in every `Row` they intersect with. (Default `false`) */ repeatMultiRowCells?: boolean; } declare const TableFooterGeneric_base: { new (...args: any[]): { getText(opts?: IBlockTypeFilterOpts | undefined): string; iterWords({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): Iterable; listWords({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): Word[]; readonly nWords: number; get text(): string; wordAtIndex(ix: number): Word; readonly id: string; readonly blockType: ApiBlockType; readonly childBlockIds: string[]; relatedBlockIdsByRelType(relType: ApiRelationshipType | ApiRelationshipType[]): string[]; _dict: ApiBlock; readonly dict: ApiBlock; parentPage: IBlockManager; iterRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): Iterable>; listRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): import("./base").IApiBlockWrapper[]; }; } & typeof PageHostedApiBlockWrapper; /** * Generic base class for a trailing/footer caption on a table * * If you're consuming this library, you probably just want to use `document.ts/TableFooter`. */ export declare class TableFooterGeneric extends TableFooterGeneric_base implements IRenderable { /** * 0-100 based confidence of the table structure model (separate from OCR content confidence) */ get confidence(): number; /** * Semantic `html()` for a table footer is just the inner (HTML-escaped) text content * * The presence of header and/or footer will affect what element it gets wrapped in when rendering * an overall `Table` object. */ html({ includeBlockTypes, skipBlockTypes }?: IRenderOpts): string; str(): string; } declare const TableTitleGeneric_base: { new (...args: any[]): { getText(opts?: IBlockTypeFilterOpts | undefined): string; iterWords({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): Iterable; listWords({ includeBlockTypes, onUnexpectedBlockType, skipBlockTypes, }?: IBlockTypeFilterOpts): Word[]; readonly nWords: number; get text(): string; wordAtIndex(ix: number): Word; readonly id: string; readonly blockType: ApiBlockType; readonly childBlockIds: string[]; relatedBlockIdsByRelType(relType: ApiRelationshipType | ApiRelationshipType[]): string[]; _dict: ApiBlock; readonly dict: ApiBlock; parentPage: IBlockManager; iterRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): Iterable>; listRelatedItemsByRelType(relType: ApiRelationshipType | ApiRelationshipType[], opts?: IBlockTypeFilterOpts | undefined): import("./base").IApiBlockWrapper[]; }; } & typeof PageHostedApiBlockWrapper; /** * Generic base class for a leading/header caption on a table * * If you're consuming this library, you probably just want to use `document.ts/TableTitle`. */ export declare class TableTitleGeneric extends TableTitleGeneric_base implements IRenderable { /** * 0-100 based confidence of the table structure model (separate from OCR content confidence) */ get confidence(): number; /** * Semantic `html()` for a table title is just the inner (HTML-escaped) text content * * The presence of header and/or footer will affect what element it gets wrapped in when rendering * an overall `Table` object. */ html({ includeBlockTypes, skipBlockTypes }?: IRenderOpts): string; str(): string; } /** * Generic base class for a table, since Page is not defined yet here * * If you're consuming this library, you probably just want to use `document.ts/Table`. */ export declare class TableGeneric extends PageHostedApiBlockWrapper { _cells: CellGeneric[]; _cellsById: { [id: string]: CellGeneric; }; _geometry: Geometry>; _mergedCells: MergedCellGeneric[]; _nCols: number; _nRows: number; constructor(block: ApiTableBlock, parentPage: TPage); /** * Sort an array of table cells by position (row, column) in-place * @param cells Array of (merged or raw) cells */ _sortCellsByLocation | MergedCellGeneric>(cells: Array): void; /** * Update this Table instance's map of (split) Cells by ID for efficient retrieval */ _updateCellsById(): void; /** * Efficiently retrieve a (split) Cell in this table by Textract block ID * * This allows MergedCell objects to retrieve references to parsed Cells they wrap, instead of raw * ApiCellBlocks. * @throws (Rather than returning undefined) if the block ID is missing from the table. */ _getSplitCellByBlockId(id: string): CellGeneric; /** * Get the Cell at a particular Y, X coordinate in the table. * @param rowIndex 1-based index of the target row in the table * @param columnIndex 1-based index of the target column in the table * @param opts Configuration options for merged and multi-spanning cells * @returns Cell at the specified row & column, or undefined if none is present. */ cellAt(rowIndex: number, columnIndex: number, opts?: IGetCellOptions): CellGeneric | MergedCellGeneric | undefined; /** * List the cells at a particular {row, column, or combination} in the table * @param rowIndex 1-based index of the target row in the table * @param columnIndex 1-based index of the target column in the table * @param opts Configuration options for merged and multi-spanning cells * @returns Cell at the specified row & column, or undefined if none is present. */ cellsAt(rowIndex: number | null, columnIndex: number | null, opts?: IGetCellOptions): Array | MergedCellGeneric>; /** * Aggregate OCR confidence score of the text (and selection elements) in this table * * This score reflects the aggregated OCR confidence of all the text content detected in this * table. For the model's confidence on the table structure itself, see `.confidence`. * * @param {AggregationMethod} aggMethod How to combine individual word OCR confidences together * @returns Aggregated confidence, or null if this table contains no content/text */ getOcrConfidence(aggMethod?: AggregationMethod): number | null; /** * Iterate through the footers linked to this table */ iterFooters(): Iterable>; /** * Iterate through the rows of the table * @param opts Configuration options for merged and multi-spanning cells * @example * for (const row of table.iterRows()) { * for (const cell of row.iterCells()) { * console.log(cell.text); * } * } * @example * [...table.iterRows()].forEach( * (row) => [...row.iterCells()].forEach( * (cell) => console.log(cell.text) * ) * ); */ iterRows(opts?: IGetRowOptions): Iterable>; /** * Iterate through the titles linked to this table */ iterTitles(): Iterable>; /** * List the footer(s) associated with the table */ listFooters(): TableFooterGeneric[]; /** * List the rows of the table * @param opts Configuration options for merged and multi-spanning cells */ listRows(opts?: IGetRowOptions): RowGeneric[]; /** * List the title(s) associated with the table */ listTitles(): TableTitleGeneric[]; /** * List the cells at a particular {row, column, or combination} in the table * @param rowIndex 1-based index of the target row in the table * @param opts Configuration options for merged and multi-spanning cells */ rowAt(rowIndex: number, opts?: IGetRowOptions): RowGeneric; /** * Confidence score of the table structure detection * * This score reflects the confidence of the model detecting the table structure itself. For the * combined table content OCR confidence, see the `.getOcrConfidence()` method instead. */ get confidence(): number; set confidence(newVal: number); /** * Access the first `TableFooter` associated to this table, if any * * This convenience property is provided because as far as we're aware at time of writing, * there's always either 0 or 1 footer linked to a table by the model - no more. */ get firstFooter(): TableFooterGeneric | undefined; /** * Access the first `TableTitle` associated to this table, if any * * This convenience property is provided because as far as we're aware at time of writing, * there's always either 0 or 1 title linked to a table by the model - no more. */ get firstTitle(): TableTitleGeneric | undefined; /** * Position of the table on the input image / page */ get geometry(): Geometry>; /** * Total number of cells in the table * * (For the total number of *sub-cells* ignoring merged cells, just use `nColumns * nRows`) */ get nCells(): number; /** * Number of columns in the table */ get nColumns(): number; /** * Number of rows in the table */ get nRows(): number; /** * Get the overall type (EntityType) of this table * * In the underlying Amazon Textract API, table EntityTypes is a list. In practice though, it will either * contain `STRUCTURED_TABLE`, or `SEMI_STRUCTURED_TABLE`, or neither. * * This dynamic property simplifies checking whether a table is structured, semi-structured, or untagged. * * @throws Error if the table block is tagged with multiple conflicting EntityTypes. */ get tableType(): ApiTableEntityType | null; /** * The plain text content of this table, with newlines between rows and tabs between cells */ get text(): string; /** * Generate semantic HTML representation for this table * * The outer element will be a `` *unless both* table title and footer elements are * present - because an HTML table can only have one `
` child. In those cases, you'll * see an outer `
`. */ html(opts?: IRenderOpts): string; str(): string; } /** * Interface for a (`Page`-like) object that exposes a collection of tables */ export interface IWithTables { /** * Iterate through the available `Table`s */ iterTables(): Iterable>; /** * Fetch a snapshot of the list of `Table`s */ listTables(): TableGeneric[]; /** * Fetch a particular parsed `Table` by its index */ tableAtIndex(ix: number): TableGeneric; /** * Number of `Table`s present */ get nTables(): number; } export {};