From b40c5bad745e7ef983eebb7248e9859a2f985041 Mon Sep 17 00:00:00 2001 From: Mariana Rios Flores Date: Tue, 14 Apr 2020 20:56:47 -0700 Subject: [PATCH] Enable FR StarTraining (#11322) * starttraining * no null --- .../src/FormTrainingClient.cs | 36 ++++--------------- .../TrainingFileFilter.Serialization.cs | 7 ++-- .../Generated/Models/TrainingFileFilter.cs | 7 +--- .../src/TrainingFileFilter.cs | 7 ++++ 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient.cs index cfb09aaaff636..339fd11e48c2e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTrainingClient.cs @@ -58,22 +58,10 @@ public FormTrainingClient(Uri endpoint, AzureKeyCredential credential, FormRecog [ForwardsClientCalls] public virtual TrainingOperation StartTraining(Uri trainingFiles, bool useLabels = false, TrainingFileFilter filter = default, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - - //TrainRequest_internal trainRequest = new TrainRequest_internal() { Source = trainingFiles.AbsoluteUri }; - - //// TODO: Q1 - if there's a way to default a property value, set filter.Path ="" and set it here in a nicer way. - //// https://github.com/Azure/autorest.csharp/issues/467 - //// When this is complete, we will be able to default filter.Path to "". - //// Decision to make, do we always send filter, or only if needed? - //// Tracking with https://github.com/Azure/azure-sdk-for-net/issues/10359 - //if (filter != default) - //{ - // trainRequest.SourceFilter = filter; - //} - - //ResponseWithHeaders response = ServiceClient.RestClient.TrainCustomModelAsync(trainRequest); - //return new TrainingOperation(ServiceClient, response.Headers.Location); + var trainRequest = new TrainRequest_internal(trainingFiles.AbsoluteUri, filter, useLabels); + + ResponseWithHeaders response = ServiceClient.RestClient.TrainCustomModelAsync(trainRequest); + return new TrainingOperation(response.Headers.Location, ServiceClient); } /// @@ -88,20 +76,10 @@ public virtual TrainingOperation StartTraining(Uri trainingFiles, bool useLabels [ForwardsClientCalls] public virtual async Task StartTrainingAsync(Uri trainingFiles, bool useLabels = false, TrainingFileFilter filter = default, CancellationToken cancellationToken = default) { - await Task.Run(() => { }).ConfigureAwait(false); - throw new NotImplementedException(); - - //TrainRequest_internal trainRequest = new TrainRequest_internal() { Source = trainingFiles.AbsoluteUri }; - - //// TODO: Q1 - if there's a way to default a property value, set filter.Path ="" and set it here in a nicer way. - //// https://github.com/Azure/azure-sdk-for-net/issues/10359 - //if (filter != default) - //{ - // trainRequest.SourceFilter = filter; - //} + var trainRequest = new TrainRequest_internal(trainingFiles.AbsoluteUri, filter, useLabels); - //ResponseWithHeaders response = await ServiceClient.RestClient.TrainCustomModelAsyncAsync(trainRequest).ConfigureAwait(false); - //return new TrainingOperation(ServiceClient, response.Headers.Location); + ResponseWithHeaders response = await ServiceClient.RestClient.TrainCustomModelAsyncAsync(trainRequest).ConfigureAwait(false); + return new TrainingOperation(response.Headers.Location, ServiceClient); } /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.Serialization.cs index 50cb2bf1ebacc..0d1b3134c8957 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.Serialization.cs @@ -20,11 +20,8 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("prefix"); writer.WriteStringValue(Prefix); } - if (IncludeSubFolders != null) - { - writer.WritePropertyName("includeSubFolders"); - writer.WriteBooleanValue(IncludeSubFolders.Value); - } + writer.WritePropertyName("includeSubFolders"); + writer.WriteBooleanValue(IncludeSubFolders); writer.WriteEndObject(); } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.cs index e05da5c8efc74..4a248c2d93bc9 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingFileFilter.cs @@ -14,15 +14,10 @@ public partial class TrainingFileFilter /// Initializes a new instance of TrainingFileFilter. /// 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. /// 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. - internal TrainingFileFilter(string prefix, bool? includeSubFolders) + internal TrainingFileFilter(string prefix, bool includeSubFolders) { Prefix = prefix; IncludeSubFolders = includeSubFolders; } - - /// 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. - public string Prefix { get; set; } - /// 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. - public bool? IncludeSubFolders { get; set; } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingFileFilter.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingFileFilter.cs index 3d13e4541a109..9cced9f4d20e7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingFileFilter.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingFileFilter.cs @@ -13,5 +13,12 @@ public partial class TrainingFileFilter internal TrainingFileFilter() { } + + /// + public string Prefix { get; set; } = string.Empty; + + /// + public bool IncludeSubFolders { get; set; } = false; + } }