共用方式為


DocumentModelAdministrationClient Class

  • java.lang.Object
    • com.azure.ai.formrecognizer.documentanalysis.administration.DocumentModelAdministrationClient

public final class DocumentModelAdministrationClient

This class provides an asynchronous client to connect to the Form Recognizer Azure Cognitive Service.

This client provides asynchronous methods to perform:

  1. Build a custom model: Extract data from your specific documents by building custom models using the beginBuildDocumentModel(String blobContainerUrl, DocumentModelBuildMode buildMode) method to provide a container SAS URL to your Azure Storage Blob container.
  2. Composed custom models: Creates a new model from document types of collection of existing models using the beginComposeDocumentModel(List<String> componentModelIds) method.
  3. Copy custom model: Copy a custom Form Recognizer model to a target Form Recognizer resource using the beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target) method.
  4. Custom model management: Get detailed information, delete and list custom models using methods getDocumentModel(String modelId), listDocumentModels() and deleteDocumentModel(String modelId) respectively.
  5. Operations management: Get detailed information and list operations on the Form Recognizer account using methods getOperation(String operationId) and listOperations() respectively.
  6. Polling and Callbacks: It includes mechanisms for polling the service to check the status of an analysis operation or registering callbacks to receive notifications when the analysis is complete.

Note: This client only supports V2022_08_31 and newer. To use an older service version, FormRecognizerClient and FormTrainingClient.

Service clients are the point of interaction for developers to use Azure Form Recognizer. DocumentModelAdministrationClient is the synchronous service client and DocumentModelAdministrationAsyncClient is the asynchronous service client. The examples shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation".

Sample: Construct a DocumentModelAdministrationAsyncClient with DefaultAzureCredential

The following code sample demonstrates the creation of a DocumentModelAdministrationAsyncClient, using the `DefaultAzureCredentialBuilder` to configure it.

DocumentModelAdministrationClient client = new DocumentModelAdministrationClientBuilder()
     .endpoint("{endpoint}")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildClient();

Further, see the code sample below to use AzureKeyCredential for client creation.

DocumentModelAdministrationAsyncClient documentModelAdministrationAsyncClient =
     new DocumentModelAdministrationClientBuilder()
         .credential(new AzureKeyCredential("{key}"))
         .endpoint("{endpoint}")
         .buildAsyncClient();

Method Summary

Modifier and Type Method and Description
SyncPoller<OperationResult,DocumentClassifierDetails> beginBuildDocumentClassifier(Map<String,ClassifierDocumentTypeDetails> documentTypes)

Builds a custom classifier document model.

SyncPoller<OperationResult,DocumentClassifierDetails> beginBuildDocumentClassifier(Map<String,ClassifierDocumentTypeDetails> documentTypes, BuildDocumentClassifierOptions buildDocumentClassifierOptions, Context context)

Builds a custom classifier document model.

SyncPoller<OperationResult,DocumentModelDetails> beginBuildDocumentModel(ContentSource contentSource, DocumentModelBuildMode buildMode)

Builds a custom document analysis model.

SyncPoller<OperationResult,DocumentModelDetails> beginBuildDocumentModel(ContentSource contentSource, DocumentModelBuildMode buildMode, BuildDocumentModelOptions buildDocumentModelOptions, Context context)

Builds a custom document analysis model.

SyncPoller<OperationResult,DocumentModelDetails> beginBuildDocumentModel(String blobContainerUrl, DocumentModelBuildMode buildMode)

Builds a custom document analysis model.

SyncPoller<OperationResult,DocumentModelDetails> beginBuildDocumentModel(String blobContainerUrl, DocumentModelBuildMode buildMode, String prefix, BuildDocumentModelOptions buildDocumentModelOptions, Context context)

Builds a custom document analysis model.

SyncPoller<OperationResult,DocumentModelDetails> beginComposeDocumentModel(List<String> componentModelIds)

Create a composed model from the provided list of existing models in the account.

SyncPoller<OperationResult,DocumentModelDetails> beginComposeDocumentModel(List<String> componentModelIds, ComposeDocumentModelOptions composeDocumentModelOptions, Context context)

Create a composed model from the provided list of existing models in the account.

SyncPoller<OperationResult,DocumentModelDetails> beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target)

Copy a custom model stored in this resource (the source) to the user specified target Form Recognizer resource.

SyncPoller<OperationResult,DocumentModelDetails> beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target, Context context)

Copy a custom model stored in this resource (the source) to the user specified target Form Recognizer resource.

void deleteDocumentClassifier(String classifierId)

Deletes the specified document classifier.

Response<Void> deleteDocumentClassifierWithResponse(String classifierId, Context context)

Deletes the specified document classifier.

void deleteDocumentModel(String modelId)

Deletes the specified custom document analysis model.

Response<Void> deleteDocumentModelWithResponse(String modelId, Context context)

Deletes the specified custom document analysis model.

DocumentModelCopyAuthorization getCopyAuthorization()

Generate authorization for copying a custom model into the target Form Recognizer resource.

Response<DocumentModelCopyAuthorization> getCopyAuthorizationWithResponse(CopyAuthorizationOptions copyAuthorizationOptions, Context context)

Generate authorization for copying a custom model into the target Form Recognizer resource.

DocumentAnalysisClient getDocumentAnalysisClient()

Creates a new DocumentAnalysisClient object.

DocumentClassifierDetails getDocumentClassifier(String classifierId)

Get detailed information for a document classifier by its ID.

Response<DocumentClassifierDetails> getDocumentClassifierWithResponse(String classifierId, Context context)

Get detailed information for a document classifier by its ID.

DocumentModelDetails getDocumentModel(String modelId)

Get detailed information for a specified model ID.

Response<DocumentModelDetails> getDocumentModelWithResponse(String modelId, Context context)

Get detailed information for a specified model ID.

OperationDetails getOperation(String operationId)

Get detailed operation information for the specified ID with Http response.

Response<OperationDetails> getOperationWithResponse(String operationId, Context context)

Get detailed operation information for the specified ID with Http response.

ResourceDetails getResourceDetails()

Get information about the current Form Recognizer resource.

Response<ResourceDetails> getResourceDetailsWithResponse(Context context)

Get information about the current Form recognizer resource with a Http response and a specified Context.

PagedIterable<DocumentClassifierDetails> listDocumentClassifiers()

List information for each document classifier on the Form Recognizer account that were built successfully.

PagedIterable<DocumentClassifierDetails> listDocumentClassifiers(Context context)

List information for each document classifier on the Form Recognizer account that were built successfully with a Http response and a specified Context.

PagedIterable<DocumentModelSummary> listDocumentModels()

List information for each model on the Form Recognizer account that were built successfully.

PagedIterable<DocumentModelSummary> listDocumentModels(Context context)

List information for each model on the Form Recognizer account that were built successfully with a Http response and a specified Context.

PagedIterable<OperationSummary> listOperations()

List information for each model operation on the Form Recognizer account in the past 24 hours.

PagedIterable<OperationSummary> listOperations(Context context)

List information for each operation on the Form Recognizer account in the past 24 hours with an HTTP response and a specified Context.

Methods inherited from java.lang.Object

Method Details

beginBuildDocumentClassifier

public SyncPoller beginBuildDocumentClassifier(Map documentTypes)

Builds a custom classifier document model.

Classifier models can identify multiple documents or multiple instances of a single document. For that, you need at least five documents for each class and two classes of documents.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String blobContainerUrl1040D = "{SAS_URL_of_your_container_in_blob_storage}";
 String blobContainerUrl1040A = "{SAS_URL_of_your_container_in_blob_storage}";
 HashMap<String, ClassifierDocumentTypeDetails> documentTypes = new HashMap<>();
 documentTypes.put("1040-D", new ClassifierDocumentTypeDetails(new BlobContentSource(blobContainerUrl1040D)
 ));
 documentTypes.put("1040-A", new ClassifierDocumentTypeDetails(new BlobContentSource(blobContainerUrl1040A)
 ));

 DocumentClassifierDetails classifierDetails
     = documentModelAdministrationClient.beginBuildDocumentClassifier(documentTypes)
     .getFinalResult();

 System.out.printf("Classifier ID: %s%n", classifierDetails.getClassifierId());
 System.out.printf("Classifier description: %s%n", classifierDetails.getDescription());
 System.out.printf("Classifier created on: %s%n", classifierDetails.getCreatedOn());
 System.out.printf("Classifier expires on: %s%n", classifierDetails.getExpiresOn());
 classifierDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     if (documentTypeDetails.getContentSource() instanceof BlobContentSource) {
         System.out.printf("Blob Source container Url: %s", ((BlobContentSource) documentTypeDetails
             .getContentSource()).getContainerUrl());
     }
 });

Parameters:

documentTypes - List of document types to classify against.

Returns:

A SyncPoller<T,U> that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the built DocumentClassifierDetails.

beginBuildDocumentClassifier

public SyncPoller beginBuildDocumentClassifier(Map documentTypes, BuildDocumentClassifierOptions buildDocumentClassifierOptions, Context context)

Builds a custom classifier document model.

Classifier models can identify multiple documents or multiple instances of a single document. For that, you need at least five documents for each class and two classes of documents.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String blobContainerUrl1040D = "{SAS_URL_of_your_container_in_blob_storage}";
 String blobContainerUrl1040A = "{SAS_URL_of_your_container_in_blob_storage}";
 HashMap<String, ClassifierDocumentTypeDetails> documentTypesDetailsMap = new HashMap<>();
 documentTypesDetailsMap.put("1040-D", new ClassifierDocumentTypeDetails(new BlobContentSource(blobContainerUrl1040D)
 ));
 documentTypesDetailsMap.put("1040-A", new ClassifierDocumentTypeDetails(new BlobContentSource(blobContainerUrl1040A)
 ));

 DocumentClassifierDetails classifierDetails
     = documentModelAdministrationClient.beginBuildDocumentClassifier(documentTypesDetailsMap,
         new BuildDocumentClassifierOptions()
             .setClassifierId("classifierId")
             .setDescription("classifier desc"),
         Context.NONE)
     .getFinalResult();

 System.out.printf("Classifier ID: %s%n", classifierDetails.getClassifierId());
 System.out.printf("Classifier description: %s%n", classifierDetails.getDescription());
 System.out.printf("Classifier created on: %s%n", classifierDetails.getCreatedOn());
 System.out.printf("Classifier expires on: %s%n", classifierDetails.getExpiresOn());
 classifierDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     if (documentTypeDetails.getContentSource() instanceof BlobContentSource) {
         System.out.printf("Blob Source container Url: %s", ((BlobContentSource) documentTypeDetails
             .getContentSource()).getContainerUrl());
     }
 });

Parameters:

documentTypes - List of document types to classify against.
buildDocumentClassifierOptions - The configurable BuildDocumentClassifierOptions to pass when building a custom classifier document model.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A SyncPoller<T,U> that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the built DocumentClassifierDetails.

beginBuildDocumentModel

public SyncPoller beginBuildDocumentModel(ContentSource contentSource, DocumentModelBuildMode buildMode)

Builds a custom document analysis model.

Models are built using documents that are of the following content type - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff', image/bmp. Other type of content is ignored.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String blobContainerUrl = "{SAS-URL-of-your-container-in-blob-storage}";
 String fileList = "";

 DocumentModelDetails documentModelDetails
     = documentModelAdministrationClient.beginBuildDocumentModel(
         new BlobFileListContentSource(blobContainerUrl, fileList),
         DocumentModelBuildMode.TEMPLATE)
     .getFinalResult();

 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

contentSource - training data source to be used for building the model. It can be an Azure Storage blob container's provided along with its respective prefix or Path to a JSONL file within the container specifying the set of documents for training. For more information on setting up a training data set, see: here.
buildMode - the preferred technique for creating models. For faster training of models use TEMPLATE. See here for more information on building mode for custom documents. been cancelled. The completed operation returns the built DocumentModelDetails.

Returns:

A SyncPoller<T,U> that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the built DocumentModelDetails.

beginBuildDocumentModel

public SyncPoller beginBuildDocumentModel(ContentSource contentSource, DocumentModelBuildMode buildMode, BuildDocumentModelOptions buildDocumentModelOptions, Context context)

Builds a custom document analysis model.

Models are built using documents that are of the following content type - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff', image/bmp. Other type of content is ignored.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String blobContainerUrl = "{SAS-URL-of-your-container-in-blob-storage}";
 String fileList = "";
 String modelId = "custom-model-id";
 Map<String, String> attrs = new HashMap<String, String>();
 attrs.put("createdBy", "sample");

 DocumentModelDetails documentModelDetails
     = documentModelAdministrationClient.beginBuildDocumentModel(
         new BlobFileListContentSource(blobContainerUrl, fileList),
         DocumentModelBuildMode.TEMPLATE,
         new BuildDocumentModelOptions()
             .setModelId(modelId)
             .setDescription("model desc")
             .setTags(attrs),
         Context.NONE)
     .getFinalResult();

 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 System.out.printf("Model assigned tags: %s%n", documentModelDetails.getTags());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

contentSource - training data source to be used for building the model. It can be an Azure Storage blob container's provided along with its respective prefix or Path to a JSONL file within the container specifying the set of documents for training. For more information on setting up a training data set, see: here.
buildMode - the preferred technique for creating models. For faster training of models use TEMPLATE. See here for more information on building mode for custom documents.
buildDocumentModelOptions - The configurable BuildDocumentModelOptions to pass when building a custom document analysis model.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A SyncPoller<T,U> that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the built DocumentModelDetails.

beginBuildDocumentModel

public SyncPoller beginBuildDocumentModel(String blobContainerUrl, DocumentModelBuildMode buildMode)

Builds a custom document analysis model.

Models are built using documents that are of the following content type - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff', image/bmp. Other type of content is ignored.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String blobContainerUrl = "{SAS-URL-of-your-container-in-blob-storage}";
 DocumentModelDetails documentModelDetails
     = documentModelAdministrationClient.beginBuildDocumentModel(blobContainerUrl,
         DocumentModelBuildMode.TEMPLATE)
     .getFinalResult();

 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

blobContainerUrl - an Azure Storage blob container's SAS URI. A container URI (without SAS) can be used if the container is public or has a managed identity configured. For more information on setting up a training data set, see: here.
buildMode - the preferred technique for creating models. For faster training of models use TEMPLATE. See here for more information on building mode for custom documents.

Returns:

A SyncPoller<T,U> that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the trained DocumentModelDetails.

beginBuildDocumentModel

public SyncPoller beginBuildDocumentModel(String blobContainerUrl, DocumentModelBuildMode buildMode, String prefix, BuildDocumentModelOptions buildDocumentModelOptions, Context context)

Builds a custom document analysis model.

Models are built using documents that are of the following content type - 'application/pdf', 'image/jpeg', 'image/png', 'image/tiff', image/bmp. Other type of content is ignored.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String blobContainerUrl = "{SAS-URL-of-your-container-in-blob-storage}";
 String modelId = "custom-model-id";
 String prefix = "Invoice";
 Map<String, String> attrs = new HashMap<String, String>();
 attrs.put("createdBy", "sample");

 DocumentModelDetails documentModelDetails
     = documentModelAdministrationClient.beginBuildDocumentModel(blobContainerUrl,
         DocumentModelBuildMode.TEMPLATE,
         prefix,
         new BuildDocumentModelOptions()
             .setModelId(modelId)
             .setDescription("model desc")
             .setTags(attrs),
         Context.NONE)
     .getFinalResult();

 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 System.out.printf("Model assigned tags: %s%n", documentModelDetails.getTags());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

blobContainerUrl - an Azure Storage blob container's SAS URI. A container URI (without SAS) can be used if the container is public or has a managed identity configured. For more information on setting up a training data set, see: here.
buildMode - the preferred technique for creating models. For faster training of models use TEMPLATE. See here for more information on building mode for custom documents.
prefix - case-sensitive prefix blob name prefix to filter documents for training.
buildDocumentModelOptions - The configurable BuildDocumentModelOptions to pass when building a custom document analysis model.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A SyncPoller<T,U> that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the built DocumentModelDetails.

beginComposeDocumentModel

public SyncPoller beginComposeDocumentModel(List componentModelIds)

Create a composed model from the provided list of existing models in the account.

This operations fails if the list consists of an invalid, non-existing model Id or duplicate IDs.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String modelId1 = "{custom-model-id_1}";
 String modelId2 = "{custom-model-id_2}";
 final DocumentModelDetails documentModelDetails
     = documentModelAdministrationClient.beginComposeDocumentModel(Arrays.asList(modelId1, modelId2))
     .getFinalResult();

 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

componentModelIds - The list of models IDs to form the composed model.

Returns:

A SyncPoller<T,U> that polls the create composed model operation until it has completed, has failed, or has been cancelled. The completed operation returns the DocumentModelDetails.

beginComposeDocumentModel

public SyncPoller beginComposeDocumentModel(List componentModelIds, ComposeDocumentModelOptions composeDocumentModelOptions, Context context)

Create a composed model from the provided list of existing models in the account.

This operations fails if the list consists of an invalid, non-existing model Id or duplicate IDs.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String modelId1 = "{custom-model-id_1}";
 String modelId2 = "{custom-model-id_2}";
 String modelId = "my-composed-model";
 Map<String, String> attrs = new HashMap<String, String>();
 attrs.put("createdBy", "sample");

 final DocumentModelDetails documentModelDetails =
     documentModelAdministrationClient.beginComposeDocumentModel(Arrays.asList(modelId1, modelId2),
             new ComposeDocumentModelOptions()
                 .setModelId(modelId)
                 .setDescription("my composed model desc")
                 .setTags(attrs),
             Context.NONE)
         .setPollInterval(Duration.ofSeconds(5))
         .getFinalResult();

 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 System.out.printf("Model assigned tags: %s%n", documentModelDetails.getTags());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

componentModelIds - The list of models IDs to form the composed model.
composeDocumentModelOptions - The configurable ComposeDocumentModelOptions to pass when creating a composed model.
context - Additional context that is passed through the HTTP pipeline during the service call.

Returns:

A SyncPoller<T,U> that polls the create composed model operation until it has completed, has failed, or has been cancelled. The completed operation returns the DocumentModelDetails.

beginCopyDocumentModelTo

public SyncPoller beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target)

Copy a custom model stored in this resource (the source) to the user specified target Form Recognizer resource.

This should be called with the source Form Recognizer resource (with the model that is intended to be copied). The target parameter should be supplied from the target resource's output from getCopyAuthorization() method.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String copyModelId = "copy-model";
 // Get authorization to copy the model to target resource
 DocumentModelCopyAuthorization documentModelCopyAuthorization
     = documentModelAdministrationClient.getCopyAuthorization();
 // Start copy operation from the source client
 DocumentModelDetails documentModelDetails
     = documentModelAdministrationClient.beginCopyDocumentModelTo(copyModelId, documentModelCopyAuthorization)
         .getFinalResult();
 System.out.printf("Copied model has model ID: %s, was created on: %s.%n,",
     documentModelDetails.getModelId(),
     documentModelDetails.getCreatedOn());

Parameters:

sourceModelId - Model identifier of the source model to copy to target resource.
target - the copy authorization to the target Form Recognizer resource. The copy authorization can be generated from the target resource's call to getCopyAuthorization()

Returns:

A SyncPoller<T,U> that polls the copy model operation until it has completed, has failed, or has been cancelled.

beginCopyDocumentModelTo

public SyncPoller beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target, Context context)

Copy a custom model stored in this resource (the source) to the user specified target Form Recognizer resource.

This should be called with the source Form Recognizer resource (with the model that is intended to be copied). The target parameter should be supplied from the target resource's output from getCopyAuthorization() method.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String copyModelId = "copy-model";
 // Get authorization to copy the model to target resource
 DocumentModelCopyAuthorization documentModelCopyAuthorization
     = documentModelAdministrationClient.getCopyAuthorization();
 // Start copy operation from the source client
 DocumentModelDetails documentModelDetails =
     documentModelAdministrationClient.beginCopyDocumentModelTo(copyModelId,
             documentModelCopyAuthorization,
             Context.NONE)
         .getFinalResult();
 System.out.printf("Copied model has model ID: %s, was created on: %s.%n,",
     documentModelDetails.getModelId(),
     documentModelDetails.getCreatedOn());

Parameters:

sourceModelId - Model identifier of the model to copy to target resource.
target - the copy authorization to the target Form Recognizer resource. The copy authorization can be generated from the target resource's call to getCopyAuthorization().
context - Additional context that is passed through the HTTP pipeline during the service call.

Returns:

A SyncPoller<T,U> that polls the copy model operation until it has completed, has failed, or has been cancelled.

deleteDocumentClassifier

public void deleteDocumentClassifier(String classifierId)

Deletes the specified document classifier.

Code sample

String classifierId = "{classifierId}";
 documentModelAdministrationClient.deleteDocumentClassifier(classifierId);
 System.out.printf("Classifier ID: %s is deleted.%n", classifierId);

Parameters:

classifierId - The unique document classifier identifier.

deleteDocumentClassifierWithResponse

public Response deleteDocumentClassifierWithResponse(String classifierId, Context context)

Deletes the specified document classifier.

Code sample

String classifierId = "{classifierId}";
 Response<Void> response
     = documentModelAdministrationClient.deleteDocumentClassifierWithResponse(classifierId, Context.NONE);
 System.out.printf("Response Status Code: %d.", response.getStatusCode());
 System.out.printf("Classifier ID: %s is deleted.%n", classifierId);

Parameters:

classifierId - The unique document classifier identifier.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A Response<T> containing status code and HTTP headers.

deleteDocumentModel

public void deleteDocumentModel(String modelId)

Deletes the specified custom document analysis model.

Code sample

String modelId = "{custom-model-id}";
 documentModelAdministrationClient.deleteDocumentModel(modelId);
 System.out.printf("Model ID: %s is deleted.%n", modelId);

Parameters:

modelId - The unique model identifier.

deleteDocumentModelWithResponse

public Response deleteDocumentModelWithResponse(String modelId, Context context)

Deletes the specified custom document analysis model.

Code sample

String modelId = "{custom-model-id}";
 Response<Void> response
     = documentModelAdministrationClient.deleteDocumentModelWithResponse(modelId, Context.NONE);
 System.out.printf("Response Status Code: %d.", response.getStatusCode());
 System.out.printf("Model ID: %s is deleted.%n", modelId);

Parameters:

modelId - The unique model identifier.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A Response<T> containing status code and HTTP headers.

getCopyAuthorization

public DocumentModelCopyAuthorization getCopyAuthorization()

Generate authorization for copying a custom model into the target Form Recognizer resource.

This should be called by the target resource (where the model will be copied to) and the output can be passed as the target parameter into beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target).

Code sample

DocumentModelCopyAuthorization documentModelCopyAuthorization
     = documentModelAdministrationClient.getCopyAuthorization();
 System.out.printf("Copy Authorization for model id: %s, access token: %s, expiration time: %s, "
         + "target resource ID; %s, target resource region: %s%n",
     documentModelCopyAuthorization.getTargetModelId(),
     documentModelCopyAuthorization.getAccessToken(),
     documentModelCopyAuthorization.getExpiresOn(),
     documentModelCopyAuthorization.getTargetResourceId(),
     documentModelCopyAuthorization.getTargetResourceRegion()
 );

Returns:

getCopyAuthorizationWithResponse

public Response getCopyAuthorizationWithResponse(CopyAuthorizationOptions copyAuthorizationOptions, Context context)

Generate authorization for copying a custom model into the target Form Recognizer resource.

This should be called by the target resource (where the model will be copied to) and the output can be passed as the target parameter into beginCopyDocumentModelTo(String sourceModelId, DocumentModelCopyAuthorization target).

Parameters:

copyAuthorizationOptions - The configurable CopyAuthorizationOptions to pass when copying a model.
context - Additional context that is passed through the Http pipeline during the service call. Code sample String modelId = "my-copied-model"; Map<String, String> attrs = new HashMap<String, String>(); attrs.put("createdBy", "sample");

Response<DocumentModelCopyAuthorization> copyAuthorizationResponse = documentModelAdministrationClient.getCopyAuthorizationWithResponse( new CopyAuthorizationOptions() .setModelId(modelId) .setDescription("model-desc") .setTags(attrs), Context.NONE); System.out.printf("Copy Authorization operation returned with status: %s", copyAuthorizationResponse.getStatusCode()); DocumentModelCopyAuthorization documentModelCopyAuthorization = copyAuthorizationResponse.getValue(); System.out.printf("Copy Authorization for model id: %s, access token: %s, " + "expiration time: %s, target resource ID; %s, target resource region: %s%n", documentModelCopyAuthorization.getTargetModelId(), documentModelCopyAuthorization.getAccessToken(), documentModelCopyAuthorization.getExpiresOn(), documentModelCopyAuthorization.getTargetResourceId(), documentModelCopyAuthorization.getTargetResourceRegion() );

Returns:

getDocumentAnalysisClient

public DocumentAnalysisClient getDocumentAnalysisClient()

Creates a new DocumentAnalysisClient object. The new DocumentAnalysisClient uses the same request policy pipeline as the DocumentAnalysisClient.

Returns:

getDocumentClassifier

public DocumentClassifierDetails getDocumentClassifier(String classifierId)

Get detailed information for a document classifier by its ID.

Code sample

String classifierId = "{classifierId}";
 DocumentClassifierDetails documentClassifierDetails
     = documentModelAdministrationClient.getDocumentClassifier(classifierId);
 System.out.printf("Classifier ID: %s%n", documentClassifierDetails.getClassifierId());
 System.out.printf("Classifier Description: %s%n", documentClassifierDetails.getDescription());
 System.out.printf("Classifier Created on: %s%n", documentClassifierDetails.getCreatedOn());
 documentClassifierDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     if (documentTypeDetails.getContentSource() instanceof BlobContentSource) {
         System.out.printf("Blob Source container Url: %s", ((BlobContentSource) documentTypeDetails
             .getContentSource()).getContainerUrl());
     }
     if (documentTypeDetails.getContentSource() instanceof BlobFileListContentSource) {
         System.out.printf("Blob File List Source container Url: %s",
             ((BlobFileListContentSource) documentTypeDetails
                 .getContentSource()).getContainerUrl());
     }
 });

Parameters:

classifierId - The unique document classifier identifier.

Returns:

The detailed information for the specified document classifier ID.

getDocumentClassifierWithResponse

public Response getDocumentClassifierWithResponse(String classifierId, Context context)

Get detailed information for a document classifier by its ID.

Code sample

String modelId = "{custom-model-id}";
 Response<DocumentClassifierDetails> response
     = documentModelAdministrationClient.getDocumentClassifierWithResponse(modelId, Context.NONE);
 System.out.printf("Response Status Code: %d.", response.getStatusCode());
 DocumentClassifierDetails documentClassifierDetails = response.getValue();
 System.out.printf("Classifier ID: %s%n", documentClassifierDetails.getClassifierId());
 System.out.printf("Classifier Description: %s%n", documentClassifierDetails.getDescription());
 System.out.printf("Classifier Created on: %s%n", documentClassifierDetails.getCreatedOn());
 documentClassifierDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     if (documentTypeDetails.getContentSource() instanceof BlobContentSource) {
         System.out.printf("Blob Source container Url: %s", ((BlobContentSource) documentTypeDetails
             .getContentSource()).getContainerUrl());
     }
     if (documentTypeDetails.getContentSource() instanceof BlobFileListContentSource) {
         System.out.printf("Blob File List Source container Url: %s",
             ((BlobFileListContentSource) documentTypeDetails
                 .getContentSource()).getContainerUrl());
     }
 });

Parameters:

classifierId - The unique document classifier identifier.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

The detailed information for the specified document classifier ID.

getDocumentModel

public DocumentModelDetails getDocumentModel(String modelId)

Get detailed information for a specified model ID.

Code sample

String modelId = "{custom-model-id}";
 DocumentModelDetails documentModelDetails = documentModelAdministrationClient.getDocumentModel(modelId);
 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

modelId - The unique model identifier.

Returns:

The detailed information for the specified model.

getDocumentModelWithResponse

public Response getDocumentModelWithResponse(String modelId, Context context)

Get detailed information for a specified model ID.

Code sample

String modelId = "{custom-model-id}";
 Response<DocumentModelDetails> response
     = documentModelAdministrationClient.getDocumentModelWithResponse(modelId, Context.NONE);
 System.out.printf("Response Status Code: %d.", response.getStatusCode());
 DocumentModelDetails documentModelDetails = response.getValue();
 System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
 System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
 System.out.printf("Model Created on: %s%n", documentModelDetails.getCreatedOn());
 documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
     documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
         System.out.printf("Field: %s", field);
         System.out.printf("Field type: %s", documentFieldSchema.getType());
         System.out.printf("Field confidence: %.2f", documentTypeDetails.getFieldConfidence().get(field));
     });
 });

Parameters:

modelId - The unique model identifier.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

The detailed information for the specified model.

getOperation

public OperationDetails getOperation(String operationId)

Get detailed operation information for the specified ID with Http response.

This operations fails if the operation ID used is past 24 hours.

Code sample

String operationId = "{operation-id}";
 OperationDetails operationDetails
     = documentModelAdministrationClient.getOperation(operationId);
 System.out.printf("Operation ID: %s%n", operationDetails.getOperationId());
 System.out.printf("Operation Kind: %s%n", operationDetails.getKind());
 System.out.printf("Operation Status: %s%n", operationDetails.getStatus());
 System.out.printf("Model ID created with this operation: %s%n",
     ((DocumentModelBuildOperationDetails) operationDetails).getResult().getModelId());
 if (OperationStatus.FAILED.equals(operationDetails.getStatus())) {
     System.out.printf("Operation fail error: %s%n", operationDetails.getError().getMessage());
 }

Parameters:

operationId - Unique operation ID.

Returns:

The detailed information for the specified operation.

getOperationWithResponse

public Response getOperationWithResponse(String operationId, Context context)

Get detailed operation information for the specified ID with Http response.

This operations fails if the operation ID used is past 24 hours.

Code sample

String operationId = "{operation-id}";
 Response<OperationDetails> response =
     documentModelAdministrationClient.getOperationWithResponse(operationId, Context.NONE);
 System.out.printf("Response Status Code: %d.", response.getStatusCode());
 OperationDetails operationDetails = response.getValue();
 System.out.printf("Operation ID: %s%n", operationDetails.getOperationId());
 System.out.printf("Operation Kind: %s%n", operationDetails.getKind());
 System.out.printf("Operation Status: %s%n", operationDetails.getStatus());
 System.out.printf("Model ID created with this operation: %s%n",
     ((DocumentModelBuildOperationDetails) operationDetails).getResult().getModelId());
 if (OperationStatus.FAILED.equals(operationDetails.getStatus())) {
     System.out.printf("Operation fail error: %s%n", operationDetails.getError().getMessage());
 }

Parameters:

operationId - Unique operation ID.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

The detailed information for the specified operation.

getResourceDetails

public ResourceDetails getResourceDetails()

Get information about the current Form Recognizer resource.

Code sample

ResourceDetails resourceDetails = documentModelAdministrationClient.getResourceDetails();
 System.out.printf("Max number of models that can be build for this account: %d%n",
     resourceDetails.getCustomDocumentModelLimit());
 System.out.printf("Current count of built document analysis models: %d%n",
     resourceDetails.getCustomDocumentModelCount());

Returns:

The requested resource information details.

getResourceDetailsWithResponse

public Response getResourceDetailsWithResponse(Context context)

Get information about the current Form recognizer resource with a Http response and a specified Context.

Code sample

Response<ResourceDetails> response =
     documentModelAdministrationClient.getResourceDetailsWithResponse(Context.NONE);
 System.out.printf("Response Status Code: %d.", response.getStatusCode());
 ResourceDetails resourceDetails = response.getValue();
 System.out.printf("Max number of models that can be build for this account: %d%n",
     resourceDetails.getCustomDocumentModelLimit());
 System.out.printf("Current count of built document analysis models: %d%n",
     resourceDetails.getCustomDocumentModelCount());

Parameters:

context - Additional context that is passed through the Http pipeline during the service call.

Returns:

The requested resource information details.

listDocumentClassifiers

public PagedIterable listDocumentClassifiers()

List information for each document classifier on the Form Recognizer account that were built successfully.

Code sample

documentModelAdministrationClient.listDocumentClassifiers()
     .forEach(documentModel ->
         System.out.printf("Classifier ID: %s, Classifier description: %s, Created on: %s.%n",
             documentModel.getClassifierId(),
             documentModel.getDescription(),
             documentModel.getCreatedOn())
     );

Returns:

PagedIterable<T> of DocumentClassifierDetails on the Form Recognizer account.

listDocumentClassifiers

public PagedIterable listDocumentClassifiers(Context context)

List information for each document classifier on the Form Recognizer account that were built successfully with a Http response and a specified Context.

Code sample

documentModelAdministrationClient.listDocumentClassifiers(Context.NONE)
     .forEach(documentModel ->
         System.out.printf("Classifier ID: %s, Classifier description: %s, Created on: %s.%n",
             documentModel.getClassifierId(),
             documentModel.getDescription(),
             documentModel.getCreatedOn())
     );

Parameters:

context - Additional context that is passed through the Http pipeline during the service call.

Returns:

PagedIterable<T> of DocumentClassifierDetails on the Form Recognizer account.

listDocumentModels

public PagedIterable listDocumentModels()

List information for each model on the Form Recognizer account that were built successfully.

Code sample

documentModelAdministrationClient.listDocumentModels()
     .forEach(documentModel ->
         System.out.printf("Model ID: %s, Model description: %s, Created on: %s.%n",
             documentModel.getModelId(),
             documentModel.getDescription(),
             documentModel.getCreatedOn())
     );

Returns:

PagedIterable<T> of DocumentModelSummary custom form model information.

listDocumentModels

public PagedIterable listDocumentModels(Context context)

List information for each model on the Form Recognizer account that were built successfully with a Http response and a specified Context.

Code sample

documentModelAdministrationClient.listDocumentModels(Context.NONE)
     .forEach(documentModel ->
         System.out.printf("Model ID: %s, Model description: %s, Created on: %s.%n",
             documentModel.getModelId(),
             documentModel.getDescription(),
             documentModel.getCreatedOn())
     );

Parameters:

context - Additional context that is passed through the Http pipeline during the service call.

Returns:

PagedIterable<T> of DocumentModelSummary custom form model information.

listOperations

public PagedIterable listOperations()

List information for each model operation on the Form Recognizer account in the past 24 hours.

Code sample

PagedIterable<OperationSummary>
     modelOperationInfo = documentModelAdministrationClient.listOperations();
 modelOperationInfo.forEach(modelOperationSummary -> {
     System.out.printf("Operation ID: %s%n", modelOperationSummary.getOperationId());
     System.out.printf("Operation Status: %s%n", modelOperationSummary.getStatus());
     System.out.printf("Operation Created on: %s%n", modelOperationSummary.getCreatedOn());
     System.out.printf("Operation Percent completed: %d%n", modelOperationSummary.getPercentCompleted());
     System.out.printf("Operation Kind: %s%n", modelOperationSummary.getKind());
     System.out.printf("Operation Last updated on: %s%n", modelOperationSummary.getLastUpdatedOn());
     System.out.printf("Operation resource location: %s%n", modelOperationSummary.getResourceLocation());
 });

Returns:

PagedIterable<T> of OperationSummary custom form model information.

listOperations

public PagedIterable listOperations(Context context)

List information for each operation on the Form Recognizer account in the past 24 hours with an HTTP response and a specified Context.

Code sample

PagedIterable<OperationSummary>
     modelOperationInfo = documentModelAdministrationClient.listOperations(Context.NONE);
 modelOperationInfo.forEach(modelOperationSummary -> {
     System.out.printf("Operation ID: %s%n", modelOperationSummary.getOperationId());
     System.out.printf("Operation Status: %s%n", modelOperationSummary.getStatus());
     System.out.printf("Operation Created on: %s%n", modelOperationSummary.getCreatedOn());
     System.out.printf("Operation Percent completed: %d%n", modelOperationSummary.getPercentCompleted());
     System.out.printf("Operation Kind: %s%n", modelOperationSummary.getKind());
     System.out.printf("Operation Last updated on: %s%n", modelOperationSummary.getLastUpdatedOn());
     System.out.printf("Operation resource location: %s%n", modelOperationSummary.getResourceLocation());
 });

Parameters:

context - Additional context that is passed through the Http pipeline during the service call.

Returns:

PagedIterable<T> of OperationSummary custom form model information.

Applies to