Class DocumentModelAdministrationAsyncClient
- java.lang.Object
-
- com.azure.ai.formrecognizer.administration.DocumentModelAdministrationAsyncClient
-
public final class DocumentModelAdministrationAsyncClient extends Object
This class provides an asynchronous client that contains model management operations that apply to Azure Form Recognizer. Operations allowed by the client are creating, building of custom document analysis models, deleting models, listing models, copying a custom-built model to another Form Recognizer account, composing models from component models, getting operation information and getting account information.Instantiating an asynchronous Document Model Administration Client
DocumentModelAdministrationAsyncClient documentModelAdministrationAsyncClient = new DocumentModelAdministrationClientBuilder().buildAsyncClient();
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel>
beginBuildModel(String trainingFilesUrl, String modelId)
Builds a custom document analysis model.com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel>
beginBuildModel(String trainingFilesUrl, String modelId, BuildModelOptions buildModelOptions)
Builds a custom document analysis model.com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel>
beginCopyModel(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> modelIDs, String modelId)
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> modelIDs, String modelId, CreateComposedModelOptions createComposedModelOptions)
Create a composed model from the provided list of existing models in the account.Mono<Void>
deleteModel(String modelId)
Deletes the specified custom document analysis model.Mono<com.azure.core.http.rest.Response<Void>>
deleteModelWithResponse(String modelId)
Deletes the specified custom document analysis model.Mono<AccountProperties>
getAccountProperties()
Get account information of the Form Recognizer account.Mono<com.azure.core.http.rest.Response<AccountProperties>>
getAccountPropertiesWithResponse()
Get account information of the Form Recognizer account with a Http response.Mono<CopyAuthorization>
getCopyAuthorization(String modelId)
Generate authorization for copying a custom document analysis model into the target Form Recognizer resource.Mono<com.azure.core.http.rest.Response<CopyAuthorization>>
getCopyAuthorizationWithResponse(String modelId, CopyAuthorizationOptions copyAuthorizationOptions)
Generate authorization for copying a custom document analysis model into the target Form Recognizer resource.DocumentAnalysisAsyncClient
getDocumentAnalysisAsyncClient()
Creates a newDocumentAnalysisAsyncClient
object.Mono<DocumentModel>
getModel(String modelId)
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.Mono<ModelOperation>
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>
listModels()
List information for each model on the Form Recognizer account that were built successfully.com.azure.core.http.rest.PagedFlux<ModelOperationInfo>
listOperations()
List information for each model operation on the Form Recognizer account in the past 24 hours.
-
-
-
Method Detail
-
getDocumentAnalysisAsyncClient
public DocumentAnalysisAsyncClient 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, String modelId)
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, "model-name") // 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
- source URL parameter that is an externally accessible Azure storage blob container Url (preferably a Shared Access Signature Url).modelId
- unique model identifier. If not specified, a model ID will be created for you.- 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, String modelId, 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}"; documentModelAdministrationAsyncClient.beginBuildModel(trainingFilesUrl, "model-name", new BuildModelOptions() .setDescription("model desc") .setPrefix("Invoice")) // 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()); 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
- source URL parameter that is an externally accessible Azure storage blob container Url (preferably a Shared Access Signature Url).modelId
- unique model identifier. If not specified, a model ID will be created for you.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
public Mono<AccountProperties> 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
public Mono<Void> deleteModel(String modelId)
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
public Mono<com.azure.core.http.rest.Response<Void>> deleteModelWithResponse(String modelId)
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
public Mono<CopyAuthorization> getCopyAuthorization(String modelId)
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
beginCopyModel(String, CopyAuthorization)
.- Parameters:
modelId
- A unique ID for your copied model. If not specified, a model ID will be created for you.Code sample
String modelId = "my-copied-model"; documentModelAdministrationAsyncClient.getCopyAuthorization(modelId) .subscribe(copyAuthorization -> System.out.printf("Copy Authorization for model id: %s, access token: %s, expiration time: %s, " + "target resource ID; %s, target resource region: %s%n", copyAuthorization.getTargetModelId(), copyAuthorization.getAccessToken(), copyAuthorization.getExpiresOn(), copyAuthorization.getTargetResourceId(), copyAuthorization.getTargetResourceRegion() ));
- Returns:
- The
CopyAuthorization
that could be used to authorize copying model between resources.
-
getCopyAuthorizationWithResponse
public Mono<com.azure.core.http.rest.Response<CopyAuthorization>> getCopyAuthorizationWithResponse(String modelId, 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
beginCopyModel(String, CopyAuthorization)
.- Parameters:
modelId
- A unique ID for your copied model. If not specified, a model ID will be created for you.copyAuthorizationOptions
- The configurableoptions
to pass when copying a model.Code sample
String modelId = "my-copied-model"; documentModelAdministrationAsyncClient.getCopyAuthorizationWithResponse(modelId, new CopyAuthorizationOptions().setDescription("model desc")) .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> modelIDs, String modelId)
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), "my-composed-model") // 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:
modelIDs
- The list of component models to compose.modelId
- The unique model identifier for the 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 createdcomposed model
. - Throws:
DocumentModelOperationException
- If create composed model operation fails and model withOperationStatus.FAILED
is created.NullPointerException
- If the list ofmodelIDs
ormodelId
is null or empty.
-
beginCreateComposedModel
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginCreateComposedModel(List<String> modelIDs, String modelId, 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}"; documentModelAdministrationAsyncClient.beginCreateComposedModel(Arrays.asList(modelId1, modelId2), "my-composed-model", new CreateComposedModelOptions().setDescription("model-desc")) // 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()); 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:
modelIDs
- The list of component models to compose.modelId
- The unique model identifier for the composed model.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.
-
beginCopyModel
public com.azure.core.util.polling.PollerFlux<DocumentOperationResult,DocumentModel> beginCopyModel(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(String)
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"; String targetModelId = "my-copied-model-id"; // Get authorization to copy the model to target resource documentModelAdministrationAsyncClient.getCopyAuthorization(targetModelId) // Start copy operation from the source client // The ID of the model that needs to be copied to the target resource .subscribe(copyAuthorization -> documentModelAdministrationAsyncClient.beginCopyModel(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(String)
- 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
public com.azure.core.http.rest.PagedFlux<DocumentModelInfo> 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
public Mono<DocumentModel> getModel(String modelId)
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
public Mono<com.azure.core.http.rest.Response<DocumentModel>> getModelWithResponse(String modelId)
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
public Mono<ModelOperation> getOperation(String operationId)
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.com.azure.core.exception.HttpResponseException
- If theoperationId
is past 24 hours.
-
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
public com.azure.core.http.rest.PagedFlux<ModelOperationInfo> 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
.
-
-