diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml index f9dd1b4c24cc..9dccb5286e34 100755 --- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml +++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml @@ -267,14 +267,14 @@ - + - - + + --name ``` Use the API key as the credential parameter to authenticate the client: - + ```java FormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder() .credential(new AzureKeyCredential("{key}")) @@ -83,7 +83,7 @@ FormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder() ``` The Azure Form Recognizer client library provides a way to **rotate the existing API key**. - + ```java AzureKeyCredential credential = new AzureKeyCredential("{key}"); FormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder() @@ -143,7 +143,7 @@ The following section provides several code snippets covering some of the most c ### Recognize Forms Using a Custom Model Recognize name/value pairs and table data from forms. These models are trained with your own data, so they're tailored to your forms. You should only recognize forms of the same form type that the custom model was trained on. - + ```java String analyzeFilePath = "{file_source_url}"; String modelId = "{custom_trained_model_id}"; @@ -166,7 +166,7 @@ recognizedForms.forEach(form -> { ### Recognize Content Recognize text and table structures, along with their bounding box coordinates, from documents. - + ```java String analyzeFilePath = "{file_source_url}"; SyncPoller> recognizeLayoutPoller = @@ -193,7 +193,7 @@ layoutPageResults.forEach(formPage -> { ### Recognize receipts Recognize data from a USA sales receipts using a prebuilt model. - + ```java String receiptSourceUrl = "https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/media" + "/contoso-allinone.jpg"; @@ -219,11 +219,11 @@ receiptPageResults.forEach(recognizedReceipt -> { Train a machine-learned model on your own form type. The resulting model will be able to recognize values from the types of forms it was trained on. Provide a container SAS url to your Azure Storage Blob container where you're storing the training documents. See details on setting this up in the [service quickstart documentation][quickstart_training]. - + ```java -String trainingSetSource = "{unlabeled_training_set_SAS_URL}"; +String trainingFilesUrl = "{training_set_SAS_URL}"; SyncPoller trainingPoller = - formTrainingClient.beginTraining(trainingSetSource, false); + formTrainingClient.beginTraining(trainingFilesUrl, false); CustomFormModel customFormModel = trainingPoller.getFinalResult(); @@ -246,13 +246,13 @@ customFormModel.getSubModels().forEach(customFormSubModel -> { ### Manage your models Manage the custom models attached to your account. - + ```java AtomicReference modelId = new AtomicReference<>(); // First, we see how many custom models we have, and what our limit is AccountProperties accountProperties = formTrainingClient.getAccountProperties(); System.out.printf("The account has %s custom models, and we can have at most %s custom models", - accountProperties.getCount(), accountProperties.getLimit()); + accountProperties.getCustomModelCount(), accountProperties.getCustomModelLimit()); // Next, we get a paged list of all of our custom models PagedIterable customModels = formTrainingClient.getModelInfos(); @@ -288,7 +288,7 @@ to provide an invalid file source URL an `ErrorResponseException` would be raise In the following code snippet, the error is handled gracefully by catching the exception and display the additional information about the error. - + ```java try { formRecognizerClient.beginRecognizeContentFromUrl("invalidSourceUrl"); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java index 502d170ae7dc..8eee174560ab 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java @@ -15,6 +15,7 @@ import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java index 6956d6318514..eaa81a1102e1 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerClient.java @@ -9,6 +9,7 @@ import com.azure.ai.formrecognizer.models.OperationResult; import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.models.RecognizedReceipt; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java index c5fd9952ca3d..9391fb276be5 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java @@ -34,10 +34,11 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.function.BiConsumer; import java.util.regex.Pattern; import java.util.stream.Collectors; +import static com.azure.ai.formrecognizer.implementation.Utility.forEachWithIndex; + /** * Helper class to convert service level models to SDK exposed models. */ @@ -159,18 +160,6 @@ static List toRecognizedLayout(AnalyzeResult analyzeResult, boolean in return formPages; } - /** - * Given an iterable will apply the indexing function to it and return the index and each item of the iterable. - * - * @param iterable the list to apply the mapping function to. - * @param biConsumer the function which accepts the index and the each value of the iterable. - * @param the type of items being returned. - */ - static void forEachWithIndex(Iterable iterable, BiConsumer biConsumer) { - int[] index = new int[]{0}; - iterable.forEach(element -> biConsumer.accept(index[0]++, element)); - } - /** * Helper method to get per-page table information. * diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/Utility.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/Utility.java index ae3459e9aacb..e5c4ac58cfb0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/Utility.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/Utility.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import java.util.function.BiConsumer; /** * Utility method class. @@ -26,7 +27,7 @@ private Utility() { /** * Automatically detect byte buffer's content type. - * + *

* Given the source: . * * @param buffer The byte buffer input. @@ -35,8 +36,8 @@ private Utility() { */ public static Mono detectContentType(Flux buffer) { byte[] header = new byte[4]; - int[] written = new int[] {0}; - ContentType[] contentType = { ContentType.fromString("none")}; + int[] written = new int[]{0}; + ContentType[] contentType = {ContentType.fromString("none")}; return buffer.map(chunk -> { final int len = chunk.remaining(); for (int i = 0; i < len; i++) { @@ -61,15 +62,15 @@ public static Mono detectContentType(Flux buffer) { // current chunk don't have enough bytes so return true to get next Chunk if there is one. return true; }) - .takeWhile(doContinue -> doContinue) - .then(Mono.defer(() -> { - if (contentType[0] != null) { - return Mono.just(contentType[0]); - } else { - return Mono.error(new RuntimeException("Content type could not be detected. " - + "Should use other overload API that takes content type.")); - } - })); + .takeWhile(doContinue -> doContinue) + .then(Mono.defer(() -> { + if (contentType[0] != null) { + return Mono.just(contentType[0]); + } else { + return Mono.error(new RuntimeException("Content type could not be detected. " + + "Should use other overload API that takes content type.")); + } + })); } private static boolean isJpeg(byte[] header) { @@ -85,7 +86,7 @@ private static boolean isPdf(byte[] header) { private static boolean isPng(byte[] header) { return header[0] == (byte) 0x89 - && header[1] == (byte) 0x50 + && header[1] == (byte) 0x50 && header[2] == (byte) 0x4e && header[3] == (byte) 0x47; } @@ -107,6 +108,7 @@ private static boolean isTiff(byte[] header) { * InputStream. * * @param inputStream InputStream to back the Flux + * * @return Flux of ByteBuffer backed by the InputStream */ public static Flux toFluxByteBuffer(InputStream inputStream) { @@ -132,6 +134,37 @@ public static Flux toFluxByteBuffer(InputStream inputStream) { .cache(); } + /** + * Extracts the result ID from the URL. + * + * @param operationLocation The URL specified in the 'Operation-Location' response header containing the + * resultId used to track the progress and obtain the result of the analyze operation. + * + * @return The resultId used to track the progress. + */ + public static String parseModelId(String operationLocation) { + if (!CoreUtils.isNullOrEmpty(operationLocation)) { + int lastIndex = operationLocation.lastIndexOf('/'); + if (lastIndex != -1) { + return operationLocation.substring(lastIndex + 1); + } + } + throw LOGGER.logExceptionAsError( + new RuntimeException("Failed to parse operation header for result Id from: " + operationLocation)); + } + + /** + * Given an iterable will apply the indexing function to it and return the index and each item of the iterable. + * + * @param iterable the list to apply the mapping function to. + * @param biConsumer the function which accepts the index and the each value of the iterable. + * @param the type of items being returned. + */ + public static void forEachWithIndex(Iterable iterable, BiConsumer biConsumer) { + int[] index = new int[]{0}; + iterable.forEach(element -> biConsumer.accept(index[0]++, element)); + } + private static class Pair { private ByteBuffer byteBuffer; private int readBytes; @@ -154,23 +187,4 @@ Pair readBytes(int cnt) { return this; } } - - /** - * Extracts the result ID from the URL. - * - * @param operationLocation The URL specified in the 'Operation-Location' response header containing the - * resultId used to track the progress and obtain the result of the analyze operation. - * - * @return The resultId used to track the progress. - */ - public static String parseModelId(String operationLocation) { - if (!CoreUtils.isNullOrEmpty(operationLocation)) { - int lastIndex = operationLocation.lastIndexOf('/'); - if (lastIndex != -1) { - return operationLocation.substring(lastIndex + 1); - } - } - throw LOGGER.logExceptionAsError( - new RuntimeException("Failed to parse operation header for result Id from: " + operationLocation)); - } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/AccountProperties.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/AccountProperties.java index 3dd5f0867f40..76311cc810f2 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/AccountProperties.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/AccountProperties.java @@ -14,22 +14,22 @@ public final class AccountProperties { /* * The current count of trained custom models. */ - private final int count; + private final int customModelCount; /* * Max number of models that can be trained for this account. */ - private final int limit; + private final int customModelLimit; /** * Constructs an AccountProperties object. * - * @param count The current count of trained custom models. - * @param limit Max number of models that can be trained for this account. + * @param customModelCount The current count of trained custom models. + * @param customModelLimit Max number of models that can be trained for this account. */ - public AccountProperties(final int count, final int limit) { - this.count = count; - this.limit = limit; + public AccountProperties(final int customModelCount, final int customModelLimit) { + this.customModelCount = customModelCount; + this.customModelLimit = customModelLimit; } /** @@ -37,8 +37,8 @@ public AccountProperties(final int count, final int limit) { * * @return the count value. */ - public int getCount() { - return this.count; + public int getCustomModelCount() { + return this.customModelCount; } /** @@ -47,7 +47,7 @@ public int getCount() { * * @return the limit value. */ - public int getLimit() { - return this.limit; + public int getCustomModelLimit() { + return this.customModelLimit; } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/TrainModelOptions.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/TrainModelOptions.java new file mode 100644 index 000000000000..2cf2d9ec8f43 --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/TrainModelOptions.java @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.formrecognizer.models; + +import com.azure.core.annotation.Fluent; + +/** + * The TrainModelOptions model. + */ +@Fluent +public final class TrainModelOptions { + + /* + * A case-sensitive prefix string to filter documents in the source path + * for training. + */ + private String prefix; + + /* + * A flag to indicate if sub folders within the set of prefix folders will + * also need to be included when searching for content to be preprocessed. + */ + private boolean includeSubFolders; + + /** + * Get the case-sensitive prefix string to filter + * documents in the source path for training. + * + * @return the prefix value. + */ + public String getPrefix() { + return this.prefix; + } + + /** + * Set the case-sensitive prefix string to filter documents in the source path for training. + * + * @param prefix the prefix value to set. + * @return the TrainModelOptions object itself. + */ + public TrainModelOptions setPrefix(String prefix) { + this.prefix = prefix; + return this; + } + + /** + * Get the flag to indicate if sub folders within the set of prefix folders will also need to be included when + * searching for content to be preprocessed. + * + * @return the includeSubFolders value. + */ + public Boolean isIncludeSubFolders() { + return this.includeSubFolders; + } + + /** + * Set the includeSubFolders flag to indicate if sub folders are also to be included when + * searching for content to be preprocessed. + * + * @param includeSubFolders the includeSubFolders value to set. + * @return the TrainModelOptions object itself. + */ + public TrainModelOptions setIncludeSubFolders(boolean includeSubFolders) { + this.includeSubFolders = includeSubFolders; + return this; + } +} diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/CustomModelTransforms.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/CustomModelTransforms.java similarity index 96% rename from sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/CustomModelTransforms.java rename to sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/CustomModelTransforms.java index 5a3c8d395d87..98e4d9012974 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/CustomModelTransforms.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/CustomModelTransforms.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.ai.formrecognizer; +package com.azure.ai.formrecognizer.training; import com.azure.ai.formrecognizer.implementation.models.Model; import com.azure.ai.formrecognizer.implementation.models.ModelInfo; @@ -19,6 +19,7 @@ import com.azure.core.util.IterableStream; import com.azure.core.util.logging.ClientLogger; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -26,13 +27,14 @@ import java.util.TreeMap; import java.util.stream.Collectors; -import static com.azure.ai.formrecognizer.Transforms.forEachWithIndex; +import static com.azure.ai.formrecognizer.implementation.Utility.forEachWithIndex; /** * Helper class to convert service level custom form related models to SDK exposed models. */ final class CustomModelTransforms { private static final ClientLogger LOGGER = new ClientLogger(CustomModelTransforms.class); + static final Duration DEFAULT_DURATION = Duration.ofSeconds(5); private CustomModelTransforms() { } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormTrainingAsyncClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java similarity index 83% rename from sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormTrainingAsyncClient.java rename to sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java index ffb6e68a2189..06939755cac7 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormTrainingAsyncClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingAsyncClient.java @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.ai.formrecognizer; +package com.azure.ai.formrecognizer.training; +import com.azure.ai.formrecognizer.FormRecognizerAsyncClient; +import com.azure.ai.formrecognizer.FormRecognizerClientBuilder; +import com.azure.ai.formrecognizer.FormRecognizerServiceVersion; import com.azure.ai.formrecognizer.implementation.FormRecognizerClientImpl; import com.azure.ai.formrecognizer.implementation.models.Model; import com.azure.ai.formrecognizer.implementation.models.TrainRequest; @@ -11,6 +14,7 @@ import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.CustomFormModelInfo; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.models.TrainModelOptions; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; @@ -35,10 +39,10 @@ import java.util.UUID; import java.util.function.Function; -import static com.azure.ai.formrecognizer.CustomModelTransforms.toCustomFormModel; -import static com.azure.ai.formrecognizer.CustomModelTransforms.toCustomFormModelInfo; -import static com.azure.ai.formrecognizer.FormRecognizerClientBuilder.DEFAULT_DURATION; import static com.azure.ai.formrecognizer.implementation.Utility.parseModelId; +import static com.azure.ai.formrecognizer.training.CustomModelTransforms.DEFAULT_DURATION; +import static com.azure.ai.formrecognizer.training.CustomModelTransforms.toCustomFormModel; +import static com.azure.ai.formrecognizer.training.CustomModelTransforms.toCustomFormModelInfo; import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; @@ -49,7 +53,7 @@ * subscription account information. * *

Instantiating an asynchronous Form Training Client

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.initialization} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.initialization} * * @see FormRecognizerClientBuilder * @see FormRecognizerAsyncClient @@ -68,7 +72,9 @@ public class FormTrainingAsyncClient { * @param service The proxy service used to perform REST calls. * @param serviceVersion The versions of Azure Form Recognizer supported by this client library. */ - FormTrainingAsyncClient(FormRecognizerClientImpl service, FormRecognizerServiceVersion serviceVersion) { + // TODO (savaity): Should not be a public constructor, still deciding the best approach here, + // to be redone in #10909 + public FormTrainingAsyncClient(FormRecognizerClientImpl service, FormRecognizerServiceVersion serviceVersion) { this.service = service; this.serviceVersion = serviceVersion; } @@ -91,18 +97,19 @@ public FormRecognizerServiceVersion getServiceVersion() { * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.beginTraining#string-boolean} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.beginTraining#string-boolean} * - * @param fileSourceUrl source URL parameter that is either an externally accessible Azure + * @param trainingFilesUrl source URL parameter that is either an externally accessible Azure * storage blob container Uri (preferably a Shared Access Signature Uri). - * @param useLabelFile Boolean to specify the use of labeled files for training the model. + * @param useTrainingLabels Boolean to specify the use of labeled files for training the model. * * @return A {@link PollerFlux} that polls the training model operation until it has completed, has failed, or has * been cancelled. */ @ServiceMethod(returns = ReturnType.SINGLE) - public PollerFlux beginTraining(String fileSourceUrl, boolean useLabelFile) { - return beginTraining(fileSourceUrl, useLabelFile, false, null, null); + public PollerFlux beginTraining(String trainingFilesUrl, + boolean useTrainingLabels) { + return beginTraining(trainingFilesUrl, useTrainingLabels, null, null); } /** @@ -115,16 +122,12 @@ public PollerFlux beginTraining(String fileSou * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.beginTraining#string-boolean-boolean-string-Duration} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.beginTraining#string-boolean-trainModelOptions-Duration} * - * @param fileSourceUrl source URL parameter that is either an externally accessible Azure - * storage blob container Uri (preferably a Shared Access Signature Uri). - * @param useLabelFile Boolean to specify the use of labeled files for training the model. - * @param includeSubFolders to indicate if sub folders within the set of prefix folders will - * also need to be included when searching for content to be preprocessed. - * @param filePrefix A case-sensitive prefix string to filter documents in the source path - * for training. For example, when using a Azure storage blob Uri, use the prefix to restrict - * sub folders for training. + * @param trainingFilesUrl an externally accessible Azure storage blob container Uri (preferably a + * Shared Access Signature Uri). + * @param useTrainingLabels Boolean to specify the use of labeled files for training the model. + * @param trainModelOptions Filter to apply to the documents in the source path for training. * @param pollInterval Duration between each poll for the operation status. If none is specified, a default of * 5 seconds is used. * @@ -132,12 +135,15 @@ public PollerFlux beginTraining(String fileSou * has completed, has failed, or has been cancelled. */ @ServiceMethod(returns = ReturnType.SINGLE) - public PollerFlux beginTraining(String fileSourceUrl, - boolean useLabelFile, boolean includeSubFolders, String filePrefix, Duration pollInterval) { + public PollerFlux beginTraining(String trainingFilesUrl, + boolean useTrainingLabels, TrainModelOptions trainModelOptions, Duration pollInterval) { final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; return new PollerFlux( interval, - getTrainingActivationOperation(fileSourceUrl, includeSubFolders, filePrefix, useLabelFile), + getTrainingActivationOperation(trainingFilesUrl, + trainModelOptions != null ? trainModelOptions.isIncludeSubFolders() : false, + trainModelOptions != null ? trainModelOptions.getPrefix() : null, + useTrainingLabels), createTrainingPollOperation(), (activationResponse, context) -> Mono.error(new RuntimeException("Cancellation is not supported")), fetchTrainingModelResultOperation()); @@ -147,7 +153,7 @@ public PollerFlux beginTraining(String fileSou * Get detailed information for a specified custom model id. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.getCustomModel#string} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getCustomModel#string} * * @param modelId The UUID string format model identifier. * @@ -162,7 +168,7 @@ public Mono getCustomModel(String modelId) { * Get detailed information for a specified custom model id with Http response * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.getCustomModelWithResponse#string} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getCustomModelWithResponse#string} * * @param modelId The UUID string format model identifier. * @@ -187,7 +193,7 @@ Mono> getCustomModelWithResponse(String modelId, Conte * Get account information for all custom models. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.getAccountProperties} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getAccountProperties} * * @return The account information. */ @@ -200,7 +206,7 @@ public Mono getAccountProperties() { * Get account information. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.getAccountPropertiesWithResponse} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getAccountPropertiesWithResponse} * * @return A {@link Response} containing the requested account information details. */ @@ -224,7 +230,7 @@ Mono> getAccountPropertiesWithResponse(Context conte * Deletes the specified custom model. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.deleteModel#string} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.deleteModel#string} * * @param modelId The UUID string format model identifier. * @@ -239,7 +245,7 @@ public Mono deleteModel(String modelId) { * Deletes the specified custom model. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.deleteModelWithResponse#string} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.deleteModelWithResponse#string} * * @param modelId The UUID string format model identifier. * @@ -265,7 +271,7 @@ Mono> deleteModelWithResponse(String modelId, Context context) { * List information for all models. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingAsyncClient.getModelInfos} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getModelInfos} * * @return {@link PagedFlux} of {@link CustomFormModelInfo}. */ @@ -352,14 +358,14 @@ private Function, Mono> fetchTr } private Function, Mono> getTrainingActivationOperation( - String fileSourceUrl, boolean includeSubFolders, String filePrefix, boolean useLabelFile) { + String fileSourceUrl, boolean includeSubFolders, String filePrefix, boolean useTrainingLabels) { return (pollingContext) -> { try { Objects.requireNonNull(fileSourceUrl, "'fileSourceUrl' cannot be null."); TrainSourceFilter trainSourceFilter = new TrainSourceFilter().setIncludeSubFolders(includeSubFolders) .setPrefix(filePrefix); TrainRequest serviceTrainRequest = new TrainRequest().setSource(fileSourceUrl). - setSourceFilter(trainSourceFilter).setUseLabelFile(useLabelFile); + setSourceFilter(trainSourceFilter).setUseLabelFile(useTrainingLabels); return service.trainCustomModelAsyncWithResponseAsync(serviceTrainRequest) .map(response -> new OperationResult(parseModelId(response.getDeserializedHeaders().getLocation()))); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormTrainingClient.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java similarity index 70% rename from sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormTrainingClient.java rename to sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java index c929b695c432..4e86c083bfb5 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormTrainingClient.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/FormTrainingClient.java @@ -1,12 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.ai.formrecognizer; +package com.azure.ai.formrecognizer.training; +import com.azure.ai.formrecognizer.FormRecognizerAsyncClient; +import com.azure.ai.formrecognizer.FormRecognizerClient; +import com.azure.ai.formrecognizer.FormRecognizerClientBuilder; import com.azure.ai.formrecognizer.models.AccountProperties; import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.CustomFormModelInfo; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.models.TrainModelOptions; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; @@ -20,11 +24,11 @@ /** * This class provides a synchronous client that contains model management the operations that apply * to Azure Form Recognizer. - * Operations allowed by the client are, to creating, training of custom models, delete models, list models and get + * Operations allowed by the client are creating, training of custom models, deleting models, listing models and getting * subscription account information. * *

Instantiating a synchronous Form Training Client

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.initialization} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.initialization} * * @see FormRecognizerClientBuilder * @see FormRecognizerClient @@ -40,19 +44,11 @@ public class FormTrainingClient { * * @param formTrainingAsyncClient The {@link FormRecognizerAsyncClient} that the client routes its request through. */ - FormTrainingClient(FormTrainingAsyncClient formTrainingAsyncClient) { + // TODO (savaity): Still deciding the best approach here, to be redone in #10909 + public FormTrainingClient(FormTrainingAsyncClient formTrainingAsyncClient) { this.client = formTrainingAsyncClient; } - /** - * Gets the service version the client is using. - * - * @return the service version the client is using. - */ - public FormRecognizerServiceVersion getServiceVersion() { - return client.getServiceVersion(); - } - /** * Create and train a custom model. *

Models are trained using documents that are of the following content @@ -63,18 +59,19 @@ public FormRecognizerServiceVersion getServiceVersion() { * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.beginTraining#string-boolean} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean} * - * @param fileSourceUrl source URL parameter that is either an externally accessible - * Azure storage blob container Uri (preferably a Shared Access Signature Uri). - * @param useLabelFile Boolean to specify the use of labeled files for training the model. + * @param trainingFilesUrl an externally accessible Azure storage blob container Uri (preferably a Shared Access + * Signature Uri). + * @param useTrainingLabels Boolean to specify the use of labeled files for training the model. * * @return A {@link SyncPoller} that polls the training model operation until it has completed, has failed, or has * been cancelled. */ @ServiceMethod(returns = ReturnType.SINGLE) - public SyncPoller beginTraining(String fileSourceUrl, boolean useLabelFile) { - return beginTraining(fileSourceUrl, useLabelFile, false, null, null); + public SyncPoller beginTraining(String trainingFilesUrl, + boolean useTrainingLabels) { + return beginTraining(trainingFilesUrl, useTrainingLabels, null, null); } /** @@ -86,16 +83,12 @@ public SyncPoller beginTraining(String fileSou * error message indicating absence of cancellation support.

* *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.beginTraining#string-boolean-boolean-string-Duration} - * - * @param fileSourceUrl source URL parameter that is either an externally accessible Azure storage - * blob container Uri (preferably a Shared Access Signature Uri). - * @param useLabelFile Boolean to specify the use of labeled files for training the model. - * @param includeSubFolders to indicate if sub folders within the set of prefix folders will - * also need to be included when searching for content to be preprocessed. - * @param filePrefix A case-sensitive prefix string to filter documents in the source path - * for training. For example, when using a Azure storage blob Uri, use the prefix to restrict - * sub folders for training. + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainModelOptions-Duration} + * + * @param trainingFilesUrl an externally accessible Azure storage blob container Uri (preferably a + * Shared Access Signature Uri). + * @param useTrainingLabels Boolean to specify the use of labeled files for training the model. + * @param trainModelOptions Filter to apply to the documents in the source path for training. * @param pollInterval Duration between each poll for the operation status. If none is specified, a default of * 5 seconds is used. * @@ -103,17 +96,17 @@ public SyncPoller beginTraining(String fileSou * has completed, has failed, or has been cancelled. */ @ServiceMethod(returns = ReturnType.SINGLE) - public SyncPoller beginTraining(String fileSourceUrl, boolean useLabelFile, - boolean includeSubFolders, String filePrefix, Duration pollInterval) { - return client.beginTraining(fileSourceUrl, useLabelFile, includeSubFolders, - filePrefix, pollInterval).getSyncPoller(); + public SyncPoller beginTraining(String trainingFilesUrl, + boolean useTrainingLabels, TrainModelOptions trainModelOptions, Duration pollInterval) { + return client.beginTraining(trainingFilesUrl, useTrainingLabels, trainModelOptions, pollInterval) + .getSyncPoller(); } /** * Get detailed information for a specified custom model id. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.getCustomModel#string} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.getCustomModel#string} * * @param modelId The UUID string format model identifier. * @@ -128,7 +121,7 @@ public CustomFormModel getCustomModel(String modelId) { * Get detailed information for a specified custom model id. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.getCustomModelWithResponse#string-Context} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.getCustomModelWithResponse#string-Context} * * @param modelId The UUID string format model identifier. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -144,7 +137,7 @@ public Response getCustomModelWithResponse(String modelId, Cont * Get account information for all custom models. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.getAccountProperties} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.getAccountProperties} * * @return The account information. */ @@ -157,7 +150,7 @@ public AccountProperties getAccountProperties() { * Get account information for all custom models. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.getAccountPropertiesWithResponse#Context} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.getAccountPropertiesWithResponse#Context} * * @param context Additional context that is passed through the Http pipeline during the service call. * @@ -172,7 +165,7 @@ public Response getAccountPropertiesWithResponse(Context cont * Deletes the specified custom model. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.deleteModel#string} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.deleteModel#string} * * @param modelId The UUID string format model identifier. */ @@ -185,7 +178,7 @@ public void deleteModel(String modelId) { * Deletes the specified custom model. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.deleteModelWithResponse#string-Context} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.deleteModelWithResponse#string-Context} * * @param modelId The UUID string format model identifier. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -201,7 +194,7 @@ public Response deleteModelWithResponse(String modelId, Context context) { * List information for all models. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.getModelInfos} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.getModelInfos} * * @return {@link PagedIterable} of {@link CustomFormModelInfo} custom form model information. */ @@ -214,9 +207,10 @@ public PagedIterable getModelInfos() { * List information for all models with taking {@link Context}. * *

Code sample

- * {@codesnippet com.azure.ai.formrecognizer.FormTrainingClient.getModelInfos#Context} + * {@codesnippet com.azure.ai.formrecognizer.training.FormTrainingClient.getModelInfos#Context} * * @param context Additional context that is passed through the Http pipeline during the service call. + * * @return {@link PagedIterable} of {@link CustomFormModelInfo} custom form model information. */ @ServiceMethod(returns = ReturnType.COLLECTION) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/package-info.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/package-info.java new file mode 100644 index 000000000000..9a515b611e3e --- /dev/null +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Package containing form recognizer training clients for Azure Form Recognizer. + */ +package com.azure.ai.formrecognizer.training; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientJavaDocCodeSnippets.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientJavaDocCodeSnippets.java index a31f69b80f00..980512c09434 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientJavaDocCodeSnippets.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientJavaDocCodeSnippets.java @@ -5,6 +5,8 @@ import com.azure.ai.formrecognizer.models.AccountProperties; import com.azure.ai.formrecognizer.models.CustomFormModel; +import com.azure.ai.formrecognizer.models.TrainModelOptions; +import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import java.time.Duration; @@ -19,20 +21,20 @@ public class FormTrainingAsyncClientJavaDocCodeSnippets { * Code snippet for {@link FormTrainingAsyncClient} initialization */ public void formTrainingAsyncClientInInitialization() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.initialization + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.initialization FormTrainingAsyncClient formTrainingAsyncClient = new FormRecognizerClientBuilder().buildAsyncClient() .getFormTrainingAsyncClient(); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.initialization + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.initialization } /** - * Code snippet for {@link FormTrainingAsyncClient#beginTraining} + * Code snippet for {@link FormTrainingAsyncClient#beginTraining(String, boolean)} */ public void beginTraining() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.beginTraining#string-boolean - String trainingSetSource = "{training-set-SAS-URL}"; - boolean useLabelFile = true; - formTrainingAsyncClient.beginTraining(trainingSetSource, useLabelFile).subscribe( + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.beginTraining#string-boolean + String trainingFilesUrl = "{training-set-SAS-URL}"; + boolean useTrainingLabels = true; + formTrainingAsyncClient.beginTraining(trainingFilesUrl, useTrainingLabels).subscribe( recognizePollingOperation -> { // if training polling operation completed, retrieve the final result. recognizePollingOperation.getFinalResult().subscribe(customFormModel -> { @@ -44,20 +46,19 @@ public void beginTraining() { key, customFormModelField.getName(), customFormModelField.getAccuracy()))); }); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.beginTraining#string-boolean + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.beginTraining#string-boolean } /** - * Code snippet for {@link FormTrainingAsyncClient#beginTraining} with options + * Code snippet for {@link FormTrainingAsyncClient#beginTraining(String, boolean, TrainModelOptions, Duration)} + * with options */ public void beginTrainingWithOptions() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.beginTraining#string-boolean-boolean-string-Duration - String trainingSetSource = "{training-set-SAS-URL}"; - boolean isIncludeSubFolders = false; // {is-include-subfolders} - String filePrefix = "{file-prefix}"; - boolean useLabelFile = true; + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.beginTraining#string-boolean-trainModelOptions-Duration + String trainingFilesUrl = "{training-set-SAS-URL}"; + TrainModelOptions trainModelOptions = new TrainModelOptions().setIncludeSubFolders(false).setPrefix("Invoice"); - formTrainingAsyncClient.beginTraining(trainingSetSource, useLabelFile, isIncludeSubFolders, filePrefix, + formTrainingAsyncClient.beginTraining(trainingFilesUrl, true, trainModelOptions, Duration.ofSeconds(5)).subscribe(recognizePollingOperation -> { // if training polling operation completed, retrieve the final result. recognizePollingOperation.getFinalResult().subscribe(customFormModel -> { @@ -69,14 +70,14 @@ public void beginTrainingWithOptions() { key, customFormModelField.getName(), customFormModelField.getAccuracy()))); }); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.beginTraining#string-boolean-boolean-string-Duration + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.beginTraining#string-boolean-trainModelOptions-Duration } /** - * Code snippet for {@link FormTrainingAsyncClient#getCustomModel} + * Code snippet for {@link FormTrainingAsyncClient#getCustomModel(String)} */ public void getCustomModel() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getCustomModel#string + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getCustomModel#string String modelId = "{model_id}"; formTrainingAsyncClient.getCustomModel(modelId).subscribe(customFormModel -> { System.out.printf("Model Id: %s%n", customFormModel.getModelId()); @@ -87,14 +88,14 @@ public void getCustomModel() { key, customFormModelField.getName(), customFormModelField.getAccuracy()))); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getCustomModel#string + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getCustomModel#string } /** - * Code snippet for {@link FormTrainingAsyncClient#getCustomModelWithResponse} + * Code snippet for {@link FormTrainingAsyncClient#getCustomModelWithResponse(String)} */ public void getCustomModelWithResponse() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getCustomModelWithResponse#string + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getCustomModelWithResponse#string String modelId = "{model_id}"; formTrainingAsyncClient.getCustomModelWithResponse(modelId).subscribe(response -> { System.out.printf("Response Status Code: %d.", response.getStatusCode()); @@ -106,72 +107,72 @@ public void getCustomModelWithResponse() { System.out.printf("Form Type: %s Field Text: %s Field Accuracy: %s%n", key, customFormModelField.getName(), customFormModelField.getAccuracy()))); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getCustomModelWithResponse#string + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getCustomModelWithResponse#string } /** - * Code snippet for {@link FormTrainingAsyncClient#getAccountProperties} + * Code snippet for {@link FormTrainingAsyncClient#getAccountProperties()} */ public void getAccountProperties() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getAccountProperties + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getAccountProperties formTrainingAsyncClient.getAccountProperties().subscribe(accountProperties -> { System.out.printf("Max number of models that can be trained for this account: %s%n", - accountProperties.getLimit()); - System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCount()); + accountProperties.getCustomModelLimit()); + System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCustomModelCount()); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getAccountProperties + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getAccountProperties } /** - * Code snippet for {@link FormTrainingAsyncClient#getAccountPropertiesWithResponse} + * Code snippet for {@link FormTrainingAsyncClient#getAccountPropertiesWithResponse()} */ public void getAccountPropertiesWithResponse() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getAccountPropertiesWithResponse + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getAccountPropertiesWithResponse formTrainingAsyncClient.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 trained for this account: %s%n", - accountProperties.getLimit()); - System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCount()); + accountProperties.getCustomModelLimit()); + System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCustomModelCount()); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getAccountPropertiesWithResponse + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getAccountPropertiesWithResponse } /** * Code snippet for {@link FormTrainingAsyncClient#deleteModel} */ public void deleteModel() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.deleteModel#string + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.deleteModel#string String modelId = "{model_id}"; formTrainingAsyncClient.deleteModel(modelId).subscribe(val -> System.out.printf("Model Id: %s is deleted%n", modelId)); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.deleteModel#string + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.deleteModel#string } /** - * Code snippet for {@link FormTrainingAsyncClient#deleteModelWithResponse} + * Code snippet for {@link FormTrainingAsyncClient#deleteModelWithResponse(String)} */ public void deleteModelWithResponse() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.deleteModelWithResponse#string + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.deleteModelWithResponse#string String modelId = "{model_id}"; formTrainingAsyncClient.deleteModelWithResponse(modelId).subscribe(response -> { System.out.printf("Response Status Code: %d.", response.getStatusCode()); System.out.printf("Model Id: %s is deleted%n", modelId); }); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.deleteModelWithResponse#string + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.deleteModelWithResponse#string } /** - * Code snippet for {@link FormTrainingAsyncClient#getModelInfos} + * Code snippet for {@link FormTrainingAsyncClient#getModelInfos()} */ public void getModelInfos() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getModelInfos + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getModelInfos formTrainingAsyncClient.getModelInfos().subscribe(customModel -> System.out.printf("Model Id: %s, Model status: %s, Created on: %s, Last updated on: %s.%n", customModel.getModelId(), customModel.getStatus(), customModel.getCreatedOn(), customModel.getLastUpdatedOn())); - // END: com.azure.ai.formrecognizer.FormTrainingAsyncClient.getModelInfos + // END: com.azure.ai.formrecognizer.training.FormTrainingAsyncClient.getModelInfos } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java index 1b89116c109a..da85da1eb44d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/FormTrainingClientJavaDocCodeSnippets.java @@ -5,6 +5,8 @@ import com.azure.ai.formrecognizer.models.AccountProperties; import com.azure.ai.formrecognizer.models.CustomFormModel; +import com.azure.ai.formrecognizer.models.TrainModelOptions; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; @@ -21,42 +23,42 @@ public class FormTrainingClientJavaDocCodeSnippets { * Code snippet for {@link FormTrainingClient} initialization */ public void formTrainingClientInInitialization() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.initialization + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.initialization FormTrainingClient formTrainingClient = new FormRecognizerClientBuilder().buildClient() .getFormTrainingClient(); - // END: com.azure.ai.formrecognizer.FormTrainingClient.initialization + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.initialization } /** - * Code snippet for {@link FormTrainingClient#beginTraining} + * Code snippet for {@link FormTrainingClient#beginTraining(String, boolean)} */ public void beginTraining() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.beginTraining#string-boolean - String trainingSetSource = "{training-set-SAS-URL}"; - boolean useLabelFile = true; + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean + String trainingFilesUrl = "{training-set-SAS-URL}"; + boolean useTrainingLabels = true; CustomFormModel customFormModel = - formTrainingClient.beginTraining(trainingSetSource, useLabelFile).getFinalResult(); + formTrainingClient.beginTraining(trainingFilesUrl, useTrainingLabels).getFinalResult(); System.out.printf("Model Id: %s%n", customFormModel.getModelId()); System.out.printf("Model Status: %s%n", customFormModel.getModelStatus()); customFormModel.getSubModels().forEach(customFormSubModel -> customFormSubModel.getFieldMap().forEach((key, customFormModelField) -> System.out.printf("Form Type: %s Field Text: %s Field Accuracy: %s%n", key, customFormModelField.getName(), customFormModelField.getAccuracy()))); - // END: com.azure.ai.formrecognizer.FormTrainingClient.beginTraining#string-boolean + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean } /** - * Code snippet for {@link FormTrainingClient#beginTraining} with options + * Code snippet for {@link FormTrainingClient#beginTraining(String, boolean, TrainModelOptions, Duration)} + * with options */ public void beginTrainingWithOptions() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.beginTraining#string-boolean-boolean-string-Duration - String trainingSetSource = "{training-set-SAS-URL}"; - boolean isIncludeSubFolders = false; // {is-include-subfolders} - String filePrefix = "{file-prefix}"; - boolean useLabelFile = true; + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainModelOptions-Duration + String trainingFilesUrl = "{training-set-SAS-URL}"; + TrainModelOptions trainModelOptions = new TrainModelOptions().setIncludeSubFolders(false).setPrefix("Invoice"); + boolean useTrainingLabels = true; - CustomFormModel customFormModel = formTrainingClient.beginTraining( - trainingSetSource, useLabelFile, isIncludeSubFolders, filePrefix, Duration.ofSeconds(5)).getFinalResult(); + CustomFormModel customFormModel = formTrainingClient.beginTraining(trainingFilesUrl, useTrainingLabels, + trainModelOptions, Duration.ofSeconds(5)).getFinalResult(); System.out.printf("Model Id: %s%n", customFormModel.getModelId()); System.out.printf("Model Status: %s%n", customFormModel.getModelStatus()); @@ -64,14 +66,14 @@ public void beginTrainingWithOptions() { customFormSubModel.getFieldMap().forEach((key, customFormModelField) -> System.out.printf("Form Type: %s Field Text: %s Field Accuracy: %s%n", key, customFormModelField.getName(), customFormModelField.getAccuracy()))); - // END: com.azure.ai.formrecognizer.FormTrainingClient.beginTraining#string-boolean-boolean-string-Duration + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.beginTraining#string-boolean-trainModelOptions-Duration } /** - * Code snippet for {@link FormTrainingClient#getCustomModel} + * Code snippet for {@link FormTrainingClient#getCustomModel(String)} */ public void getCustomModel() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.getCustomModel#string + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.getCustomModel#string String modelId = "{model_id}"; CustomFormModel customFormModel = formTrainingClient.getCustomModel(modelId); System.out.printf("Model Id: %s%n", customFormModel.getModelId()); @@ -80,14 +82,14 @@ public void getCustomModel() { customFormSubModel.getFieldMap().forEach((key, customFormModelField) -> System.out.printf("Form Type: %s Field Text: %s Field Accuracy: %s%n", key, customFormModelField.getName(), customFormModelField.getAccuracy()))); - // END: com.azure.ai.formrecognizer.FormTrainingClient.getCustomModel#string + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.getCustomModel#string } /** - * Code snippet for {@link FormTrainingClient#getCustomModelWithResponse} + * Code snippet for {@link FormTrainingClient#getCustomModelWithResponse(String, Context)} */ public void getCustomModelWithResponse() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.getCustomModelWithResponse#string-Context + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.getCustomModelWithResponse#string-Context String modelId = "{model_id}"; Response response = formTrainingClient.getCustomModelWithResponse(modelId, Context.NONE); System.out.printf("Response Status Code: %d.", response.getStatusCode()); @@ -96,65 +98,65 @@ public void getCustomModelWithResponse() { System.out.printf("Model Status: %s%n", customFormModel.getModelStatus()); customFormModel.getSubModels().forEach(customFormSubModel -> customFormSubModel.getFieldMap().forEach((key, customFormModelField) -> - System.out.printf("Form Type: %s Field Text: %s Field Accuracy: %s%n", + System.out.printf("Field: %s Field Text: %s Field Accuracy: %s%n", key, customFormModelField.getName(), customFormModelField.getAccuracy()))); - // END: com.azure.ai.formrecognizer.FormTrainingClient.getCustomModelWithResponse#string-Context + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.getCustomModelWithResponse#string-Context } /** - * Code snippet for {@link FormTrainingClient#getAccountProperties} + * Code snippet for {@link FormTrainingClient#getAccountProperties()} */ public void getAccountProperties() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.getAccountProperties + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.getAccountProperties AccountProperties accountProperties = formTrainingClient.getAccountProperties(); System.out.printf("Max number of models that can be trained for this account: %s%n", - accountProperties.getLimit()); - System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCount()); - // END: com.azure.ai.formrecognizer.FormTrainingClient.getAccountProperties + accountProperties.getCustomModelLimit()); + System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCustomModelCount()); + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.getAccountProperties } /** - * Code snippet for {@link FormTrainingClient#getAccountPropertiesWithResponse} + * Code snippet for {@link FormTrainingClient#getAccountPropertiesWithResponse(Context)} */ public void getAccountPropertiesWithResponse() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.getAccountPropertiesWithResponse#Context + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.getAccountPropertiesWithResponse#Context Response response = formTrainingClient.getAccountPropertiesWithResponse(Context.NONE); System.out.printf("Response Status Code: %d.", response.getStatusCode()); AccountProperties accountProperties = response.getValue(); System.out.printf("Max number of models that can be trained for this account: %s%n", - accountProperties.getLimit()); - System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCount()); - // END: com.azure.ai.formrecognizer.FormTrainingClient.getAccountPropertiesWithResponse#Context + accountProperties.getCustomModelLimit()); + System.out.printf("Current count of trained custom models: %d%n", accountProperties.getCustomModelCount()); + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.getAccountPropertiesWithResponse#Context } /** - * Code snippet for {@link FormTrainingClient#deleteModel} + * Code snippet for {@link FormTrainingClient#deleteModel(String)} */ public void deleteModel() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.deleteModel#string + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.deleteModel#string String modelId = "{model_id}"; formTrainingClient.deleteModel(modelId); System.out.printf("Model Id: %s is deleted.%n", modelId); - // END: com.azure.ai.formrecognizer.FormTrainingClient.deleteModel#string + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.deleteModel#string } /** - * Code snippet for {@link FormTrainingClient#deleteModelWithResponse} + * Code snippet for {@link FormTrainingClient#deleteModelWithResponse(String, Context)} */ public void deleteModelWithResponse() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.deleteModelWithResponse#string-Context + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.deleteModelWithResponse#string-Context String modelId = "{model_id}"; Response response = formTrainingClient.deleteModelWithResponse(modelId, Context.NONE); System.out.printf("Response Status Code: %d.", response.getStatusCode()); System.out.printf("Model Id: %s is deleted.%n", modelId); - // END: com.azure.ai.formrecognizer.FormTrainingClient.deleteModelWithResponse#string-Context + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.deleteModelWithResponse#string-Context } /** - * Code snippet for {@link FormTrainingClient#getModelInfos} + * Code snippet for {@link FormTrainingClient#getModelInfos()} */ public void getModelInfos() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.getModelInfos + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.getModelInfos formTrainingClient.getModelInfos().forEach(customModel -> System.out.printf("Model Id: %s, Model status: %s, Created on: %s, Last updated on: %s.%n", customModel.getModelId(), @@ -162,14 +164,14 @@ public void getModelInfos() { customModel.getCreatedOn(), customModel.getLastUpdatedOn()) ); - // END: com.azure.ai.formrecognizer.FormTrainingClient.getModelInfos + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.getModelInfos } /** * Code snippet for {@link FormTrainingClient#getModelInfos(Context)} */ public void getModelInfosWithContext() { - // BEGIN: com.azure.ai.formrecognizer.FormTrainingClient.getModelInfos#Context + // BEGIN: com.azure.ai.formrecognizer.training.FormTrainingClient.getModelInfos#Context formTrainingClient.getModelInfos(Context.NONE).forEach(customModel -> System.out.printf("Model Id: %s, Model status: %s, Created on: %s, Last updated on: %s.%n", customModel.getModelId(), @@ -177,6 +179,6 @@ public void getModelInfosWithContext() { customModel.getCreatedOn(), customModel.getLastUpdatedOn()) ); - // END: com.azure.ai.formrecognizer.FormTrainingClient.getModelInfos#Context + // END: com.azure.ai.formrecognizer.training.FormTrainingClient.getModelInfos#Context } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModels.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModels.java index 94140b0527d0..f341079c092e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModels.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModels.java @@ -6,6 +6,7 @@ import com.azure.ai.formrecognizer.models.AccountProperties; import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.CustomFormModelInfo; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.rest.PagedIterable; import com.azure.core.util.Context; @@ -35,7 +36,7 @@ public static void main(final String[] args) { // First, we see how many custom models we have, and what our limit is AccountProperties accountProperties = client.getAccountProperties(); System.out.printf("The account has %s custom models, and we can have at most %s custom models", - accountProperties.getCount(), accountProperties.getLimit()); + accountProperties.getCustomModelCount(), accountProperties.getCustomModelLimit()); // Next, we get a paged list of all of our custom models PagedIterable customModels = client.getModelInfos(); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModelsAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModelsAsync.java index 1c4729c7d5a6..c65c48eb0968 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModelsAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ManageCustomModelsAsync.java @@ -3,6 +3,7 @@ package com.azure.ai.formrecognizer; +import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.credential.AzureKeyCredential; import java.util.concurrent.TimeUnit; @@ -31,7 +32,7 @@ public static void main(final String[] args) { // First, we see how many custom models we have, and what our limit is client.getAccountProperties().subscribe(accountProperties -> System.out.printf("The account has %s custom models, and we can have at most %s custom models.%n", - accountProperties.getCount(), accountProperties.getLimit())); + accountProperties.getCustomModelCount(), accountProperties.getCustomModelLimit())); // Next, we get a paged list of all of our custom models System.out.println("We have following models in the account:"); client.getModelInfos().subscribe(customFormModelInfo -> { diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java index 74e21002bbf4..41658a200146 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java @@ -12,6 +12,7 @@ import com.azure.ai.formrecognizer.models.RecognizedForm; import com.azure.ai.formrecognizer.models.RecognizedReceipt; import com.azure.ai.formrecognizer.models.USReceipt; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.rest.PagedIterable; import com.azure.core.util.IterableStream; @@ -119,9 +120,9 @@ public void recognizeReceipt() { } public void trainModel() { - String trainingSetSource = "{unlabeled_training_set_SAS_URL}"; + String trainingFilesUrl = "{training_set_SAS_URL}"; SyncPoller trainingPoller = - formTrainingClient.beginTraining(trainingSetSource, false); + formTrainingClient.beginTraining(trainingFilesUrl, false); CustomFormModel customFormModel = trainingPoller.getFinalResult(); @@ -147,7 +148,7 @@ public void manageModels() { // First, we see how many custom models we have, and what our limit is AccountProperties accountProperties = formTrainingClient.getAccountProperties(); System.out.printf("The account has %s custom models, and we can have at most %s custom models", - accountProperties.getCount(), accountProperties.getLimit()); + accountProperties.getCustomModelCount(), accountProperties.getCustomModelLimit()); // Next, we get a paged list of all of our custom models PagedIterable customModels = formTrainingClient.getModelInfos(); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java index 8f4a7b711dcd..6cdc48c3f3a7 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceipts.java @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. package com.azure.ai.formrecognizer; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java index 4e871ae1b4af..57504460fd3a 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsAsync.java @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. package com.azure.ai.formrecognizer; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java index 981d0a648218..2e9ce0a1276a 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrl.java @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. package com.azure.ai.formrecognizer; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java index 2d60b2d8b83e..c328af9df3d2 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeReceiptsFromUrlAsync.java @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. package com.azure.ai.formrecognizer; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabels.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabels.java index faef79025a9e..cc1fe3911266 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabels.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabels.java @@ -5,6 +5,7 @@ import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.SyncPoller; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabelsAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabelsAsync.java index 529b7d039f08..b5a0886bcdfc 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabelsAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithLabelsAsync.java @@ -5,6 +5,7 @@ import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.LongRunningOperationStatus; import com.azure.core.util.polling.PollerFlux; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabels.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabels.java index aec502c17e44..d7d23dd33b9e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabels.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabels.java @@ -5,6 +5,7 @@ import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.SyncPoller; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabelsAsync.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabelsAsync.java index 3e5e455c46cf..452b0a5d2638 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabelsAsync.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/TrainModelWithoutLabelsAsync.java @@ -5,6 +5,7 @@ import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.util.polling.LongRunningOperationStatus; import com.azure.core.util.polling.PollerFlux; diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java index 5ebb25723546..07f4bbfdd45b 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java @@ -274,9 +274,9 @@ public void recognizeLayoutInvalidSourceUrl(HttpClient httpClient, FormRecognize public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.getFormTrainingAsyncClient().beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.getFormTrainingAsyncClient().beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); StepVerifier.create(client.beginRecognizeCustomFormsFromUrl(INVALID_URL, createdModel.getModelId())) @@ -291,9 +291,9 @@ public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient, @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); - customFormDataRunner(data -> beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + customFormDataRunner(data -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = - client.getFormTrainingAsyncClient().beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.getFormTrainingAsyncClient().beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = @@ -312,9 +312,9 @@ public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizer public void recognizeCustomFormLabeledDataWithNullValues(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); - customFormDataRunner(data -> beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + customFormDataRunner(data -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.getFormTrainingAsyncClient().beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.getFormTrainingAsyncClient().beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); assertThrows(RuntimeException.class, () -> client.beginRecognizeCustomForms(null, @@ -335,9 +335,9 @@ public void recognizeCustomFormLabeledDataWithNullValues(HttpClient httpClient, public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); - customFormDataRunner(data -> beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + customFormDataRunner(data -> beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = - client.getFormTrainingAsyncClient().beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.getFormTrainingAsyncClient().beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = @@ -355,9 +355,9 @@ public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClien @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void recognizeCustomFormUnlabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerAsyncClient(httpClient, serviceVersion); - customFormDataRunner(data -> beginTrainingUnlabeledRunner((storageSASUrl, useLabelFile) -> { + customFormDataRunner(data -> beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = - client.getFormTrainingAsyncClient().beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.getFormTrainingAsyncClient().beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); trainingPoller.waitForCompletion(); SyncPoller> syncPoller = diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java index 4fa9de3851d1..cea33391e408 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerClientTest.java @@ -217,9 +217,9 @@ public void recognizeLayoutInvalidSourceUrl(HttpClient httpClient, FormRecognize @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.getFormTrainingClient().beginTraining(storageSASUrl, useLabelFile); + client.getFormTrainingClient().beginTraining(trainingFilesUrl, useTrainingLabels); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); @@ -239,9 +239,9 @@ public void recognizeCustomFormInvalidSourceUrl(HttpClient httpClient, FormRecog public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); customFormDataRunner(data -> - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = - client.getFormTrainingClient().beginTraining(storageSASUrl, useLabelFile); + client.getFormTrainingClient().beginTraining(trainingFilesUrl, useTrainingLabels); trainingPoller.waitForCompletion(); SyncPoller> syncPoller @@ -260,9 +260,9 @@ public void recognizeCustomFormLabeledData(HttpClient httpClient, FormRecognizer public void recognizeCustomFormLabeledDataWithNullValues(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); customFormDataRunner(data -> - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.getFormTrainingClient().beginTraining(storageSASUrl, useLabelFile); + client.getFormTrainingClient().beginTraining(trainingFilesUrl, useTrainingLabels); syncPoller.waitForCompletion(); assertThrows(RuntimeException.class, () -> @@ -283,9 +283,9 @@ public void recognizeCustomFormLabeledDataWithNullValues(HttpClient httpClient, @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = - client.getFormTrainingClient().beginTraining(storageSASUrl, useLabelFile); + client.getFormTrainingClient().beginTraining(trainingFilesUrl, useTrainingLabels); trainingPoller.waitForCompletion(); SyncPoller> syncPoller @@ -305,9 +305,9 @@ public void recognizeCustomFormLabeledDataWithContentTypeAutoDetection(HttpClien public void recognizeCustomFormUnlabeledData(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormRecognizerClient(httpClient, serviceVersion); customFormDataRunner(data -> - beginTrainingUnlabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller trainingPoller = - client.getFormTrainingClient().beginTraining(storageSASUrl, useLabelFile); + client.getFormTrainingClient().beginTraining(trainingFilesUrl, useTrainingLabels); trainingPoller.waitForCompletion(); SyncPoller> syncPoller diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java index 7b685d2c938a..58a11286bc6f 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingAsyncClientTest.java @@ -5,12 +5,12 @@ import com.azure.ai.formrecognizer.models.CustomFormModel; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.training.FormTrainingAsyncClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.test.TestMode; -import com.azure.core.util.Context; import com.azure.core.util.polling.SyncPoller; import io.netty.handler.codec.http.HttpResponseStatus; import org.junit.jupiter.api.AfterAll; @@ -88,17 +88,16 @@ public void getCustomModelInvalidModelId(HttpClient httpClient, FormRecognizerSe @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void getCustomModelWithResponse(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingAsyncClient(httpClient, serviceVersion); - beginTrainingUnlabeledRunner((trainingDataSASUrl, useLabelFile) -> { - SyncPoller syncPoller = client.beginTraining(trainingDataSASUrl, - useLabelFile).getSyncPoller(); + beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { + SyncPoller syncPoller = client.beginTraining(trainingFilesUrl, + useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); CustomFormModel trainedModel = syncPoller.getFinalResult(); - StepVerifier.create(client.getCustomModelWithResponse(trainedModel.getModelId(), - Context.NONE)).assertNext(customFormModelResponse -> { - assertEquals(customFormModelResponse.getStatusCode(), HttpResponseStatus.OK.code()); - validateCustomModelData(syncPoller.getFinalResult(), false); - }); + StepVerifier.create(client.getCustomModelWithResponse(trainedModel.getModelId())).assertNext(customFormModelResponse -> { + assertEquals(customFormModelResponse.getStatusCode(), HttpResponseStatus.OK.code()); + validateCustomModelData(syncPoller.getFinalResult(), false); + }); }); } @@ -109,9 +108,9 @@ public void getCustomModelWithResponse(HttpClient httpClient, FormRecognizerServ @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void getCustomModelUnlabeled(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingAsyncClient(httpClient, serviceVersion); - beginTrainingUnlabeledRunner((trainingDataSASUrl, useLabelFile) -> { + beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingDataSASUrl, useLabelFile).getSyncPoller(); + client.beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); CustomFormModel trainedUnlabeledModel = syncPoller.getFinalResult(); StepVerifier.create(client.getCustomModel(trainedUnlabeledModel.getModelId())) @@ -127,9 +126,9 @@ public void getCustomModelUnlabeled(HttpClient httpClient, FormRecognizerService @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void getCustomModelLabeled(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingAsyncClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((trainingDataSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingFilesUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingDataSASUrl, useLabelFile).getSyncPoller(); + client.beginTraining(trainingFilesUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); CustomFormModel trainedLabeledModel = syncPoller.getFinalResult(); StepVerifier.create(client.getCustomModel(trainedLabeledModel.getModelId())) @@ -181,9 +180,9 @@ public void deleteModelInvalidModelId(HttpClient httpClient, FormRecognizerServi @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void deleteModelValidModelIdWithResponse(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingAsyncClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((storageSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.beginTraining(storageSASUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); @@ -212,20 +211,6 @@ public void getModelInfos(HttpClient httpClient, FormRecognizerServiceVersion se .verifyComplete(); } - /** - * Test for listing all models information with {@link Context}. - */ - @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) - @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") - public void getModelInfosWithContext(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { - client = getFormTrainingAsyncClient(httpClient, serviceVersion); - StepVerifier.create(client.getModelInfos(Context.NONE)) - .thenConsumeWhile(modelInfo -> - modelInfo.getModelId() != null && modelInfo.getCreatedOn() != null - && modelInfo.getLastUpdatedOn() != null && modelInfo.getStatus() != null) - .verifyComplete(); - } - /** * Verifies that an exception is thrown for null source url input. */ @@ -247,9 +232,9 @@ public void beginTrainingNullInput(HttpClient httpClient, FormRecognizerServiceV @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void beginTrainingLabeledResult(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingAsyncClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((storageSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.beginTraining(storageSASUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); validateCustomModelData(syncPoller.getFinalResult(), true); }); @@ -262,9 +247,9 @@ public void beginTrainingLabeledResult(HttpClient httpClient, FormRecognizerServ @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void beginTrainingUnlabeledResult(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingAsyncClient(httpClient, serviceVersion); - beginTrainingUnlabeledRunner((storageSASUrl, useLabelFile) -> { + beginTrainingUnlabeledRunner((storageSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(storageSASUrl, useLabelFile).getSyncPoller(); + client.beginTraining(storageSASUrl, useTrainingLabels).getSyncPoller(); syncPoller.waitForCompletion(); validateCustomModelData(syncPoller.getFinalResult(), false); }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java index 7b7e149418a6..243b2ff4bb72 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTest.java @@ -8,6 +8,7 @@ import com.azure.ai.formrecognizer.models.CustomFormModelInfo; import com.azure.ai.formrecognizer.models.ErrorResponseException; import com.azure.ai.formrecognizer.models.OperationResult; +import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.policy.HttpLogDetailLevel; @@ -76,8 +77,8 @@ public void getCustomModelInvalidModelId(HttpClient httpClient, FormRecognizerSe @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void getCustomModelWithResponse(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingClient(httpClient, serviceVersion); - beginTrainingUnlabeledRunner((trainingDataSasUrl, useLabelFile) -> { - CustomFormModel trainedUnlabeledModel = client.beginTraining(trainingDataSasUrl, useLabelFile) + beginTrainingUnlabeledRunner((trainingDataSasUrl, useTrainingLabels) -> { + CustomFormModel trainedUnlabeledModel = client.beginTraining(trainingDataSasUrl, useTrainingLabels) .getFinalResult(); Response customModelWithResponse = client.getCustomModelWithResponse(trainedUnlabeledModel.getModelId(), @@ -94,9 +95,9 @@ public void getCustomModelWithResponse(HttpClient httpClient, FormRecognizerServ @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void getCustomModelUnlabeled(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingClient(httpClient, serviceVersion); - beginTrainingUnlabeledRunner((trainingDataSASUri, useLabelFile) -> { - SyncPoller syncPoller = client.beginTraining(trainingDataSASUri, - useLabelFile); + beginTrainingUnlabeledRunner((trainingFilesUrl, useTrainingLabels) -> { + SyncPoller syncPoller = client.beginTraining(trainingFilesUrl, + useTrainingLabels); syncPoller.waitForCompletion(); CustomFormModel trainedUnlabeledModel = syncPoller.getFinalResult(); validateCustomModelData(client.getCustomModel(trainedUnlabeledModel.getModelId()), false); @@ -110,8 +111,8 @@ public void getCustomModelUnlabeled(HttpClient httpClient, FormRecognizerService @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void getCustomModelLabeled(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((trainingDataSASUrl, useLabelFile) -> { - CustomFormModel customFormModel = client.beginTraining(trainingDataSASUrl, useLabelFile) + beginTrainingLabeledRunner((trainingDataSASUrl, useTrainingLabels) -> { + CustomFormModel customFormModel = client.beginTraining(trainingDataSASUrl, useTrainingLabels) .getFinalResult(); validateCustomModelData(client.getCustomModel(customFormModel.getModelId()), true); }); @@ -155,9 +156,9 @@ public void deleteModelInvalidModelId(HttpClient httpClient, FormRecognizerServi @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void deleteModelValidModelIdWithResponse(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((trainingDataSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingDataSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingDataSASUrl, useLabelFile); + client.beginTraining(trainingDataSASUrl, useTrainingLabels); syncPoller.waitForCompletion(); CustomFormModel createdModel = syncPoller.getFinalResult(); @@ -216,9 +217,9 @@ public void beginTrainingNullInput(HttpClient httpClient, FormRecognizerServiceV @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void beginTrainingLabeledResult(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingClient(httpClient, serviceVersion); - beginTrainingLabeledRunner((trainingDataSASUrl, useLabelFile) -> { + beginTrainingLabeledRunner((trainingDataSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingDataSASUrl, useLabelFile); + client.beginTraining(trainingDataSASUrl, useTrainingLabels); syncPoller.waitForCompletion(); validateCustomModelData(syncPoller.getFinalResult(), true); }); @@ -231,9 +232,9 @@ public void beginTrainingLabeledResult(HttpClient httpClient, FormRecognizerServ @MethodSource("com.azure.ai.formrecognizer.TestUtils#getTestParameters") public void beginTrainingUnlabeledResult(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion) { client = getFormTrainingClient(httpClient, serviceVersion); - beginTrainingUnlabeledRunner((trainingDataSASUrl, useLabelFile) -> { + beginTrainingUnlabeledRunner((trainingDataSASUrl, useTrainingLabels) -> { SyncPoller syncPoller = - client.beginTraining(trainingDataSASUrl, useLabelFile); + client.beginTraining(trainingDataSASUrl, useTrainingLabels); syncPoller.waitForCompletion(); validateCustomModelData(syncPoller.getFinalResult(), false); }); diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java index 8eb777583967..af158c14c614 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormTrainingClientTestBase.java @@ -80,8 +80,8 @@ private static void validateErrorData(List expectedErrors, static void validateAccountProperties(AccountProperties expectedAccountProperties, AccountProperties actualAccountProperties) { - assertEquals(expectedAccountProperties.getLimit(), actualAccountProperties.getLimit()); - assertNotNull(actualAccountProperties.getCount()); + assertEquals(expectedAccountProperties.getCustomModelLimit(), actualAccountProperties.getCustomModelLimit()); + assertNotNull(actualAccountProperties.getCustomModelCount()); } /** @@ -176,9 +176,6 @@ private Model getRawModelResponse() { @Test abstract void getModelInfos(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion); - @Test - abstract void getModelInfosWithContext(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion); - @Test abstract void beginTrainingNullInput(HttpClient httpClient, FormRecognizerServiceVersion serviceVersion);