- 2.58.0 (latest)
- 2.57.0
- 2.56.0
- 2.55.0
- 2.53.0
- 2.52.0
- 2.51.0
- 2.50.0
- 2.49.0
- 2.48.0
- 2.47.0
- 2.46.0
- 2.45.0
- 2.44.0
- 2.43.0
- 2.41.0
- 2.40.0
- 2.39.0
- 2.38.0
- 2.37.0
- 2.36.0
- 2.35.0
- 2.34.0
- 2.33.0
- 2.32.0
- 2.31.0
- 2.28.0
- 2.27.0
- 2.26.0
- 2.25.0
- 2.24.0
- 2.23.0
- 2.22.0
- 2.21.0
- 2.20.0
- 2.19.0
- 2.18.0
- 2.17.0
- 2.16.0
- 2.15.0
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.5
- 2.6.2
- 2.5.1
- 2.4.3
- 2.3.1
- 2.2.1
- 2.1.9
public class DocumentProcessorServiceClient implements BackgroundResource
Service Description: Service to call Cloud DocumentAI to process documents according to the processor's definition. Processors are built using state-of-the-art Google AI such as natural language, computer vision, and translation to extract structured information from unstructured or semi-structured documents.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
ProcessResponse response = documentProcessorServiceClient.processDocument(name);
}
Note: close() needs to be called on the DocumentProcessorServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of DocumentProcessorServiceSettings to create(). For example:
To customize credentials:
DocumentProcessorServiceSettings documentProcessorServiceSettings =
DocumentProcessorServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create(documentProcessorServiceSettings);
To customize the endpoint:
DocumentProcessorServiceSettings documentProcessorServiceSettings =
DocumentProcessorServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create(documentProcessorServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Implements
BackgroundResourceStatic Methods
create()
public static final DocumentProcessorServiceClient create()
Constructs an instance of DocumentProcessorServiceClient with default settings.
Type | Description |
DocumentProcessorServiceClient |
Type | Description |
IOException |
create(DocumentProcessorServiceSettings settings)
public static final DocumentProcessorServiceClient create(DocumentProcessorServiceSettings settings)
Constructs an instance of DocumentProcessorServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
Name | Description |
settings | DocumentProcessorServiceSettings |
Type | Description |
DocumentProcessorServiceClient |
Type | Description |
IOException |
create(DocumentProcessorServiceStub stub)
public static final DocumentProcessorServiceClient create(DocumentProcessorServiceStub stub)
Constructs an instance of DocumentProcessorServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(DocumentProcessorServiceSettings).
Name | Description |
stub | DocumentProcessorServiceStub |
Type | Description |
DocumentProcessorServiceClient |
Constructors
DocumentProcessorServiceClient(DocumentProcessorServiceSettings settings)
protected DocumentProcessorServiceClient(DocumentProcessorServiceSettings settings)
Constructs an instance of DocumentProcessorServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
Name | Description |
settings | DocumentProcessorServiceSettings |
DocumentProcessorServiceClient(DocumentProcessorServiceStub stub)
protected DocumentProcessorServiceClient(DocumentProcessorServiceStub stub)
Name | Description |
stub | DocumentProcessorServiceStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)
Name | Description |
duration | long |
unit | TimeUnit |
Type | Description |
boolean |
Type | Description |
InterruptedException |
batchProcessDocumentsAsync(BatchProcessRequest request)
public final OperationFuture<BatchProcessResponse,BatchProcessMetadata> batchProcessDocumentsAsync(BatchProcessRequest request)
LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
BatchProcessRequest request =
BatchProcessRequest.newBuilder()
.setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setInputDocuments(BatchDocumentsInputConfig.newBuilder().build())
.setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build())
.setSkipHumanReview(true)
.build();
BatchProcessResponse response =
documentProcessorServiceClient.batchProcessDocumentsAsync(request).get();
}
Name | Description |
request | BatchProcessRequest The request object containing all of the parameters for the API call. |
Type | Description |
OperationFuture<BatchProcessResponse,BatchProcessMetadata> |
batchProcessDocumentsAsync(ProcessorName name)
public final OperationFuture<BatchProcessResponse,BatchProcessMetadata> batchProcessDocumentsAsync(ProcessorName name)
LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
BatchProcessResponse response =
documentProcessorServiceClient.batchProcessDocumentsAsync(name).get();
}
Name | Description |
name | ProcessorName Required. The processor resource name. |
Type | Description |
OperationFuture<BatchProcessResponse,BatchProcessMetadata> |
batchProcessDocumentsAsync(String name)
public final OperationFuture<BatchProcessResponse,BatchProcessMetadata> batchProcessDocumentsAsync(String name)
LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
String name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString();
BatchProcessResponse response =
documentProcessorServiceClient.batchProcessDocumentsAsync(name).get();
}
Name | Description |
name | String Required. The processor resource name. |
Type | Description |
OperationFuture<BatchProcessResponse,BatchProcessMetadata> |
batchProcessDocumentsCallable()
public final UnaryCallable<BatchProcessRequest,Operation> batchProcessDocumentsCallable()
LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
BatchProcessRequest request =
BatchProcessRequest.newBuilder()
.setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setInputDocuments(BatchDocumentsInputConfig.newBuilder().build())
.setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build())
.setSkipHumanReview(true)
.build();
ApiFuture<Operation> future =
documentProcessorServiceClient.batchProcessDocumentsCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
Type | Description |
UnaryCallable<BatchProcessRequest,Operation> |
batchProcessDocumentsOperationCallable()
public final OperationCallable<BatchProcessRequest,BatchProcessResponse,BatchProcessMetadata> batchProcessDocumentsOperationCallable()
LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
BatchProcessRequest request =
BatchProcessRequest.newBuilder()
.setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setInputDocuments(BatchDocumentsInputConfig.newBuilder().build())
.setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build())
.setSkipHumanReview(true)
.build();
OperationFuture<BatchProcessResponse, BatchProcessMetadata> future =
documentProcessorServiceClient
.batchProcessDocumentsOperationCallable()
.futureCall(request);
// Do something.
BatchProcessResponse response = future.get();
}
Type | Description |
OperationCallable<BatchProcessRequest,BatchProcessResponse,BatchProcessMetadata> |
close()
public final void close()
getOperationsClient()
public final OperationsClient getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.
Type | Description |
OperationsClient |
getSettings()
public final DocumentProcessorServiceSettings getSettings()
Type | Description |
DocumentProcessorServiceSettings |
getStub()
public DocumentProcessorServiceStub getStub()
Type | Description |
DocumentProcessorServiceStub |
isShutdown()
public boolean isShutdown()
Type | Description |
boolean |
isTerminated()
public boolean isTerminated()
Type | Description |
boolean |
processDocument(ProcessRequest request)
public final ProcessResponse processDocument(ProcessRequest request)
Processes a single document.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ProcessRequest request =
ProcessRequest.newBuilder()
.setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setSkipHumanReview(true)
.build();
ProcessResponse response = documentProcessorServiceClient.processDocument(request);
}
Name | Description |
request | ProcessRequest The request object containing all of the parameters for the API call. |
Type | Description |
ProcessResponse |
processDocument(ProcessorName name)
public final ProcessResponse processDocument(ProcessorName name)
Processes a single document.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ProcessorName name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
ProcessResponse response = documentProcessorServiceClient.processDocument(name);
}
Name | Description |
name | ProcessorName Required. The processor resource name. |
Type | Description |
ProcessResponse |
processDocument(String name)
public final ProcessResponse processDocument(String name)
Processes a single document.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
String name = ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString();
ProcessResponse response = documentProcessorServiceClient.processDocument(name);
}
Name | Description |
name | String Required. The processor resource name. |
Type | Description |
ProcessResponse |
processDocumentCallable()
public final UnaryCallable<ProcessRequest,ProcessResponse> processDocumentCallable()
Processes a single document.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ProcessRequest request =
ProcessRequest.newBuilder()
.setName(ProcessorName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setSkipHumanReview(true)
.build();
ApiFuture<ProcessResponse> future =
documentProcessorServiceClient.processDocumentCallable().futureCall(request);
// Do something.
ProcessResponse response = future.get();
}
Type | Description |
UnaryCallable<ProcessRequest,ProcessResponse> |
reviewDocumentAsync(HumanReviewConfigName humanReviewConfig)
public final OperationFuture<ReviewDocumentResponse,ReviewDocumentOperationMetadata> reviewDocumentAsync(HumanReviewConfigName humanReviewConfig)
Send a document for Human Review. The input document should be processed by the specified processor.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
HumanReviewConfigName humanReviewConfig =
HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]");
ReviewDocumentResponse response =
documentProcessorServiceClient.reviewDocumentAsync(humanReviewConfig).get();
}
Name | Description |
humanReviewConfig | HumanReviewConfigName Required. The resource name of the HumanReviewConfig that the document will be reviewed with. |
Type | Description |
OperationFuture<ReviewDocumentResponse,ReviewDocumentOperationMetadata> |
reviewDocumentAsync(ReviewDocumentRequest request)
public final OperationFuture<ReviewDocumentResponse,ReviewDocumentOperationMetadata> reviewDocumentAsync(ReviewDocumentRequest request)
Send a document for Human Review. The input document should be processed by the specified processor.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ReviewDocumentRequest request =
ReviewDocumentRequest.newBuilder()
.setHumanReviewConfig(
HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setEnableSchemaValidation(true)
.build();
ReviewDocumentResponse response =
documentProcessorServiceClient.reviewDocumentAsync(request).get();
}
Name | Description |
request | ReviewDocumentRequest The request object containing all of the parameters for the API call. |
Type | Description |
OperationFuture<ReviewDocumentResponse,ReviewDocumentOperationMetadata> |
reviewDocumentAsync(String humanReviewConfig)
public final OperationFuture<ReviewDocumentResponse,ReviewDocumentOperationMetadata> reviewDocumentAsync(String humanReviewConfig)
Send a document for Human Review. The input document should be processed by the specified processor.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
String humanReviewConfig =
HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString();
ReviewDocumentResponse response =
documentProcessorServiceClient.reviewDocumentAsync(humanReviewConfig).get();
}
Name | Description |
humanReviewConfig | String Required. The resource name of the HumanReviewConfig that the document will be reviewed with. |
Type | Description |
OperationFuture<ReviewDocumentResponse,ReviewDocumentOperationMetadata> |
reviewDocumentCallable()
public final UnaryCallable<ReviewDocumentRequest,Operation> reviewDocumentCallable()
Send a document for Human Review. The input document should be processed by the specified processor.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ReviewDocumentRequest request =
ReviewDocumentRequest.newBuilder()
.setHumanReviewConfig(
HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setEnableSchemaValidation(true)
.build();
ApiFuture<Operation> future =
documentProcessorServiceClient.reviewDocumentCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
Type | Description |
UnaryCallable<ReviewDocumentRequest,Operation> |
reviewDocumentOperationCallable()
public final OperationCallable<ReviewDocumentRequest,ReviewDocumentResponse,ReviewDocumentOperationMetadata> reviewDocumentOperationCallable()
Send a document for Human Review. The input document should be processed by the specified processor.
Sample code:
try (DocumentProcessorServiceClient documentProcessorServiceClient =
DocumentProcessorServiceClient.create()) {
ReviewDocumentRequest request =
ReviewDocumentRequest.newBuilder()
.setHumanReviewConfig(
HumanReviewConfigName.of("[PROJECT]", "[LOCATION]", "[PROCESSOR]").toString())
.setEnableSchemaValidation(true)
.build();
OperationFuture<ReviewDocumentResponse, ReviewDocumentOperationMetadata> future =
documentProcessorServiceClient.reviewDocumentOperationCallable().futureCall(request);
// Do something.
ReviewDocumentResponse response = future.get();
}
Type | Description |
OperationCallable<ReviewDocumentRequest,ReviewDocumentResponse,ReviewDocumentOperationMetadata> |
shutdown()
public void shutdown()
shutdownNow()
public void shutdownNow()