Class DocumentModelAdministrationAsyncClient
Instantiating an asynchronous Document Model Administration Client
DocumentModelAdministrationAsyncClient documentModelAdministrationAsyncClient = new DocumentModelAdministrationClientBuilder().buildAsyncClient();
-
Method Summary
Modifier and TypeMethodDescriptioncom.azure.core.util.polling.PollerFlux<DocumentOperationResult,
DocumentModel> beginBuildModel
(String trainingFilesUrl, DocumentBuildMode buildMode) Builds a custom document analysis model.com.azure.core.util.polling.PollerFlux<DocumentOperationResult,
DocumentModel> beginBuildModel
(String trainingFilesUrl, DocumentBuildMode buildMode, BuildModelOptions buildModelOptions) Builds a custom document analysis model.com.azure.core.util.polling.PollerFlux<DocumentOperationResult,
DocumentModel> beginCopyModelTo
(String modelId, CopyAuthorization target) Copy a custom model stored in this resource (the source) to the user specified target Form Recognizer resource.com.azure.core.util.polling.PollerFlux<DocumentOperationResult,
DocumentModel> beginCreateComposedModel
(List<String> componentModelIds) Create a composed model from the provided list of existing models in the account.com.azure.core.util.polling.PollerFlux<DocumentOperationResult,
DocumentModel> beginCreateComposedModel
(List<String> componentModelIds, CreateComposedModelOptions createComposedModelOptions) Create a composed model from the provided list of existing models in the account.deleteModel
(String modelId) Deletes the specified custom document analysis model.deleteModelWithResponse
(String modelId) Deletes the specified custom document analysis model.Get account information of the Form Recognizer account.Mono<com.azure.core.http.rest.Response<AccountProperties>>
Get account information of the Form Recognizer account with a Http response.Generate authorization for copying a custom document analysis model into the target Form Recognizer resource.Mono<com.azure.core.http.rest.Response<CopyAuthorization>>
getCopyAuthorizationWithResponse
(CopyAuthorizationOptions copyAuthorizationOptions) Generate authorization for copying a custom document analysis model into the target Form Recognizer resource.Creates a newDocumentAnalysisAsyncClient
object.Get detailed information for a specified model ID.Mono<com.azure.core.http.rest.Response<DocumentModel>>
getModelWithResponse
(String modelId) Get detailed information for a specified model ID with Http response.getOperation
(String operationId) Get detailed operation information for the specified ID.Mono<com.azure.core.http.rest.Response<ModelOperation>>
getOperationWithResponse
(String operationId) Get detailed operation information for the specified ID with Http response.com.azure.core.http.rest.PagedFlux<DocumentModelInfo>
List information for each model on the Form Recognizer account that were built successfully.com.azure.core.http.rest.PagedFlux<ModelOperationInfo>
List information for each model operation on the Form Recognizer account in the past 24 hours.
-
Method Details
-
getDocumentAnalysisAsyncClient
Creates a newDocumentAnalysisAsyncClient
object. The newDocumentTrainingAsyncClient
uses the same request policy pipeline as theDocumentTrainingAsyncClient
.- Returns:
- A new
DocumentAnalysisAsyncClient
object.
-
beginBuildModel
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginBuildModel(String trainingFilesUrl, DocumentBuildMode 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.
See here for information on building your own administration data set.Code sample
String trainingFilesUrl = "{SAS-URL-of-your-container-in-blob-storage}"; documentModelAdministrationAsyncClient.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE ) // if polling operation completed, retrieve the final result. .flatMap(AsyncPollResponse::getFinalResult) .subscribe(documentModel -> { System.out.printf("Model ID: %s%n", documentModel.getModelId()); System.out.printf("Model Created on: %s%n", documentModel.getCreatedOn()); documentModel.getDocTypes().forEach((key, docTypeInfo) -> { docTypeInfo.getFieldSchema().forEach((field, documentFieldSchema) -> { System.out.printf("Field: %s", field); System.out.printf("Field type: %s", documentFieldSchema.getType()); System.out.printf("Field confidence: %.2f", docTypeInfo.getFieldConfidence().get(field)); }); }); });
- Parameters:
trainingFilesUrl
- 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 useDocumentBuildMode.TEMPLATE
. See here for more information on building mode for custom documents.- Returns:
- A
PollerFlux
that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the trainedcustom document analysis model
. - Throws:
DocumentModelOperationException
- If building a model fails withOperationStatus.FAILED
is created.NullPointerException
- IftrainingFilesUrl
is null.
-
beginBuildModel
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginBuildModel(String trainingFilesUrl, DocumentBuildMode buildMode, BuildModelOptions buildModelOptions) 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.
See here for information on building your own administration data set.Code sample
String trainingFilesUrl = "{SAS-URL-of-your-container-in-blob-storage}"; String modelId = "model-id"; Map<String, String> attrs = new HashMap<String, String>(); attrs.put("createdBy", "sample"); documentModelAdministrationAsyncClient.beginBuildModel(trainingFilesUrl, DocumentBuildMode.TEMPLATE, new BuildModelOptions() .setModelId(modelId) .setDescription("model desc") .setPrefix("Invoice") .setTags(attrs)) // if polling operation completed, retrieve the final result. .flatMap(AsyncPollResponse::getFinalResult) .subscribe(documentModel -> { System.out.printf("Model ID: %s%n", documentModel.getModelId()); System.out.printf("Model Description: %s%n", documentModel.getDescription()); System.out.printf("Model Created on: %s%n", documentModel.getCreatedOn()); System.out.printf("Model assigned tags: %s%n", documentModel.getTags()); documentModel.getDocTypes().forEach((key, docTypeInfo) -> { docTypeInfo.getFieldSchema().forEach((field, documentFieldSchema) -> { System.out.printf("Field: %s", field); System.out.printf("Field type: %s", documentFieldSchema.getType()); System.out.printf("Field confidence: %.2f", docTypeInfo.getFieldConfidence().get(field)); }); }); });
- Parameters:
trainingFilesUrl
- 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 useDocumentBuildMode.TEMPLATE
. See here for more information on building mode for custom documents.buildModelOptions
- The configurableoptions
to pass when building a custom document analysis model.- Returns:
- A
PollerFlux
that polls the building model operation until it has completed, has failed, or has been cancelled. The completed operation returns the trainedcustom document analysis model
. - Throws:
DocumentModelOperationException
- If building a model fails withOperationStatus.FAILED
is created.NullPointerException
- IftrainingFilesUrl
is null.
-
getAccountProperties
Get account information of the Form Recognizer account.Code sample
documentModelAdministrationAsyncClient.getAccountProperties() .subscribe(accountProperties -> { System.out.printf("Max number of models that can be build for this account: %d%n", accountProperties.getDocumentModelLimit()); System.out.printf("Current count of built document analysis models: %d%n", accountProperties.getDocumentModelCount()); });
- Returns:
- The requested account information details.
-
getAccountPropertiesWithResponse
public Mono<com.azure.core.http.rest.Response<AccountProperties>> getAccountPropertiesWithResponse()Get account information of the Form Recognizer account with a Http response.Code sample
documentModelAdministrationAsyncClient.getAccountPropertiesWithResponse() .subscribe(response -> { System.out.printf("Response Status Code: %d.", response.getStatusCode()); AccountProperties accountProperties = response.getValue(); System.out.printf("Max number of models that can be build for this account: %d%n", accountProperties.getDocumentModelLimit()); System.out.printf("Current count of built document analysis models: %d%n", accountProperties.getDocumentModelCount()); });
- Returns:
- A
Response
containing the requested account information details.
-
deleteModel
Deletes the specified custom document analysis model.Code sample
String modelId = "{model_id}"; documentModelAdministrationAsyncClient.deleteModel(modelId) .subscribe(ignored -> System.out.printf("Model ID: %s is deleted%n", modelId));
- Parameters:
modelId
- The unique model identifier.- Returns:
- An empty Mono.
- Throws:
IllegalArgumentException
- IfmodelId
is null or empty.
-
deleteModelWithResponse
Deletes the specified custom document analysis model.Code sample
String modelId = "{model_id}"; documentModelAdministrationAsyncClient.deleteModelWithResponse(modelId) .subscribe(response -> { 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.- Returns:
- A
Response
containing the status code and HTTP headers. - Throws:
IllegalArgumentException
- IfmodelId
is null or empty.
-
getCopyAuthorization
Generate authorization for copying a custom document analysis 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
beginCopyModelTo(String, CopyAuthorization)
.- Returns:
- The
CopyAuthorization
that could be used to authorize copying model between resources.
-
getCopyAuthorizationWithResponse
public Mono<com.azure.core.http.rest.Response<CopyAuthorization>> getCopyAuthorizationWithResponse(CopyAuthorizationOptions copyAuthorizationOptions) Generate authorization for copying a custom document analysis 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
beginCopyModelTo(String, CopyAuthorization)
.- Parameters:
copyAuthorizationOptions
- The configurableoptions
to pass when copying a model.Code sample
String modelId = "my-copied-model"; Map<String, String> attrs = new HashMap<String, String>(); attrs.put("createdBy", "sample"); documentModelAdministrationAsyncClient.getCopyAuthorizationWithResponse( new CopyAuthorizationOptions() .setModelId(modelId) .setDescription("model desc") .setTags(attrs)) .subscribe(copyAuthorization -> System.out.printf("Copy Authorization response status: %s, for model id: %s, access token: %s, " + "expiration time: %s, target resource ID; %s, target resource region: %s%n", copyAuthorization.getStatusCode(), copyAuthorization.getValue().getTargetModelId(), copyAuthorization.getValue().getAccessToken(), copyAuthorization.getValue().getExpiresOn(), copyAuthorization.getValue().getTargetResourceId(), copyAuthorization.getValue().getTargetResourceRegion() ));
- Returns:
- The
CopyAuthorization
that could be used to authorize copying model between resources.
-
beginCreateComposedModel
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginCreateComposedModel(List<String> 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 = "{model_Id_1}"; String modelId2 = "{model_Id_2}"; documentModelAdministrationAsyncClient.beginCreateComposedModel(Arrays.asList(modelId1, modelId2) ) // if polling operation completed, retrieve the final result. .flatMap(AsyncPollResponse::getFinalResult) .subscribe(documentModel -> { System.out.printf("Model ID: %s%n", documentModel.getModelId()); System.out.printf("Model Created on: %s%n", documentModel.getCreatedOn()); documentModel.getDocTypes().forEach((key, docTypeInfo) -> { docTypeInfo.getFieldSchema().forEach((field, documentFieldSchema) -> { System.out.printf("Field: %s", field); System.out.printf("Field type: %s", documentFieldSchema.getType()); System.out.printf("Field confidence: %.2f", docTypeInfo.getFieldConfidence().get(field)); }); }); });
- Parameters:
componentModelIds
- The list of component models to compose.- Returns:
- A
PollerFlux
that polls the create composed model operation until it has completed, has failed, or has been cancelled. The completed operation returns the createdcomposed model
. - Throws:
DocumentModelOperationException
- If create composed model operation fails and model withOperationStatus.FAILED
is created.NullPointerException
- If the list ofmodelIDs
is null or empty.
-
beginCreateComposedModel
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginCreateComposedModel(List<String> componentModelIds, CreateComposedModelOptions createComposedModelOptions) 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 = "{model_Id_1}"; String modelId2 = "{model_Id_2}"; String modelId = "my-composed-model"; Map<String, String> attrs = new HashMap<String, String>(); attrs.put("createdBy", "sample"); documentModelAdministrationAsyncClient.beginCreateComposedModel(Arrays.asList(modelId1, modelId2), new CreateComposedModelOptions() .setModelId(modelId) .setDescription("model-desc") .setTags(attrs)) // if polling operation completed, retrieve the final result. .flatMap(AsyncPollResponse::getFinalResult) .subscribe(documentModel -> { System.out.printf("Model ID: %s%n", documentModel.getModelId()); System.out.printf("Model Description: %s%n", documentModel.getDescription()); System.out.printf("Model Created on: %s%n", documentModel.getCreatedOn()); System.out.printf("Model assigned tags: %s%n", documentModel.getTags()); documentModel.getDocTypes().forEach((key, docTypeInfo) -> { docTypeInfo.getFieldSchema().forEach((field, documentFieldSchema) -> { System.out.printf("Field: %s", field); System.out.printf("Field type: %s", documentFieldSchema.getType()); System.out.printf("Field confidence: %.2f", docTypeInfo.getFieldConfidence().get(field)); }); }); });
- Parameters:
componentModelIds
- The list of component models to compose.createComposedModelOptions
- The configurableoptions
to pass when creating a composed model.- Returns:
- A
PollerFlux
that polls the create composed model operation until it has completed, has failed, or has been cancelled. The completed operation returns the copied modelDocumentModel
. - Throws:
DocumentModelOperationException
- If create composed model operation fails and model withOperationStatus.FAILED
is created.NullPointerException
- If the list ofmodelIDs
is null or empty.
-
beginCopyModelTo
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginCopyModelTo(String modelId, CopyAuthorization 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 documentModelAdministrationAsyncClient.getCopyAuthorization() // Start copy operation from the source client // The ID of the model that needs to be copied to the target resource .subscribe(copyAuthorization -> documentModelAdministrationAsyncClient.beginCopyModelTo(copyModelId, copyAuthorization) .filter(pollResponse -> pollResponse.getStatus().isComplete()) .flatMap(AsyncPollResponse::getFinalResult) .subscribe(documentModel -> System.out.printf("Copied model has model ID: %s, was created on: %s.%n,", documentModel.getModelId(), documentModel.getCreatedOn())));
- Parameters:
modelId
- 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 togetCopyAuthorization()
- Returns:
- A
PollerFlux
that polls the copy model operation until it has completed, has failed, or has been cancelled. The completed operation returns the copied modelDocumentModel
. - Throws:
DocumentModelOperationException
- If copy operation fails and model withOperationStatus.FAILED
is created.NullPointerException
- IfmodelId
ortarget
is null.
-
listModels
List information for each model on the Form Recognizer account that were built successfully.Code sample
documentModelAdministrationAsyncClient.listModels() .subscribe(documentModelInfo -> System.out.printf("Model ID: %s, Model description: %s, Created on: %s.%n", documentModelInfo.getModelId(), documentModelInfo.getDescription(), documentModelInfo.getCreatedOn()));
- Returns:
PagedFlux
ofDocumentModelInfo
.
-
getModel
Get detailed information for a specified model ID.Code sample
String modelId = "{model_id}"; documentModelAdministrationAsyncClient.getModel(modelId).subscribe(documentModel -> { System.out.printf("Model ID: %s%n", documentModel.getModelId()); System.out.printf("Model Description: %s%n", documentModel.getDescription()); System.out.printf("Model Created on: %s%n", documentModel.getCreatedOn()); documentModel.getDocTypes().forEach((key, docTypeInfo) -> { docTypeInfo.getFieldSchema().forEach((field, documentFieldSchema) -> { System.out.printf("Field: %s", field); System.out.printf("Field type: %s", documentFieldSchema.getType()); System.out.printf("Field confidence: %.2f", docTypeInfo.getFieldConfidence().get(field)); }); }); });
- Parameters:
modelId
- The unique model identifier.- Returns:
- The detailed information for the specified model.
- Throws:
IllegalArgumentException
- IfmodelId
is null or empty.
-
getModelWithResponse
Get detailed information for a specified model ID with Http response.Code sample
String modelId = "{model_id}"; documentModelAdministrationAsyncClient.getModelWithResponse(modelId).subscribe(response -> { System.out.printf("Response Status Code: %d.", response.getStatusCode()); DocumentModel documentModel = response.getValue(); System.out.printf("Model ID: %s%n", documentModel.getModelId()); System.out.printf("Model Description: %s%n", documentModel.getDescription()); System.out.printf("Model Created on: %s%n", documentModel.getCreatedOn()); documentModel.getDocTypes().forEach((key, docTypeInfo) -> { docTypeInfo.getFieldSchema().forEach((field, documentFieldSchema) -> { System.out.printf("Field: %s", field); System.out.printf("Field type: %s", documentFieldSchema.getType()); System.out.printf("Field confidence: %.2f", docTypeInfo.getFieldConfidence().get(field)); }); }); });
- Parameters:
modelId
- The unique model identifier.- Returns:
- A
Response
containing the requestedmodel
. - Throws:
IllegalArgumentException
- IfmodelId
is null or empty.
-
getOperation
Get detailed operation information for the specified ID.This operations fails if the operation ID used is past 24 hours.
Code sample
String operationId = "{operation_Id}"; documentModelAdministrationAsyncClient.getOperation(operationId).subscribe(modelOperation -> { System.out.printf("Operation ID: %s%n", modelOperation.getOperationId()); System.out.printf("Operation Kind: %s%n", modelOperation.getKind()); System.out.printf("Operation Status: %s%n", modelOperation.getStatus()); System.out.printf("Model ID created with this operation: %s%n", modelOperation.getModelId()); if (ModelOperationStatus.FAILED.equals(modelOperation.getStatus())) { System.out.printf("Operation fail error: %s%n", modelOperation.getError().getMessage()); } });
- Parameters:
operationId
- Unique operation ID.- Returns:
- detailed operation information for the specified ID.
- Throws:
IllegalArgumentException
- IfoperationId
is null or empty.
-
getOperationWithResponse
public Mono<com.azure.core.http.rest.Response<ModelOperation>> getOperationWithResponse(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}"; documentModelAdministrationAsyncClient.getOperationWithResponse(operationId).subscribe(response -> { System.out.printf("Response Status Code: %d.", response.getStatusCode()); ModelOperation modelOperation = response.getValue(); System.out.printf("Operation ID: %s%n", modelOperation.getOperationId()); System.out.printf("Operation Kind: %s%n", modelOperation.getKind()); System.out.printf("Operation Status: %s%n", modelOperation.getStatus()); System.out.printf("Model ID created with this operation: %s%n", modelOperation.getModelId()); if (ModelOperationStatus.FAILED.equals(modelOperation.getStatus())) { System.out.printf("Operation fail error: %s%n", modelOperation.getError().getMessage()); } });
- Parameters:
operationId
- Unique operation ID.- Returns:
- A
Response
containing the requestedModelOperation
. - Throws:
IllegalArgumentException
- IfoperationId
is null or empty.
-
listOperations
List information for each model operation on the Form Recognizer account in the past 24 hours.Code sample
documentModelAdministrationAsyncClient.listOperations() .subscribe(modelOperation -> { System.out.printf("Operation ID: %s%n", modelOperation.getOperationId()); System.out.printf("Operation Status: %s%n", modelOperation.getStatus()); System.out.printf("Operation Created on: %s%n", modelOperation.getCreatedOn()); System.out.printf("Operation Percent completed: %d%n", modelOperation.getPercentCompleted()); System.out.printf("Operation Kind: %s%n", modelOperation.getKind()); System.out.printf("Operation Last updated on: %s%n", modelOperation.getLastUpdatedOn()); System.out.printf("Operation resource location: %s%n", modelOperation.getResourceLocation()); });
- Returns:
PagedFlux
ofModelOperationInfo
.
-