/** * TRP classes for (generic document) query objects * * See: https://docs.aws.amazon.com/textract/latest/dg/queryresponse.html */ import { ApiQueryBlock, ApiQueryResultBlock } from "./api-models/query"; import { IBlockManager, IRenderable, IRenderOpts, PageHostedApiBlockWrapper } from "./base"; import { Geometry } from "./geometry"; /** * Generic base class for a QueryResult, as the parent Page is not defined here. * * If you're consuming this library, you probably just want to use `document.ts/QueryResult`. */ export declare class QueryResultGeneric extends PageHostedApiBlockWrapper implements IRenderable { _geometry?: Geometry>; _parentQuery: QueryInstanceGeneric; constructor(block: ApiQueryResultBlock, parentQuery: QueryInstanceGeneric); get confidence(): number; /** * geometry may be undefined for interpreted (rather than literal) query answers. */ get geometry(): undefined | Geometry>; get parentQuery(): QueryInstanceGeneric; get text(): string; /** * The semantic `html()` representation of a query result is just its (HTML-escaped) text */ html(opts?: IRenderOpts): string; str(): string; } /** * Generic base class for a QueryInstance, as the parent Page is not defined here. * * If you're consuming this library, you probably just want to use `document.ts/QueryResult`. */ export declare class QueryInstanceGeneric extends PageHostedApiBlockWrapper implements IRenderable { constructor(block: ApiQueryBlock, parentPage: TPage); /** * Alias of the query as configured in the original AnalyzeDocument request (if one was set) */ get alias(): string | undefined; get nResults(): number; /** * Text of the input query (question) */ get text(): string; /** * Retrieve the top result by confidence score, if any are available. */ get topResult(): QueryResultGeneric | undefined; /** * List this query instance's results, in raw Amazon Textract response order * * Any invalid relationship block IDs will be skipped from the list (no logs) * * TODO: Refactor to use list/iterRelatedItemsByRelType when ready for breaking change * * This refactor will require changing the handling of invalid JSONs (i.e. missing blocks) for * more consistency between different modules of TRP.js. */ protected _listResults(): QueryResultGeneric[]; /** * List this query instance's results, sorted from the most to least confident. */ listResultsByConfidence(): QueryResultGeneric[]; /** * The HTML for a `QueryInstance` uses a `
` of class "query" * * The question itself is presented within `

` tags, and then a bulleted list of the answers / * results in order of descending confidence. */ html(opts?: IRenderOpts): string; /** * Generate a human-readable representation of this query instance */ str(): string; } /** * Configuration options for listing/filtering Amazon Textract Queries */ export interface IFilterQueryOpts { /** * Set `true` to skip queries with no answers (by default, they're included) */ skipUnanswered?: boolean; } /** * Generic base class for a collection of query instances, as parent Page is not defined here. * * If you're consuming this library, you probably just want to use `document.ts/QueryInstanceCollection`. */ export declare class QueryInstanceCollectionGeneric implements IRenderable { _queries: QueryInstanceGeneric[]; _parentPage: TPage; constructor(queryBlocks: ApiQueryBlock[], parentPage: TPage); get nQueries(): number; get parentPage(): TPage; /** * Return the text content of all queries and their results, ordered by confidence score */ get text(): string; /** * Find a query by exact match of query alias, if one exists * @param alias Alias provided for the query (in the Amazon Textract AnalyzeDocument request) * @returns A matching query instance, or undefined if none is found */ getQueryByAlias(alias: string): QueryInstanceGeneric | undefined; /** * Find a query by exact match of query text (question), if one exists * @param question Text of the original query (in the Amazon Textract AnalyzeDocument request) * @returns A matching query instance, or undefined if none is found */ getQueryByQuestion(question: string): QueryInstanceGeneric | undefined; /** * The `html()` for a QueryCollection lists all queries within a `

` of class "queries" */ html(opts?: IRenderOpts): string; /** * Iterate through the Queries in the collection. * @param opts Filtering options to control which queries are included * @example * for (const query of q.iterQueries()) { * console.log(query.text); * } * @example * const queries = [...q.iterQueries()]; */ iterQueries(opts?: IFilterQueryOpts): Iterable>; /** * List the Queries in the collection. * @param opts Filtering options to control which queries are included */ listQueries(opts?: IFilterQueryOpts): QueryInstanceGeneric[]; /** * List the Queries in the collection with alias text containing (case-insensitive) `alias` * @param alias The text to search for in query aliases * @param opts Filtering options to control which queries are included in the search */ searchQueriesByAlias(alias: string, opts?: IFilterQueryOpts): QueryInstanceGeneric[]; /** * List the Queries in the collection with question text containing (case-insensitive) `question` * @param question The text to search for in query text * @param opts Filtering options to control which queries are included in the search */ searchQueriesByQuestion(question: string, opts?: IFilterQueryOpts): QueryInstanceGeneric[]; /** * Generate a human-readable representation of the query collection */ str(): string; }