Skip to content

Commit

Permalink
feat(client-textract): This release adds support for classifying and …
Browse files Browse the repository at this point in the history
…splitting lending documents by type, and extracting information by using the Analyze Lending APIs. This release also includes support for summarized information of the processed lending document package, in addition to per document results.
  • Loading branch information
awstools committed Nov 28, 2022
1 parent 0ac256b commit be0312b
Show file tree
Hide file tree
Showing 11 changed files with 2,535 additions and 154 deletions.
162 changes: 162 additions & 0 deletions clients/client-textract/src/Textract.ts
Expand Up @@ -32,6 +32,16 @@ import {
GetExpenseAnalysisCommandInput,
GetExpenseAnalysisCommandOutput,
} from "./commands/GetExpenseAnalysisCommand";
import {
GetLendingAnalysisCommand,
GetLendingAnalysisCommandInput,
GetLendingAnalysisCommandOutput,
} from "./commands/GetLendingAnalysisCommand";
import {
GetLendingAnalysisSummaryCommand,
GetLendingAnalysisSummaryCommandInput,
GetLendingAnalysisSummaryCommandOutput,
} from "./commands/GetLendingAnalysisSummaryCommand";
import {
StartDocumentAnalysisCommand,
StartDocumentAnalysisCommandInput,
Expand All @@ -47,6 +57,11 @@ import {
StartExpenseAnalysisCommandInput,
StartExpenseAnalysisCommandOutput,
} from "./commands/StartExpenseAnalysisCommand";
import {
StartLendingAnalysisCommand,
StartLendingAnalysisCommandInput,
StartLendingAnalysisCommandOutput,
} from "./commands/StartLendingAnalysisCommand";
import { TextractClient } from "./TextractClient";

/**
Expand Down Expand Up @@ -456,6 +471,91 @@ export class Textract extends TextractClient {
}
}

/**
* <p>Gets the results for an Amazon Textract asynchronous operation that analyzes text in a
* lending document. </p>
* <p>You start asynchronous text analysis by calling <code>StartLendingAnalysis</code>,
* which returns a job identifier (<code>JobId</code>). When the text analysis operation
* finishes, Amazon Textract publishes a completion status to the Amazon Simple
* Notification Service (Amazon SNS) topic that's registered in the initial call to
* <code>StartLendingAnalysis</code>. </p>
* <p>To get the results of the text analysis operation, first check that the status value
* published to the Amazon SNS topic is SUCCEEDED. If so, call GetLendingAnalysis, and pass
* the job identifier (<code>JobId</code>) from the initial call to
* <code>StartLendingAnalysis</code>.</p>
*/
public getLendingAnalysis(
args: GetLendingAnalysisCommandInput,
options?: __HttpHandlerOptions
): Promise<GetLendingAnalysisCommandOutput>;
public getLendingAnalysis(
args: GetLendingAnalysisCommandInput,
cb: (err: any, data?: GetLendingAnalysisCommandOutput) => void
): void;
public getLendingAnalysis(
args: GetLendingAnalysisCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: GetLendingAnalysisCommandOutput) => void
): void;
public getLendingAnalysis(
args: GetLendingAnalysisCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: GetLendingAnalysisCommandOutput) => void),
cb?: (err: any, data?: GetLendingAnalysisCommandOutput) => void
): Promise<GetLendingAnalysisCommandOutput> | void {
const command = new GetLendingAnalysisCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Gets summarized results for the <code>StartLendingAnalysis</code> operation, which analyzes
* text in a lending document. The returned summary consists of information about documents grouped
* together by a common document type. Information like detected signatures, page numbers, and split
* documents is returned with respect to the type of grouped document. </p>
* <p>You start asynchronous text analysis by calling <code>StartLendingAnalysis</code>, which
* returns a job identifier (<code>JobId</code>). When the text analysis operation finishes, Amazon
* Textract publishes a completion status to the Amazon Simple Notification Service (Amazon SNS)
* topic that's registered in the initial call to <code>StartLendingAnalysis</code>. </p>
* <p>To get the results of the text analysis operation, first check that the status value
* published to the Amazon SNS topic is SUCCEEDED. If so, call
* <code>GetLendingAnalysisSummary</code>, and pass the job identifier (<code>JobId</code>) from
* the initial call to <code>StartLendingAnalysis</code>.</p>
*/
public getLendingAnalysisSummary(
args: GetLendingAnalysisSummaryCommandInput,
options?: __HttpHandlerOptions
): Promise<GetLendingAnalysisSummaryCommandOutput>;
public getLendingAnalysisSummary(
args: GetLendingAnalysisSummaryCommandInput,
cb: (err: any, data?: GetLendingAnalysisSummaryCommandOutput) => void
): void;
public getLendingAnalysisSummary(
args: GetLendingAnalysisSummaryCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: GetLendingAnalysisSummaryCommandOutput) => void
): void;
public getLendingAnalysisSummary(
args: GetLendingAnalysisSummaryCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: GetLendingAnalysisSummaryCommandOutput) => void),
cb?: (err: any, data?: GetLendingAnalysisSummaryCommandOutput) => void
): Promise<GetLendingAnalysisSummaryCommandOutput> | void {
const command = new GetLendingAnalysisSummaryCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Starts the asynchronous analysis of an input document for relationships between detected
* items such as key-value pairs, tables, and selection elements.</p>
Expand Down Expand Up @@ -599,4 +699,66 @@ export class Textract extends TextractClient {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Starts the classification and analysis of an input document.
* <code>StartLendingAnalysis</code> initiates the classification and analysis of a packet of
* lending documents. <code>StartLendingAnalysis</code> operates on a document file located in an
* Amazon S3 bucket.</p>
* <p>
* <code>StartLendingAnalysis</code> can analyze text in documents that are in one of the
* following formats: JPEG, PNG, TIFF, PDF. Use <code>DocumentLocation</code> to specify the bucket
* name and the file name of the document. </p>
* <p>
* <code>StartLendingAnalysis</code> returns a job identifier (<code>JobId</code>) that you use
* to get the results of the operation. When the text analysis is finished, Amazon Textract
* publishes a completion status to the Amazon Simple Notification Service (Amazon SNS) topic that
* you specify in <code>NotificationChannel</code>. To get the results of the text analysis
* operation, first check that the status value published to the Amazon SNS topic is SUCCEEDED. If
* the status is SUCCEEDED you can call either <code>GetLendingAnalysis</code> or
* <code>GetLendingAnalysisSummary</code> and provide the <code>JobId</code> to obtain the results
* of the analysis.</p>
* <p>If using <code>OutputConfig</code> to specify an Amazon S3 bucket, the output will be contained
* within the specified prefix in a directory labeled with the job-id. In the directory there are 3
* sub-directories: </p>
* <ul>
* <li>
* <p>detailedResponse (contains the GetLendingAnalysis response)</p>
* </li>
* <li>
* <p>summaryResponse (for the GetLendingAnalysisSummary response)</p>
* </li>
* <li>
* <p>splitDocuments (documents split across logical boundaries)</p>
* </li>
* </ul>
*/
public startLendingAnalysis(
args: StartLendingAnalysisCommandInput,
options?: __HttpHandlerOptions
): Promise<StartLendingAnalysisCommandOutput>;
public startLendingAnalysis(
args: StartLendingAnalysisCommandInput,
cb: (err: any, data?: StartLendingAnalysisCommandOutput) => void
): void;
public startLendingAnalysis(
args: StartLendingAnalysisCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: StartLendingAnalysisCommandOutput) => void
): void;
public startLendingAnalysis(
args: StartLendingAnalysisCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: StartLendingAnalysisCommandOutput) => void),
cb?: (err: any, data?: StartLendingAnalysisCommandOutput) => void
): Promise<StartLendingAnalysisCommandOutput> | void {
const command = new StartLendingAnalysisCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}
}
19 changes: 17 additions & 2 deletions clients/client-textract/src/TextractClient.ts
Expand Up @@ -60,6 +60,11 @@ import {
GetDocumentTextDetectionCommandOutput,
} from "./commands/GetDocumentTextDetectionCommand";
import { GetExpenseAnalysisCommandInput, GetExpenseAnalysisCommandOutput } from "./commands/GetExpenseAnalysisCommand";
import { GetLendingAnalysisCommandInput, GetLendingAnalysisCommandOutput } from "./commands/GetLendingAnalysisCommand";
import {
GetLendingAnalysisSummaryCommandInput,
GetLendingAnalysisSummaryCommandOutput,
} from "./commands/GetLendingAnalysisSummaryCommand";
import {
StartDocumentAnalysisCommandInput,
StartDocumentAnalysisCommandOutput,
Expand All @@ -72,6 +77,10 @@ import {
StartExpenseAnalysisCommandInput,
StartExpenseAnalysisCommandOutput,
} from "./commands/StartExpenseAnalysisCommand";
import {
StartLendingAnalysisCommandInput,
StartLendingAnalysisCommandOutput,
} from "./commands/StartLendingAnalysisCommand";
import {
ClientInputEndpointParameters,
ClientResolvedEndpointParameters,
Expand All @@ -88,9 +97,12 @@ export type ServiceInputTypes =
| GetDocumentAnalysisCommandInput
| GetDocumentTextDetectionCommandInput
| GetExpenseAnalysisCommandInput
| GetLendingAnalysisCommandInput
| GetLendingAnalysisSummaryCommandInput
| StartDocumentAnalysisCommandInput
| StartDocumentTextDetectionCommandInput
| StartExpenseAnalysisCommandInput;
| StartExpenseAnalysisCommandInput
| StartLendingAnalysisCommandInput;

export type ServiceOutputTypes =
| AnalyzeDocumentCommandOutput
Expand All @@ -100,9 +112,12 @@ export type ServiceOutputTypes =
| GetDocumentAnalysisCommandOutput
| GetDocumentTextDetectionCommandOutput
| GetExpenseAnalysisCommandOutput
| GetLendingAnalysisCommandOutput
| GetLendingAnalysisSummaryCommandOutput
| StartDocumentAnalysisCommandOutput
| StartDocumentTextDetectionCommandOutput
| StartExpenseAnalysisCommandOutput;
| StartExpenseAnalysisCommandOutput
| StartLendingAnalysisCommandOutput;

export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__HttpHandlerOptions>> {
/**
Expand Down
124 changes: 124 additions & 0 deletions clients/client-textract/src/commands/GetLendingAnalysisCommand.ts
@@ -0,0 +1,124 @@
// smithy-typescript generated code
import { EndpointParameterInstructions, getEndpointPlugin } from "@aws-sdk/middleware-endpoint";
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

import {
GetLendingAnalysisRequest,
GetLendingAnalysisRequestFilterSensitiveLog,
GetLendingAnalysisResponse,
GetLendingAnalysisResponseFilterSensitiveLog,
} from "../models/models_0";
import {
deserializeAws_json1_1GetLendingAnalysisCommand,
serializeAws_json1_1GetLendingAnalysisCommand,
} from "../protocols/Aws_json1_1";
import { ServiceInputTypes, ServiceOutputTypes, TextractClientResolvedConfig } from "../TextractClient";

export interface GetLendingAnalysisCommandInput extends GetLendingAnalysisRequest {}
export interface GetLendingAnalysisCommandOutput extends GetLendingAnalysisResponse, __MetadataBearer {}

/**
* <p>Gets the results for an Amazon Textract asynchronous operation that analyzes text in a
* lending document. </p>
* <p>You start asynchronous text analysis by calling <code>StartLendingAnalysis</code>,
* which returns a job identifier (<code>JobId</code>). When the text analysis operation
* finishes, Amazon Textract publishes a completion status to the Amazon Simple
* Notification Service (Amazon SNS) topic that's registered in the initial call to
* <code>StartLendingAnalysis</code>. </p>
* <p>To get the results of the text analysis operation, first check that the status value
* published to the Amazon SNS topic is SUCCEEDED. If so, call GetLendingAnalysis, and pass
* the job identifier (<code>JobId</code>) from the initial call to
* <code>StartLendingAnalysis</code>.</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
* import { TextractClient, GetLendingAnalysisCommand } from "@aws-sdk/client-textract"; // ES Modules import
* // const { TextractClient, GetLendingAnalysisCommand } = require("@aws-sdk/client-textract"); // CommonJS import
* const client = new TextractClient(config);
* const command = new GetLendingAnalysisCommand(input);
* const response = await client.send(command);
* ```
*
* @see {@link GetLendingAnalysisCommandInput} for command's `input` shape.
* @see {@link GetLendingAnalysisCommandOutput} for command's `response` shape.
* @see {@link TextractClientResolvedConfig | config} for TextractClient's `config` shape.
*
*/
export class GetLendingAnalysisCommand extends $Command<
GetLendingAnalysisCommandInput,
GetLendingAnalysisCommandOutput,
TextractClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties

public static getEndpointParameterInstructions(): EndpointParameterInstructions {
return {
UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
Endpoint: { type: "builtInParams", name: "endpoint" },
Region: { type: "builtInParams", name: "region" },
UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
};
}

constructor(readonly input: GetLendingAnalysisCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}

/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: TextractClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetLendingAnalysisCommandInput, GetLendingAnalysisCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.middlewareStack.use(
getEndpointPlugin(configuration, GetLendingAnalysisCommand.getEndpointParameterInstructions())
);

const stack = clientStack.concat(this.middlewareStack);

const { logger } = configuration;
const clientName = "TextractClient";
const commandName = "GetLendingAnalysisCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: GetLendingAnalysisRequestFilterSensitiveLog,
outputFilterSensitiveLog: GetLendingAnalysisResponseFilterSensitiveLog,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}

private serialize(input: GetLendingAnalysisCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return serializeAws_json1_1GetLendingAnalysisCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetLendingAnalysisCommandOutput> {
return deserializeAws_json1_1GetLendingAnalysisCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}

0 comments on commit be0312b

Please sign in to comment.