From c487890f1b87fff31b59273e98244b84043cf667 Mon Sep 17 00:00:00 2001 From: Sameeksha Vaity Date: Thu, 17 Sep 2020 11:04:19 -0700 Subject: [PATCH] Support addition of new properties on existing models (#41) --- .../ai/formrecognizer/models/RecognizedForm.java | 11 +++++++++++ .../training/models/TrainingOptions.java | 10 ++++++++++ .../formrecognizer/RecognizeCustomFormsFromUrl.java | 2 ++ .../azure/ai/formrecognizer/TrainModelWithLabels.java | 6 +++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java index 24d513e1297f3..8daaffb30f2ef 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/RecognizedForm.java @@ -15,6 +15,8 @@ @Immutable public final class RecognizedForm { + private float formTypeConfidence; + private String modelId; /* * A map of the fields recognized from the input document. * For models trained with labels, this is the training-time label of the field. For models trained with forms @@ -90,4 +92,13 @@ public FormPageRange getPageRange() { public List getPages() { return this.pages; } + + public float getFormTypeConfidence() { + return formTypeConfidence; + } + + public String getModelId() { + return modelId; + } + } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/models/TrainingOptions.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/models/TrainingOptions.java index 01b17a16f854a..28dc526402b2b 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/models/TrainingOptions.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/training/models/TrainingOptions.java @@ -12,6 +12,7 @@ */ @Fluent public final class TrainingOptions { + private String displayName; private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5); private Duration pollInterval = DEFAULT_POLL_INTERVAL; private TrainingFileFilter trainingFileFilter; @@ -60,4 +61,13 @@ public TrainingOptions setPollInterval(final Duration pollInterval) { this.pollInterval = pollInterval == null ? DEFAULT_POLL_INTERVAL : pollInterval; return this; } + + public String getDisplayName() { + return displayName; + } + + public TrainingOptions setDisplayName(final String displayName) { + this.displayName = displayName; + return this; + } } diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeCustomFormsFromUrl.java b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeCustomFormsFromUrl.java index 5d66218bee083..0524c732808d2 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeCustomFormsFromUrl.java +++ b/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeCustomFormsFromUrl.java @@ -39,7 +39,9 @@ public static void main(String[] args) { for (int i = 0; i < recognizedForms.size(); i++) { final RecognizedForm form = recognizedForms.get(i); System.out.printf("----------- Recognized custom form info for page %d -----------%n", i); + System.out.printf("Model Id used for recognizing this form: %s%n", form.getModelId()); System.out.printf("Form type: %s%n", form.getFormType()); + System.out.printf("Form type confidence: %s%n", form.getFormTypeConfidence()); form.getFields().forEach((label, formField) -> // label data is populated if you are using a model trained with unlabeled data, // since the service needs to make predictions for labels if not explicitly given to it. 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 98538d560eb5b..53fed75da5278 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 @@ -7,7 +7,9 @@ import com.azure.ai.formrecognizer.models.FormRecognizerOperationResult; import com.azure.ai.formrecognizer.training.FormTrainingClient; import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder; +import com.azure.ai.formrecognizer.training.models.TrainingOptions; import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.util.Context; import com.azure.core.util.polling.SyncPoller; /** @@ -36,12 +38,14 @@ public static void main(String[] args) { // Train custom model String trainingFilesUrl = "{SAS_URL_of_your_container_in_blob_storage}"; // The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. - SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, true); + SyncPoller trainingPoller = client.beginTraining(trainingFilesUrl, true, + new TrainingOptions().setDisplayName("user_friendly_model_name"), Context.NONE); CustomFormModel customFormModel = trainingPoller.getFinalResult(); // Model Info System.out.printf("Model Id: %s%n", customFormModel.getModelId()); + System.out.printf("Model display name: %s%n", customFormModel.getDisplayName()); System.out.printf("Model Status: %s%n", customFormModel.getModelStatus()); System.out.printf("Training started on: %s%n", customFormModel.getTrainingStartedOn()); System.out.printf("Training completed on: %s%n%n", customFormModel.getTrainingCompletedOn());