Cloud Document AI API v1 - Package cloud.google.com/go/documentai/apiv1 (v1.4.0)

Package documentai is an auto-generated package for the Cloud Document AI API.

Service to parse structured information from unstructured or semi-structured documents using state-of-the-art Google AI such as natural language, computer vision, translation, and AutoML.

Example usage

To get started with this package, create a client.

 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
 c 
 , 
  
 err 
  
 := 
  
 documentai 
 . 
 NewDocumentProcessorClient 
 ( 
 ctx 
 ) 
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
 } 
 defer 
  
 c 
 . 
 Close 
 () 

The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.

Using the Client

The following is an example of making an API call with the newly created client.

 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
 c 
 , 
  
 err 
  
 := 
  
 documentai 
 . 
 NewDocumentProcessorClient 
 ( 
 ctx 
 ) 
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
 } 
 defer 
  
 c 
 . 
 Close 
 () 
 req 
  
 := 
  
& documentaipb 
 . 
 ProcessRequest 
 { 
  
 // TODO: Fill request struct fields. 
  
 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/documentai/v1#ProcessRequest. 
 } 
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 ProcessDocument 
 ( 
 ctx 
 , 
  
 req 
 ) 
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
 } 
 // TODO: Use resp. 
 _ 
  
 = 
  
 resp 

Use of Context

The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.

To close the open connection, use the Close() method.

For information about setting deadlines, reusing contexts, and more please visit https://pkg.go.dev/cloud.google.com/go .

Functions

func DefaultAuthScopes

  func 
  
 DefaultAuthScopes 
 () 
  
 [] 
  string 
 
 

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

BatchProcessDocumentsOperation

  type 
  
 BatchProcessDocumentsOperation 
  
 struct 
  
 { 
  
 // contains filtered or unexported fields 
 } 
 

BatchProcessDocumentsOperation manages a long-running operation from BatchProcessDocuments.

func (*BatchProcessDocumentsOperation) Done

Done reports whether the long-running operation has completed.

Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.

func (*BatchProcessDocumentsOperation) Name

Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.

func (*BatchProcessDocumentsOperation) Poll

Poll fetches the latest state of the long-running operation.

Poll also fetches the latest metadata, which can be retrieved by Metadata.

If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.

func (*BatchProcessDocumentsOperation) Wait

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

DocumentProcessorCallOptions

  type 
  
 DocumentProcessorCallOptions 
  
 struct 
  
 { 
  
 ProcessDocument 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 BatchProcessDocuments 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ReviewDocument 
  
 [] 
  gax 
 
 . 
  CallOption 
 
 } 
 

DocumentProcessorCallOptions contains the retry settings for each method of DocumentProcessorClient.

DocumentProcessorClient

  type 
  
 DocumentProcessorClient 
  
 struct 
  
 { 
  
 // The call options for this service. 
  
 CallOptions 
  
 * 
  DocumentProcessorCallOptions 
 
  
 // LROClient is used internally to handle long-running operations. 
  
 // It is exposed so that its CallOptions can be modified if required. 
  
 // Users should not Close this client. 
  
 LROClient 
  
 * 
  lroauto 
 
 . 
  OperationsClient 
 
  
 // contains filtered or unexported fields 
 } 
 

DocumentProcessorClient is a client for interacting with Cloud Document AI API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

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.

func NewDocumentProcessorClient

  func 
  
 NewDocumentProcessorClient 
 ( 
 ctx 
  
  context 
 
 . 
  Context 
 
 , 
  
 opts 
  
 ... 
 option 
 . 
 ClientOption 
 ) 
  
 ( 
 * 
  DocumentProcessorClient 
 
 , 
  
  error 
 
 ) 
 

NewDocumentProcessorClient creates a new document processor service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.

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.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 documentai 
  
 "cloud.google.com/go/documentai/apiv1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 documentai 
 . 
  NewDocumentProcessorClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 defer 
  
 c 
 . 
  Close 
 
 () 
  
 // TODO: Use client. 
  
 _ 
  
 = 
  
 c 
 } 
 

func (*DocumentProcessorClient) BatchProcessDocuments

BatchProcessDocuments lRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 documentai 
  
 "cloud.google.com/go/documentai/apiv1" 
  
 documentaipb 
  
 "google.golang.org/genproto/googleapis/cloud/documentai/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 documentai 
 . 
  NewDocumentProcessorClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 defer 
  
 c 
 . 
  Close 
 
 () 
  
 req 
  
 := 
  
& documentaipb 
 . 
  BatchProcessRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/documentai/v1#BatchProcessRequest. 
  
 } 
  
 op 
 , 
  
 err 
  
 := 
  
 c 
 . 
 BatchProcessDocuments 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 op 
 . 
 Wait 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*DocumentProcessorClient) BatchProcessDocumentsOperation

  func 
  
 ( 
 c 
  
 * 
  DocumentProcessorClient 
 
 ) 
  
 BatchProcessDocumentsOperation 
 ( 
 name 
  
  string 
 
 ) 
  
 * 
  BatchProcessDocumentsOperation 
 
 

BatchProcessDocumentsOperation returns a new BatchProcessDocumentsOperation from a given name. The name must be that of a previously created BatchProcessDocumentsOperation, possibly from a different process.

func (*DocumentProcessorClient) Close

Close closes the connection to the API service. The user should invoke this when the client is no longer required.

func (*DocumentProcessorClient) Connection

  func 
  
 ( 
 c 
  
 * 
  DocumentProcessorClient 
 
 ) 
  
 Connection 
 () 
  
 * 
 grpc 
 . 
 ClientConn 
 

Connection returns a connection to the API service.

Deprecated.

func (*DocumentProcessorClient) ProcessDocument

ProcessDocument processes a single document.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 documentai 
  
 "cloud.google.com/go/documentai/apiv1" 
  
 documentaipb 
  
 "google.golang.org/genproto/googleapis/cloud/documentai/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 documentai 
 . 
  NewDocumentProcessorClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 defer 
  
 c 
 . 
  Close 
 
 () 
  
 req 
  
 := 
  
& documentaipb 
 . 
  ProcessRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/documentai/v1#ProcessRequest. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 ProcessDocument 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*DocumentProcessorClient) ReviewDocument

ReviewDocument send a document for Human Review. The input document should be processed by the specified processor.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 documentai 
  
 "cloud.google.com/go/documentai/apiv1" 
  
 documentaipb 
  
 "google.golang.org/genproto/googleapis/cloud/documentai/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 documentai 
 . 
  NewDocumentProcessorClient 
 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 defer 
  
 c 
 . 
  Close 
 
 () 
  
 req 
  
 := 
  
& documentaipb 
 . 
  ReviewDocumentRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/documentai/v1#ReviewDocumentRequest. 
  
 } 
  
 op 
 , 
  
 err 
  
 := 
  
 c 
 . 
 ReviewDocument 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 op 
 . 
 Wait 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*DocumentProcessorClient) ReviewDocumentOperation

  func 
  
 ( 
 c 
  
 * 
  DocumentProcessorClient 
 
 ) 
  
 ReviewDocumentOperation 
 ( 
 name 
  
  string 
 
 ) 
  
 * 
  ReviewDocumentOperation 
 
 

ReviewDocumentOperation returns a new ReviewDocumentOperation from a given name. The name must be that of a previously created ReviewDocumentOperation, possibly from a different process.

ReviewDocumentOperation

  type 
  
 ReviewDocumentOperation 
  
 struct 
  
 { 
  
 // contains filtered or unexported fields 
 } 
 

ReviewDocumentOperation manages a long-running operation from ReviewDocument.

func (*ReviewDocumentOperation) Done

  func 
  
 ( 
 op 
  
 * 
  ReviewDocumentOperation 
 
 ) 
  
 Done 
 () 
  
  bool 
 
 

Done reports whether the long-running operation has completed.

Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.

func (*ReviewDocumentOperation) Name

Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.

func (*ReviewDocumentOperation) Poll

Poll fetches the latest state of the long-running operation.

Poll also fetches the latest metadata, which can be retrieved by Metadata.

If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.

func (*ReviewDocumentOperation) Wait

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

Create a Mobile Website
View Site in Mobile | Classic
Share by: