From cebfd1e10dbc15d117da270112991a938e5ddeb4 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Wed, 11 Mar 2020 21:29:18 -0700 Subject: [PATCH 01/32] work in progress --- .../src/CustomFormClient.cs | 55 +++++++-- .../src/ExtractLabeledFormOperation.cs | 107 +++++++++++++++++ ...mOperation.cs => ExtractPagesOperation.cs} | 39 +++---- .../src/ExtractedForm.cs | 109 ------------------ .../src/ExtractedLabeledField.cs | 36 ++++++ .../src/ExtractedLabeledForm.cs | 65 +++++++++++ .../src/ExtractedLabeledPage.cs | 51 ++++++++ .../src/ExtractedPage.cs | 25 +--- 8 files changed, 326 insertions(+), 161 deletions(-) create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs rename sdk/formrecognizer/Azure.AI.FormRecognizer/src/{ExtractFormOperation.cs => ExtractPagesOperation.cs} (64%) delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedForm.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index 18267b820c43..e35908c7e90c 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using System; +using System.Collections; +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -117,35 +119,72 @@ public virtual async Task> StartTrainingWithLabels #endregion Training #region Analyze - public virtual Operation StartExtractForm(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + + #region Unsupervised + public virtual Operation> StartExtractPages(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + { + // TODO: automate content-type detection + // https://github.com/Azure/azure-sdk-for-net/issues/10329 + ResponseWithHeaders response = _operations.AnalyzeWithCustomModel(new Guid(modelId), includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken); + return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); + } + + public virtual Operation> StartExtractPages(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + { + SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; + ResponseWithHeaders response = _operations.RestClient.AnalyzeWithCustomModel(new Guid(modelId), includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken); + return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); + } + + public virtual async Task>> StartExtractPagesAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + { + // TODO: automate content-type detection + // https://github.com/Azure/azure-sdk-for-net/issues/10329 + ResponseWithHeaders response = await _operations.AnalyzeWithCustomModelAsync(new Guid(modelId), includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken).ConfigureAwait(false); + return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); + } + + public virtual async Task>> StartExtractPagesAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + { + SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; + ResponseWithHeaders response = await _operations.RestClient.AnalyzeWithCustomModelAsync(new Guid(modelId), includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken).ConfigureAwait(false); + return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); + } + #endregion + + #region Supervised + public virtual Operation> StartExtractLabeledForms(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 ResponseWithHeaders response = _operations.AnalyzeWithCustomModel(new Guid(modelId), includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken); - return new ExtractFormOperation(_operations, modelId, response.Headers.OperationLocation); + return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } - public virtual Operation StartExtractForm(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLabeledForms(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = _operations.RestClient.AnalyzeWithCustomModel(new Guid(modelId), includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken); - return new ExtractFormOperation(_operations, modelId, response.Headers.OperationLocation); + return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } - public virtual async Task> StartExtractFormAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLabeledFormsAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 ResponseWithHeaders response = await _operations.AnalyzeWithCustomModelAsync(new Guid(modelId), includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken).ConfigureAwait(false); - return new ExtractFormOperation(_operations, modelId, response.Headers.OperationLocation); + return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } - public virtual async Task> StartExtractFormAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLabeledFormsAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = await _operations.RestClient.AnalyzeWithCustomModelAsync(new Guid(modelId), includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken).ConfigureAwait(false); - return new ExtractFormOperation(_operations, modelId, response.Headers.OperationLocation); + return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } + #endregion + + // TODO: Add methods for labeled models #endregion Analyze diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs new file mode 100644 index 000000000000..62fb50faabbc --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.AI.FormRecognizer.Models +{ + /// + /// + internal class ExtractLabeledFormOperation : Operation> + { + private Response _response; + private IReadOnlyList _value; + private bool _hasCompleted; + + private readonly string _modelId; + private readonly ServiceClient _operations; + + public override string Id { get; } + + public override IReadOnlyList Value => OperationHelpers.GetValue(ref _value); + + public override bool HasCompleted => _hasCompleted; + + public override bool HasValue => _value != null; + + /// + public override Response GetRawResponse() => _response; + + /// + public override ValueTask>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => + this.DefaultWaitForCompletionAsync(cancellationToken); + + /// + public override ValueTask>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => + this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken); + + /// + /// + /// + /// + /// + internal ExtractLabeledFormOperation(ServiceClient operations, string modelId, string operationLocation) + { + _operations = operations; + _modelId = modelId; + + // TODO: Add validation here + // https://github.com/Azure/azure-sdk-for-net/issues/10385 + Id = operationLocation.Split('/').Last(); + } + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => + UpdateStatusAsync(false, cancellationToken).EnsureCompleted(); + + /// + public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => + await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); + + private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + { + if (!_hasCompleted) + { + Response update = async + ? await _operations.GetAnalyzeFormResultAsync(new Guid(_modelId), new Guid(Id), cancellationToken).ConfigureAwait(false) + : _operations.GetAnalyzeFormResult(new Guid(_modelId), new Guid(Id), cancellationToken); + + // TODO: Handle correctly according to returned status code + // https://github.com/Azure/azure-sdk-for-net/issues/10386 + // TODO: Add reasonable null checks. + + if (update.Value.Status == OperationStatus.Succeeded || update.Value.Status == OperationStatus.Failed) + { + _hasCompleted = true; + + // TODO: Consider what we'll do when there are multiple DocumentResults + // https://github.com/Azure/azure-sdk-for-net/issues/10387 + // Supervised + _value = ConvertToExtractedLabeledForms(update.Value.AnalyzeResult.DocumentResults, update.Value.AnalyzeResult.PageResults, update.Value.AnalyzeResult.ReadResults); + } + + _response = update.GetRawResponse(); + } + + return GetRawResponse(); + } + + private static IReadOnlyList ConvertToExtractedLabeledForms(IList documentResults, IList pageResults, IList readResults) + { + List forms = new List(); + for (int i = 0; i < documentResults.Count; i++) + { + // TODO: How do we know what pages in pageResults map to the pages in documents? + // Think about this in the morning. + forms.Add(new ExtractedLabeledForm(documentResults[i], pageResults[i], readResults[i])); + } + return forms; + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractFormOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs similarity index 64% rename from sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractFormOperation.cs rename to sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs index e63374d4230b..f0c547891d63 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractFormOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -12,10 +13,10 @@ namespace Azure.AI.FormRecognizer.Models { /// /// - internal class ExtractFormOperation : Operation + internal class ExtractPagesOperation : Operation> { private Response _response; - private ExtractedForm _value; + private IReadOnlyList _value; private bool _hasCompleted; private readonly string _modelId; @@ -23,7 +24,7 @@ internal class ExtractFormOperation : Operation public override string Id { get; } - public override ExtractedForm Value => OperationHelpers.GetValue(ref _value); + public override IReadOnlyList Value => OperationHelpers.GetValue(ref _value); public override bool HasCompleted => _hasCompleted; @@ -33,11 +34,11 @@ internal class ExtractFormOperation : Operation public override Response GetRawResponse() => _response; /// - public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => + public override ValueTask>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => this.DefaultWaitForCompletionAsync(cancellationToken); /// - public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => + public override ValueTask>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken); /// @@ -45,7 +46,7 @@ public override ValueTask> WaitForCompletionAsync(TimeSp /// /// /// - internal ExtractFormOperation(ServiceClient operations, string modelId, string operationLocation) + internal ExtractPagesOperation(ServiceClient operations, string modelId, string operationLocation) { _operations = operations; _modelId = modelId; @@ -78,21 +79,7 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can if (update.Value.Status == OperationStatus.Succeeded || update.Value.Status == OperationStatus.Failed) { _hasCompleted = true; - - // TODO: Move this logic into ExtractedForm? It's a bit convoluted right now. - // Determine if the model was supervised or unsupervised - if (update.Value.AnalyzeResult.DocumentResults?.Count == 0) - { - // Unsupervised - _value = new ExtractedForm(update.Value.AnalyzeResult.PageResults, update.Value.AnalyzeResult.ReadResults); - } - else - { - // TODO: Consider what we'll do when there are multiple DocumentResults - // https://github.com/Azure/azure-sdk-for-net/issues/10387 - // Supervised - _value = new ExtractedForm(update.Value.AnalyzeResult.DocumentResults.First(), update.Value.AnalyzeResult.PageResults, update.Value.AnalyzeResult.ReadResults); - } + _value = ConvertToExtractedPages(update.Value.AnalyzeResult.PageResults, update.Value.AnalyzeResult.ReadResults); } _response = update.GetRawResponse(); @@ -100,5 +87,15 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can return GetRawResponse(); } + + private static IReadOnlyList ConvertToExtractedPages(IList pageResults, IList readResults) + { + List pages = new List(); + for (int i = 0; i < pageResults.Count; i++) + { + pages.Add(new ExtractedPage(pageResults[i], readResults[i])); + } + return pages; + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedForm.cs deleted file mode 100644 index a4cdead7a556..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedForm.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; - -namespace Azure.AI.FormRecognizer.Models -{ - public class ExtractedForm - { - internal ExtractedForm(ICollection pageResults, ICollection readResults) - { - // Unsupervised - Pages = SetPages(pageResults, readResults); - - // TODO: Set page range from page numbers in pageResults - // https://github.com/Azure/azure-sdk-for-net/issues/10365 - } - - internal ExtractedForm(DocumentResult_internal documentResult, ICollection pageResults, ICollection readResults) - { - // Supervised - LearnedFormType = documentResult.DocType; - StartPageNumber = documentResult.PageRange.First(); - EndPageNumber = documentResult.PageRange.Last(); - Pages = ConvertPages(documentResult, pageResults, readResults); - } - - public string LearnedFormType { get; internal set; } - - public int StartPageNumber { get; internal set; } - - public int EndPageNumber { get; internal set; } - - public IReadOnlyList Pages { get; } - - private IReadOnlyList SetPages(ICollection pageResults, ICollection readResults) - { - // TODO: Add validation and appropriate exception if these don't match. - // https://github.com/Azure/azure-sdk-for-net/issues/10366 - Debug.Assert(pageResults.Count == readResults.Count); - - List pages = new List(); - - for (int i = 0; i < pageResults.Count; i++) - { - PageResult_internal pageResult = pageResults.ElementAt(i); - ReadResult_internal rawExtractedPage = readResults.ElementAt(i); - - SetLearnedFormType(pageResult.ClusterId); - - ExtractedPage page = new ExtractedPage(pageResult, rawExtractedPage); - pages.Add(page); - } - - return pages; - } - - private static IReadOnlyList ConvertPages(DocumentResult_internal documentResult, ICollection pageResults, ICollection readResults) - { - List pages = new List(); - - Dictionary> fieldsByPage = new Dictionary>(); - foreach (var field in documentResult.Fields) - { - // TODO: We are currently setting the field page to 0 if field.Value.Page comes back as null. - // https://github.com/Azure/azure-sdk-for-net/issues/10369 - - // TODO: How should we handle the multiple values per field and the strongly-typed ones? - // https://github.com/Azure/azure-sdk-for-net/issues/10333 - - List list; - if (!fieldsByPage.TryGetValue(field.Value.Page ?? 0, out list)) - { - fieldsByPage[field.Value.Page ?? 0] = new List(); - } - - fieldsByPage[field.Value.Page ?? 0].Add(new ExtractedField(field)); - } - - foreach (var pageFields in fieldsByPage) - { - int pageNumber = pageFields.Key; - var page = new ExtractedPage(pageNumber, pageFields.Value, pageResults.ElementAt(pageNumber - 1), readResults.ElementAt(pageNumber - 1)); - pages.Add(page); - } - - return pages; - } - - private void SetLearnedFormType(int? clusterId) - { - // TODO: Provide IFormatProvider - // https://github.com/Azure/azure-sdk-for-net/issues/10376 -#pragma warning disable CA1305 // Specify IFormatProvider - string formId = clusterId?.ToString(); -#pragma warning restore CA1305 // Specify IFormatProvider - - if (formId != null) - { - // TODO: is it possible that multiple pages in a page result could have different page numbers? - // https://github.com/Azure/azure-sdk-for-net/issues/10377 - Debug.Assert(LearnedFormType == formId, "Multiple form types found in ExtractedForm."); - LearnedFormType = formId; - } - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs new file mode 100644 index 000000000000..e7fc1bbb0193 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; + +namespace Azure.AI.FormRecognizer.Models +{ + // Maps to FieldValue in swagger. + public class ExtractedLabeledField + { + internal ExtractedLabeledField(KeyValuePair field, ReadResult_internal readResult) + { + // Supervised + Confidence = field.Value.Confidence; + Label = field.Key; + Value = field.Value.Text; + ValueBoundingBox = new BoundingBox(field.Value.BoundingBox); + RawExtractedItems = ExtractedField.ConvertTextReferences(readResult, field.Value.Elements); + + // TODO: Add strongly-typed value + // https://github.com/Azure/azure-sdk-for-net/issues/10333 + } + + // TODO: Why can this be nullable on FieldValue.Confidence? + // https://github.com/Azure/azure-sdk-for-net/issues/10378 + public float? Confidence { get; internal set; } + + public string Label { get; internal set; } + + public string Value { get; internal set; } + + public BoundingBox ValueBoundingBox { get; internal set; } + + public IReadOnlyList RawExtractedItems { get; internal set; } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs new file mode 100644 index 000000000000..de2c501c1d99 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace Azure.AI.FormRecognizer.Models +{ + public class ExtractedLabeledForm + { + internal ExtractedLabeledForm(DocumentResult_internal documentResult, ICollection pageResults, ICollection readResults) + { + // Supervised + FormType = documentResult.DocType; + + // TODO: validate that PageRange.Length == 2. + // https://github.com/Azure/azure-sdk-for-net/issues/10547 + StartPageNumber = documentResult.PageRange.First(); + EndPageNumber = documentResult.PageRange.Last(); + // TODO: + Fields = ConvertFields(documentResult, pageResults, readResults); + } + + public string FormType { get; internal set; } + + public int StartPageNumber { get; internal set; } + + public int EndPageNumber { get; internal set; } + + public IReadOnlyList Fields { get; } + + private static IReadOnlyList ConvertPages(DocumentResult_internal documentResult, ICollection pageResults, ICollection readResults) + { + List pages = new List(); + + Dictionary> fieldsByPage = new Dictionary>(); + foreach (var field in documentResult.Fields) + { + // TODO: We are currently setting the field page to 0 if field.Value.Page comes back as null. + // https://github.com/Azure/azure-sdk-for-net/issues/10369 + + // TODO: How should we handle the multiple values per field and the strongly-typed ones? + // https://github.com/Azure/azure-sdk-for-net/issues/10333 + + List list; + if (!fieldsByPage.TryGetValue(field.Value.Page ?? 0, out list)) + { + fieldsByPage[field.Value.Page ?? 0] = new List(); + } + + fieldsByPage[field.Value.Page ?? 0].Add(new ExtractedField(field)); + } + + foreach (var pageFields in fieldsByPage) + { + int pageNumber = pageFields.Key; + var page = new ExtractedLabeledPage(pageNumber, pageFields.Value, pageResults.ElementAt(pageNumber - 1), readResults.ElementAt(pageNumber - 1)); + pages.Add(page); + } + + return pages; + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs new file mode 100644 index 000000000000..7ca65bc17e46 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; + +namespace Azure.AI.FormRecognizer.Models +{ + public class ExtractedLabeledPage + { + // Supervised + internal ExtractedLabeledPage(int pageNumber, List fields, PageResult_internal pageResult, ReadResult_internal readResult) + { + PageNumber = pageNumber; + Fields = ConvertFields(fields); + Tables = ExtractedLayoutPage.ConvertTables(pageResult.Tables, readResult); + + if (readResult != null) + { + RawExtractedPage = new RawExtractedPage(readResult); + } + } + + public int PageNumber { get; } + + public IReadOnlyList Fields { get; } + public IReadOnlyList Tables { get; } + + public RawExtractedPage RawExtractedPage { get; } + + private static IReadOnlyList ConvertFields(ICollection keyValuePairs, ReadResult_internal readResult) + { + List fields = new List(); + foreach (var kvp in keyValuePairs) + { + ExtractedField field = new ExtractedField(kvp, readResult); + fields.Add(field); + } + return fields; + } + + private static IReadOnlyList ConvertFields(List fields) + { + List list = new List(); + foreach (var field in fields) + { + list.Add(field); + } + return list; + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs index f6f44f9f6210..7be7a45b740d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs @@ -20,26 +20,15 @@ internal ExtractedPage(PageResult_internal pageResult, ReadResult_internal readR } } - // Supervised - internal ExtractedPage(int pageNumber, List fields, PageResult_internal pageResult, ReadResult_internal readResult) - { - PageNumber = pageNumber; - Fields = ConvertFields(fields); - Tables = ExtractedLayoutPage.ConvertTables(pageResult.Tables, readResult); - - if (readResult != null) - { - RawExtractedPage = new RawExtractedPage(readResult); - } - } - public int PageNumber { get; } public IReadOnlyList Fields { get; } + public IReadOnlyList Tables { get; } public RawExtractedPage RawExtractedPage { get; } + // TODO: Unmerge Convert Fields private static IReadOnlyList ConvertFields(ICollection keyValuePairs, ReadResult_internal readResult) { List fields = new List(); @@ -50,15 +39,5 @@ private static IReadOnlyList ConvertFields(ICollection ConvertFields(List fields) - { - List list = new List(); - foreach (var field in fields) - { - list.Add(field); - } - return list; - } } } From fe1ee4f26d33b4bb03e688df942fc78f30f5559d Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 09:25:32 -0700 Subject: [PATCH 02/32] interim commit --- .../src/CustomFormClient.cs | 3 - .../src/ExtractLabeledFormOperation.cs | 4 +- .../src/ExtractedField.cs | 30 ++++++++++ .../src/ExtractedLabeledField.cs | 4 +- .../src/ExtractedLabeledForm.cs | 57 +++++++++---------- .../src/ExtractedLabeledTable.cs | 21 +++++++ .../src/ExtractedLayoutPage.cs | 15 +++++ .../src/ExtractedTable.cs | 8 +-- 8 files changed, 101 insertions(+), 41 deletions(-) create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index e35908c7e90c..30bd2e0f2b49 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading; @@ -184,8 +183,6 @@ public virtual async Task>> StartE } #endregion - // TODO: Add methods for labeled models - #endregion Analyze #region CRUD Ops diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs index 62fb50faabbc..9a3922f98e1f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs @@ -97,9 +97,7 @@ private static IReadOnlyList ConvertToExtractedLabeledForm List forms = new List(); for (int i = 0; i < documentResults.Count; i++) { - // TODO: How do we know what pages in pageResults map to the pages in documents? - // Think about this in the morning. - forms.Add(new ExtractedLabeledForm(documentResults[i], pageResults[i], readResults[i])); + forms.Add(new ExtractedLabeledForm(documentResults[i], pageResults, readResults)); } return forms; } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs index ca971a7d8a22..336cdb526c67 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs @@ -65,6 +65,16 @@ internal static IReadOnlyList ConvertTextReferences(ReadResult return extractedTexts; } + internal static IReadOnlyList ConvertTextReferences(IList readResults, ICollection references) + { + List extractedTexts = new List(); + foreach (var reference in references) + { + extractedTexts.Add(ResolveTextReference(readResults, reference)); + } + return extractedTexts; + } + //private const string SegmentReadResults = "readResults"; //private const string SegmentLines = "lines"; //private const string SegmentWords = "words"; @@ -128,5 +138,25 @@ private static RawExtractedItem ResolveTextReference(ReadResult_internal readRes // } //} } + + private static RawExtractedItem ResolveTextReference(IList readResults, string reference) + { + // TODO: Add additional validations here. + // https://github.com/Azure/azure-sdk-for-net/issues/10363 + + // Example: the following should result in LineIndex = 7, WordIndex = 12 + // "#/readResults/3/lines/7/words/12" + string[] segments = reference.Split('/'); + +#pragma warning disable CA1305 // Specify IFormatProvider + var pageIndex = int.Parse(segments[2]); + var lineIndex = int.Parse(segments[4]); + var wordIndex = int.Parse(segments[6]); +#pragma warning restore CA1305 // Specify IFormatProvider + + // TODO: Support case where text reference is lines only, without word segment + // https://github.com/Azure/azure-sdk-for-net/issues/10364 + return new RawExtractedWord(readResults[pageIndex].Lines[lineIndex].Words[wordIndex]); + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs index e7fc1bbb0193..ddce0c253a96 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs @@ -8,14 +8,14 @@ namespace Azure.AI.FormRecognizer.Models // Maps to FieldValue in swagger. public class ExtractedLabeledField { - internal ExtractedLabeledField(KeyValuePair field, ReadResult_internal readResult) + internal ExtractedLabeledField(KeyValuePair field, IList readResults) { // Supervised Confidence = field.Value.Confidence; Label = field.Key; Value = field.Value.Text; ValueBoundingBox = new BoundingBox(field.Value.BoundingBox); - RawExtractedItems = ExtractedField.ConvertTextReferences(readResult, field.Value.Elements); + RawExtractedItems = ExtractedField.ConvertTextReferences(readResults, field.Value.Elements); // TODO: Add strongly-typed value // https://github.com/Azure/azure-sdk-for-net/issues/10333 diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs index de2c501c1d99..275c3e275a18 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs @@ -2,14 +2,13 @@ // Licensed under the MIT License. using System.Collections.Generic; -using System.Diagnostics; using System.Linq; namespace Azure.AI.FormRecognizer.Models { public class ExtractedLabeledForm { - internal ExtractedLabeledForm(DocumentResult_internal documentResult, ICollection pageResults, ICollection readResults) + internal ExtractedLabeledForm(DocumentResult_internal documentResult, IList pageResults, IList readResults) { // Supervised FormType = documentResult.DocType; @@ -18,8 +17,16 @@ internal ExtractedLabeledForm(DocumentResult_internal documentResult, ICollectio // https://github.com/Azure/azure-sdk-for-net/issues/10547 StartPageNumber = documentResult.PageRange.First(); EndPageNumber = documentResult.PageRange.Last(); - // TODO: - Fields = ConvertFields(documentResult, pageResults, readResults); + + Fields = ConvertFields(documentResult.Fields, readResults); + + Tables = ExtractedLayoutPage.ConvertLabeledTables(pageResults, readResults); + + if (readResults != null) + { + //RawExtractedPage = new RawExtractedPage(readResult); + RawExtractedPages = ConvertRawPages(readResults); + } } public string FormType { get; internal set; } @@ -28,38 +35,30 @@ internal ExtractedLabeledForm(DocumentResult_internal documentResult, ICollectio public int EndPageNumber { get; internal set; } - public IReadOnlyList Fields { get; } - - private static IReadOnlyList ConvertPages(DocumentResult_internal documentResult, ICollection pageResults, ICollection readResults) - { - List pages = new List(); - - Dictionary> fieldsByPage = new Dictionary>(); - foreach (var field in documentResult.Fields) - { - // TODO: We are currently setting the field page to 0 if field.Value.Page comes back as null. - // https://github.com/Azure/azure-sdk-for-net/issues/10369 + public IReadOnlyList Fields { get; } - // TODO: How should we handle the multiple values per field and the strongly-typed ones? - // https://github.com/Azure/azure-sdk-for-net/issues/10333 + public IReadOnlyList Tables { get; } - List list; - if (!fieldsByPage.TryGetValue(field.Value.Page ?? 0, out list)) - { - fieldsByPage[field.Value.Page ?? 0] = new List(); - } + public IReadOnlyList RawExtractedPages { get; } - fieldsByPage[field.Value.Page ?? 0].Add(new ExtractedField(field)); + private static IReadOnlyList ConvertFields(IDictionary fields, IList readResults) + { + List list = new List(); + foreach (var field in fields) + { + list.Add(new ExtractedLabeledField(field, readResults)); } + return list; + } - foreach (var pageFields in fieldsByPage) + private static IReadOnlyList ConvertRawPages(IList readResults) + { + List rawPages = new List(); + foreach (var readResult in readResults) { - int pageNumber = pageFields.Key; - var page = new ExtractedLabeledPage(pageNumber, pageFields.Value, pageResults.ElementAt(pageNumber - 1), readResults.ElementAt(pageNumber - 1)); - pages.Add(page); + rawPages.Add(new RawExtractedPage(readResult)); } - - return pages; + return rawPages; } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs new file mode 100644 index 000000000000..6ebb351c42c9 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Azure.AI.FormRecognizer.Models; + +namespace Azure.AI.FormRecognizer +{ + public class ExtractedLabeledTable : ExtractedTable + { + internal ExtractedLabeledTable(DataTable_internal table, ReadResult_internal readResult, int pageNumber) + : base(table, readResult) + { + PageNumber = pageNumber; + } + + public int PageNumber { get; } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs index 7716d5d1c27a..75b5527155f7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs @@ -35,5 +35,20 @@ internal static IReadOnlyList ConvertTables(ICollection ConvertLabeledTables(IList pageResults, IList readResults) + { + List tables = new List(); + + foreach (var pageResult in pageResults) + { + foreach (var table in pageResult.Tables) + { + tables.Add(new ExtractedLabeledTable(table, readResults[pageResult.Page], pageResult.Page)); + } + } + + return tables; + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTable.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTable.cs index 56b8425985eb..a1557abdac39 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTable.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTable.cs @@ -8,11 +8,11 @@ namespace Azure.AI.FormRecognizer.Models { public class ExtractedTable { - internal ExtractedTable(DataTable_internal result, ReadResult_internal readResult) + internal ExtractedTable(DataTable_internal table, ReadResult_internal readResult) { - ColumnCount = result.Columns; - RowCount = result.Rows; - Cells = ConvertCells(result.Cells, readResult); + ColumnCount = table.Columns; + RowCount = table.Rows; + Cells = ConvertCells(table.Cells, readResult); } public IReadOnlyList Cells { get; } From 8f2bef2ff90be60e4a2720191f8fd81273328afa Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 09:29:23 -0700 Subject: [PATCH 03/32] update api --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 7699ba20c977..f1c82e16fbfa 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -1,5 +1,10 @@ namespace Azure.AI.FormRecognizer { + public partial class ExtractedLabeledTable : Azure.AI.FormRecognizer.Models.ExtractedTable + { + internal ExtractedLabeledTable() { } + public int PageNumber { get { throw null; } } + } public partial class FormLayoutClient { protected FormLayoutClient() { } @@ -43,10 +48,14 @@ public CustomFormClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.Form public virtual Azure.AsyncPageable GetModelInfosAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSubscriptionProperties(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSubscriptionPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation StartExtractForm(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation StartExtractForm(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> StartExtractFormAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> StartExtractFormAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractPages(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractPagesAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTraining(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> StartTrainingAsync(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTrainingWithLabels(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -142,13 +151,32 @@ internal ExtractedField() { } public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } public System.Collections.Generic.IReadOnlyList ValueRawExtractedItems { get { throw null; } } } - public partial class ExtractedForm + public partial class ExtractedLabeledField { - internal ExtractedForm() { } + internal ExtractedLabeledField() { } + public float? Confidence { get { throw null; } } + public string Label { get { throw null; } } + public System.Collections.Generic.IReadOnlyList RawExtractedItems { get { throw null; } } + public string Value { get { throw null; } } + public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } + } + public partial class ExtractedLabeledForm + { + internal ExtractedLabeledForm() { } public int EndPageNumber { get { throw null; } } - public string LearnedFormType { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Pages { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } + public string FormType { get { throw null; } } + public System.Collections.Generic.IReadOnlyList RawExtractedPages { get { throw null; } } public int StartPageNumber { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + } + public partial class ExtractedLabeledPage + { + internal ExtractedLabeledPage() { } + public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } + public int PageNumber { get { throw null; } } + public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } } public partial class ExtractedLayoutPage { From fc8e7ea3972cf186253c1f9568ddd8876958cd68 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 14:42:09 -0700 Subject: [PATCH 04/32] interim split --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 19 +++---- .../src/ExtractedField.cs | 34 +++++-------- .../src/ExtractedLabeledField.cs | 9 +++- .../src/ExtractedLabeledForm.cs | 3 +- .../src/ExtractedLabeledPage.cs | 51 ------------------- .../src/ExtractedLayoutPage.cs | 2 +- .../src/ExtractedPage.cs | 1 + 7 files changed, 29 insertions(+), 90 deletions(-) delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index f1c82e16fbfa..02d41b22c936 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -143,10 +143,10 @@ public enum ContentType public partial class ExtractedField { internal ExtractedField() { } - public float? Confidence { get { throw null; } } - public string Label { get { throw null; } } - public Azure.AI.FormRecognizer.Models.BoundingBox LabelBoundingBox { get { throw null; } } - public System.Collections.Generic.IReadOnlyList LabelRawExtractedItems { get { throw null; } } + public float Confidence { get { throw null; } } + public string Name { get { throw null; } } + public Azure.AI.FormRecognizer.Models.BoundingBox NameBoundingBox { get { throw null; } } + public System.Collections.Generic.IReadOnlyList NameRawExtractedItems { get { throw null; } } public string Value { get { throw null; } } public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } public System.Collections.Generic.IReadOnlyList ValueRawExtractedItems { get { throw null; } } @@ -156,6 +156,7 @@ public partial class ExtractedLabeledField internal ExtractedLabeledField() { } public float? Confidence { get { throw null; } } public string Label { get { throw null; } } + public int? PageNumber { get { throw null; } } public System.Collections.Generic.IReadOnlyList RawExtractedItems { get { throw null; } } public string Value { get { throw null; } } public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } @@ -168,15 +169,7 @@ internal ExtractedLabeledForm() { } public string FormType { get { throw null; } } public System.Collections.Generic.IReadOnlyList RawExtractedPages { get { throw null; } } public int StartPageNumber { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } - } - public partial class ExtractedLabeledPage - { - internal ExtractedLabeledPage() { } - public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } - public int PageNumber { get { throw null; } } - public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } } public partial class ExtractedLayoutPage { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs index 336cdb526c67..242e15351083 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs @@ -6,22 +6,23 @@ namespace Azure.AI.FormRecognizer.Models { + // Maps to KeyValuePair public class ExtractedField { internal ExtractedField(KeyValuePair_internal field, ReadResult_internal readResult) { - // Unsupervised Confidence = field.Confidence; - Label = field.Key.Text; - LabelBoundingBox = field.Key.BoundingBox == null ? null : new BoundingBox(field.Key.BoundingBox); + Name = field.Key.Text; + NameBoundingBox = field.Key.BoundingBox == null ? null : new BoundingBox(field.Key.BoundingBox); + if (field.Key.Elements != null) { - LabelRawExtractedItems = ConvertTextReferences(readResult, field.Key.Elements); + NameRawExtractedItems = ConvertTextReferences(readResult, field.Key.Elements); } Value = field.Value.Text; - ValueBoundingBox = new BoundingBox(field.Value.BoundingBox); + ValueBoundingBox = field.Key.BoundingBox == null ? null : new BoundingBox(field.Value.BoundingBox); if (field.Value.Elements != null) { @@ -29,29 +30,18 @@ internal ExtractedField(KeyValuePair_internal field, ReadResult_internal readRes } } - internal ExtractedField(KeyValuePair field) - { - // Supervised - Confidence = field.Value.Confidence; - Label = field.Key; - Value = field.Value.Text; - ValueBoundingBox = new BoundingBox(field.Value.BoundingBox); - } + public float Confidence { get; internal set; } + + public string Name { get; internal set; } - // TODO: Why can this be nullable on FieldValue.Confidence? - // https://github.com/Azure/azure-sdk-for-net/issues/10378 - public float? Confidence { get; internal set; } - public string Label { get; internal set; } + public BoundingBox NameBoundingBox { get; internal set; } - // TODO: Make this nullable to indicate that this is an optional field. - // https://github.com/Azure/azure-sdk-for-net/issues/10361 - // Not currently supported for Track2 libraries. - public BoundingBox LabelBoundingBox { get; internal set; } + public IReadOnlyList NameRawExtractedItems { get; internal set; } public string Value { get; internal set; } + public BoundingBox ValueBoundingBox { get; internal set; } - public IReadOnlyList LabelRawExtractedItems { get; internal set; } public IReadOnlyList ValueRawExtractedItems { get; internal set; } // TODO: Refactor to move OCR code to a common file, rather than it living in this file. diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs index ddce0c253a96..91957b8f7a86 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs @@ -12,10 +12,15 @@ internal ExtractedLabeledField(KeyValuePair field, { // Supervised Confidence = field.Value.Confidence; + PageNumber = field.Value.Page; Label = field.Key; Value = field.Value.Text; ValueBoundingBox = new BoundingBox(field.Value.BoundingBox); - RawExtractedItems = ExtractedField.ConvertTextReferences(readResults, field.Value.Elements); + + if (field.Value.Elements != null) + { + RawExtractedItems = ExtractedField.ConvertTextReferences(readResults, field.Value.Elements); + } // TODO: Add strongly-typed value // https://github.com/Azure/azure-sdk-for-net/issues/10333 @@ -25,6 +30,8 @@ internal ExtractedLabeledField(KeyValuePair field, // https://github.com/Azure/azure-sdk-for-net/issues/10378 public float? Confidence { get; internal set; } + public int? PageNumber { get; internal set; } + public string Label { get; internal set; } public string Value { get; internal set; } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs index 275c3e275a18..4b5714a4e9e7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs @@ -24,7 +24,6 @@ internal ExtractedLabeledForm(DocumentResult_internal documentResult, IList Fields { get; } - public IReadOnlyList Tables { get; } + public IReadOnlyList Tables { get; } public IReadOnlyList RawExtractedPages { get; } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs deleted file mode 100644 index 7ca65bc17e46..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledPage.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Collections.Generic; - -namespace Azure.AI.FormRecognizer.Models -{ - public class ExtractedLabeledPage - { - // Supervised - internal ExtractedLabeledPage(int pageNumber, List fields, PageResult_internal pageResult, ReadResult_internal readResult) - { - PageNumber = pageNumber; - Fields = ConvertFields(fields); - Tables = ExtractedLayoutPage.ConvertTables(pageResult.Tables, readResult); - - if (readResult != null) - { - RawExtractedPage = new RawExtractedPage(readResult); - } - } - - public int PageNumber { get; } - - public IReadOnlyList Fields { get; } - public IReadOnlyList Tables { get; } - - public RawExtractedPage RawExtractedPage { get; } - - private static IReadOnlyList ConvertFields(ICollection keyValuePairs, ReadResult_internal readResult) - { - List fields = new List(); - foreach (var kvp in keyValuePairs) - { - ExtractedField field = new ExtractedField(kvp, readResult); - fields.Add(field); - } - return fields; - } - - private static IReadOnlyList ConvertFields(List fields) - { - List list = new List(); - foreach (var field in fields) - { - list.Add(field); - } - return list; - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs index 75b5527155f7..f1c1cc7b870b 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs @@ -44,7 +44,7 @@ internal static IReadOnlyList ConvertLabeledTables(IList< { foreach (var table in pageResult.Tables) { - tables.Add(new ExtractedLabeledTable(table, readResults[pageResult.Page], pageResult.Page)); + tables.Add(new ExtractedLabeledTable(table, readResults[pageResult.Page - 1], pageResult.Page)); } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs index 7be7a45b740d..f5fefa958670 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs @@ -5,6 +5,7 @@ namespace Azure.AI.FormRecognizer.Models { + // Maps to PageResult public class ExtractedPage { // Unsupervised From 0d75a3910cc82af1b6bc6a8f824bfe2af28209f1 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 15:29:07 -0700 Subject: [PATCH 05/32] handle multiple receipts --- .../src/ExtractReceiptOperation.cs | 24 ++++-- .../src/ExtractedReceipt.cs | 4 +- .../src/ReceiptClient.cs | 73 +++---------------- 3 files changed, 31 insertions(+), 70 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs index 5a1600c3bfdf..944930e87fdd 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs @@ -7,20 +7,21 @@ using Azure.Core; using Azure.Core.Pipeline; using System.Linq; +using System.Collections.Generic; namespace Azure.AI.FormRecognizer.Models { - internal class ExtractReceiptOperation : Operation + internal class ExtractReceiptOperation : Operation> { private Response _response; - private ExtractedReceipt _value; + private IReadOnlyList _value; private bool _hasCompleted; private readonly ServiceClient _operations; public override string Id { get; } - public override ExtractedReceipt Value => OperationHelpers.GetValue(ref _value); + public override IReadOnlyList Value => OperationHelpers.GetValue(ref _value); public override bool HasCompleted => _hasCompleted; @@ -30,11 +31,11 @@ internal class ExtractReceiptOperation : Operation public override Response GetRawResponse() => _response; /// - public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => + public override ValueTask>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => this.DefaultWaitForCompletionAsync(cancellationToken); /// - public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => + public override ValueTask>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken); internal ExtractReceiptOperation(ServiceClient operations, string operationLocation) @@ -71,7 +72,8 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can // TODO: When they support extracting more than one receipt, add a pageable method for this. // https://github.com/Azure/azure-sdk-for-net/issues/10389 - _value = new ExtractedReceipt(update.Value.AnalyzeResult.DocumentResults.First(), update.Value.AnalyzeResult.ReadResults.First()); + //_value = new ExtractedReceipt(update.Value.AnalyzeResult.DocumentResults.First(), update.Value.AnalyzeResult.ReadResults.First()); + _value = ConvertToExtractedReceipts(update.Value.AnalyzeResult.DocumentResults, update.Value.AnalyzeResult.ReadResults); } _response = update.GetRawResponse(); @@ -79,5 +81,15 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can return GetRawResponse(); } + + private static IReadOnlyList ConvertToExtractedReceipts(IList documentResults, IList readResults) + { + List receipts = new List(); + for (int i = 0; i < documentResults.Count; i++) + { + receipts.Add(new ExtractedReceipt(documentResults[i], readResults[i])); + } + return receipts; + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs index 5eb3af105441..67ab5e5f7e40 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs @@ -182,8 +182,8 @@ private static string ConvertStringValue(string fieldName, IDictionary DateTimeOffset.Parse(value.ValueDate), - FieldValueType.Time => DateTimeOffset.Parse(value.ValueTime), + FieldValueType.Date => value.ValueDate == null ? default : DateTimeOffset.Parse(value.ValueDate), + FieldValueType.Time => value.ValueTime == null ? default : DateTimeOffset.Parse(value.ValueTime), #pragma warning restore CA1305 // Specify IFormatProvider _ => throw new InvalidOperationException($"The value type {value.Type} was expected to be a Date or Time") }; diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs index 88e1ae27c991..a20fd9b0664f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -44,86 +45,34 @@ public ReceiptClient(Uri endpoint, FormRecognizerApiKeyCredential credential, Fo _operations = new ServiceClient(_diagnostics, _pipeline, endpoint.ToString()); } - public virtual Response ExtractReceipt(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> ExtractReceipt(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 ResponseWithHeaders response = _operations.AnalyzeReceiptAsync(includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken); - var operation = new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); - - ValueTask> task = operation.WaitForCompletionAsync(); - - // TODO: this feels very bad. Better way? - // https://github.com/Azure/azure-sdk-for-net/issues/10391 - task.AsTask().Wait(); - - if (!operation.HasValue) - { - throw new RequestFailedException("Failed to retrieve response from ExtractReceipt Long-Running Operation"); - } - - // TODO: this is also a mess. Reconcile these together. - // https://github.com/Azure/azure-sdk-for-net/issues/10391 - return Response.FromValue(operation.Value, task.AsTask().Result.GetRawResponse()); + return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } - public virtual Response ExtractReceipt(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> ExtractReceipt(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = _operations.RestClient.AnalyzeReceiptAsync(includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken); - var operation = new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); - - ValueTask> task = operation.WaitForCompletionAsync(); - - // TODO: this feels very bad. Better way? - // https://github.com/Azure/azure-sdk-for-net/issues/10391 - task.AsTask().Wait(); - - if (!operation.HasValue) - { - throw new RequestFailedException("Failed to retrieve response from ExtractReceipt Long-Running Operation"); - } - - // TODO: this is also a mess. Reconcile these together. - // https://github.com/Azure/azure-sdk-for-net/issues/10391 - return Response.FromValue(operation.Value, task.AsTask().Result.GetRawResponse()); + return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } - public virtual async Task> ExtractReceiptAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> ExtractReceiptAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 - ResponseWithHeaders response = _operations.AnalyzeReceiptAsync(includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken); - var operation = new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); - - var operationResponse = await operation.WaitForCompletionAsync().ConfigureAwait(false); - - if (!operation.HasValue) - { - throw new RequestFailedException("Failed to retrieve response from ExtractReceipt Long-Running Operation"); - } - - // TODO: Is this the best way? - // https://github.com/Azure/azure-sdk-for-net/issues/10391 - return Response.FromValue(operation.Value, operationResponse.GetRawResponse()); + ResponseWithHeaders response = await _operations.AnalyzeReceiptAsyncAsync(includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken).ConfigureAwait(false); + return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } - public virtual async Task> ExtractReceiptAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> ExtractReceiptAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; - ResponseWithHeaders response = _operations.RestClient.AnalyzeReceiptAsync(includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken); - var operation = new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); - - var operationResponse = await operation.WaitForCompletionAsync().ConfigureAwait(false); - - if (!operation.HasValue) - { - throw new RequestFailedException("Failed to retrieve response from ExtractReceipt Long-Running Operation"); - } - - // TODO: Is this the best way? - // https://github.com/Azure/azure-sdk-for-net/issues/10391 - return Response.FromValue(operation.Value, operationResponse.GetRawResponse()); + ResponseWithHeaders response = await _operations.RestClient.AnalyzeReceiptAsyncAsync(includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken).ConfigureAwait(false); + return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } } } From 948520cc6cf477e23a7b24a69d331fba18f3a621 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 16:00:04 -0700 Subject: [PATCH 06/32] api update and bug fix --- .../api/Azure.AI.FormRecognizer.netstandard2.0.cs | 8 ++++---- .../Azure.AI.FormRecognizer/src/ExtractedField.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 02d41b22c936..36122cd7d049 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -29,10 +29,10 @@ public partial class ReceiptClient protected ReceiptClient() { } public ReceiptClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential) { } public ReceiptClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential, Azure.AI.FormRecognizer.FormRecognizerClientOptions options) { } - public virtual Azure.Response ExtractReceipt(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ExtractReceipt(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExtractReceiptAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExtractReceiptAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> ExtractReceipt(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> ExtractReceipt(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> ExtractReceiptAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> ExtractReceiptAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.AI.FormRecognizer.Custom diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs index 242e15351083..aee7d44c1130 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs @@ -22,7 +22,7 @@ internal ExtractedField(KeyValuePair_internal field, ReadResult_internal readRes } Value = field.Value.Text; - ValueBoundingBox = field.Key.BoundingBox == null ? null : new BoundingBox(field.Value.BoundingBox); + ValueBoundingBox = field.Value.BoundingBox == null ? null : new BoundingBox(field.Value.BoundingBox); if (field.Value.Elements != null) { From 0978cbf21d9f4bdfbf1d34c83ea822898eb68784 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 16:22:49 -0700 Subject: [PATCH 07/32] api tweaks --- .../Azure.AI.FormRecognizer/src/CustomFormClient.cs | 8 ++++---- .../Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs | 2 +- .../Azure.AI.FormRecognizer/src/FormLayoutClient.cs | 8 ++++---- .../Azure.AI.FormRecognizer/src/ReceiptClient.cs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index 30bd2e0f2b49..ca93d4f2c30e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -120,7 +120,7 @@ public virtual async Task> StartTrainingWithLabels #region Analyze #region Unsupervised - public virtual Operation> StartExtractPages(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractFormPages(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -128,14 +128,14 @@ public virtual Operation> StartExtractPages(string return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); } - public virtual Operation> StartExtractPages(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractFormPages(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = _operations.RestClient.AnalyzeWithCustomModel(new Guid(modelId), includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken); return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); } - public virtual async Task>> StartExtractPagesAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractFormPagesAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -143,7 +143,7 @@ public virtual async Task>> StartExtractP return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); } - public virtual async Task>> StartExtractPagesAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractFormPagesAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = await _operations.RestClient.AnalyzeWithCustomModelAsync(new Guid(modelId), includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken).ConfigureAwait(false); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs index 6ebb351c42c9..8773c5fd8b74 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs @@ -6,7 +6,7 @@ using System.Text; using Azure.AI.FormRecognizer.Models; -namespace Azure.AI.FormRecognizer +namespace Azure.AI.FormRecognizer.Models { public class ExtractedLabeledTable : ExtractedTable { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs index 6b029b8f46dc..b406baf5032f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs @@ -45,7 +45,7 @@ public FormLayoutClient(Uri endpoint, FormRecognizerApiKeyCredential credential, _operations = new ServiceClient(_diagnostics, _pipeline, endpoint.ToString()); } - public virtual Operation> StartExtractLayout(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLayouts(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -53,7 +53,7 @@ public virtual Operation> StartExtractLayout( return new ExtractLayoutOperation(_operations, response.Headers.OperationLocation); } - public virtual async Task>> StartExtractLayoutAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLayoutsAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -61,14 +61,14 @@ public virtual async Task>> StartEx return new ExtractLayoutOperation(_operations, response.Headers.OperationLocation); } - public virtual Operation> StartExtractLayout(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLayouts(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = _operations.RestClient.AnalyzeLayoutAsync(sourcePath, cancellationToken); return new ExtractLayoutOperation(_operations, response.Headers.OperationLocation); } - public virtual async Task>> StartExtractLayoutAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLayoutsAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = await _operations.RestClient.AnalyzeLayoutAsyncAsync(sourcePath, cancellationToken).ConfigureAwait(false); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs index a20fd9b0664f..d36e72a69e17 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs @@ -45,7 +45,7 @@ public ReceiptClient(Uri endpoint, FormRecognizerApiKeyCredential credential, Fo _operations = new ServiceClient(_diagnostics, _pipeline, endpoint.ToString()); } - public virtual Operation> ExtractReceipt(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractReceipts(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -53,14 +53,14 @@ public virtual Operation> ExtractReceipt(Stream return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } - public virtual Operation> ExtractReceipt(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractReceipts(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = _operations.RestClient.AnalyzeReceiptAsync(includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken); return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } - public virtual async Task>> ExtractReceiptAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractReceiptsAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -68,7 +68,7 @@ public virtual async Task>> ExtractRec return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } - public virtual async Task>> ExtractReceiptAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractReceiptsAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = await _operations.RestClient.AnalyzeReceiptAsyncAsync(includeTextDetails: includeRawPageExtractions, sourcePath, cancellationToken).ConfigureAwait(false); From b85cce76da52f729c30e54f74fae2556986677bb Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 16:23:06 -0700 Subject: [PATCH 08/32] update api --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 36122cd7d049..38968872523d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -1,19 +1,14 @@ namespace Azure.AI.FormRecognizer { - public partial class ExtractedLabeledTable : Azure.AI.FormRecognizer.Models.ExtractedTable - { - internal ExtractedLabeledTable() { } - public int PageNumber { get { throw null; } } - } public partial class FormLayoutClient { protected FormLayoutClient() { } public FormLayoutClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential) { } public FormLayoutClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential, Azure.AI.FormRecognizer.FormRecognizerClientOptions options) { } - public virtual Azure.Operation> StartExtractLayout(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractLayout(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLayoutAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLayoutAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLayouts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLayouts(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class FormRecognizerClientOptions : Azure.Core.ClientOptions { @@ -29,10 +24,10 @@ public partial class ReceiptClient protected ReceiptClient() { } public ReceiptClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential) { } public ReceiptClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential, Azure.AI.FormRecognizer.FormRecognizerClientOptions options) { } - public virtual Azure.Operation> ExtractReceipt(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> ExtractReceipt(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> ExtractReceiptAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> ExtractReceiptAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractReceipts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractReceipts(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractReceiptsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractReceiptsAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.AI.FormRecognizer.Custom @@ -48,14 +43,14 @@ public CustomFormClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.Form public virtual Azure.AsyncPageable GetModelInfosAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSubscriptionProperties(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSubscriptionPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractFormPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractFormPages(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractPages(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractPagesAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTraining(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> StartTrainingAsync(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTrainingWithLabels(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -169,7 +164,12 @@ internal ExtractedLabeledForm() { } public string FormType { get { throw null; } } public System.Collections.Generic.IReadOnlyList RawExtractedPages { get { throw null; } } public int StartPageNumber { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + } + public partial class ExtractedLabeledTable : Azure.AI.FormRecognizer.Models.ExtractedTable + { + internal ExtractedLabeledTable() { } + public int PageNumber { get { throw null; } } } public partial class ExtractedLayoutPage { From 09ccbf5c845ed0a10c525f18578d26bc10cbacab Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 16:41:46 -0700 Subject: [PATCH 09/32] Merge new CodeGen updates. --- .../src/CustomFormClient.cs | 4 +++ .../src/FormContentType.cs | 7 ++++ .../Models/ContentType.Serialization.cs | 32 ------------------- .../src/Generated/Models/ContentType.cs | 22 ------------- .../Models/FormContentType.Serialization.cs | 32 +++++++++++++++++++ .../src/Generated/Operations/ServiceClient.cs | 12 +++---- .../Generated/Operations/ServiceRestClient.cs | 18 +++++------ .../src/ReceiptClient.cs | 2 +- 8 files changed, 59 insertions(+), 70 deletions(-) delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index 77f34d2692e6..ca93d4f2c30e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -33,14 +33,18 @@ protected CustomFormClient() /// /// Initializes a new instance of the . /// +#pragma warning disable AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. public CustomFormClient(Uri endpoint, FormRecognizerApiKeyCredential credential) : this(endpoint, credential, new FormRecognizerClientOptions()) +#pragma warning restore AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. { } /// /// Initializes a new instance of the . /// +#pragma warning disable AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. public CustomFormClient(Uri endpoint, FormRecognizerApiKeyCredential credential, FormRecognizerClientOptions options) +#pragma warning restore AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. { _diagnostics = new ClientDiagnostics(options); _pipeline = HttpPipelineBuilder.Build(options, new ApiKeyAuthenticationPolicy(credential)); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs index a407c8e123bc..77dbbf60a05d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs @@ -1,23 +1,30 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.Core; + namespace Azure.AI.FormRecognizer.Models { /// /// Form content type for local files. /// + [CodeGenSchema("ContentType")] public enum FormContentType { /// application/pdf + [CodeGenSchemaMember("ApplicationPdf")] Pdf = 1, /// image/png + [CodeGenSchemaMember("ImagePng")] Png = 2, /// image/jpeg + [CodeGenSchemaMember("ImageJpeg")] Jpeg = 3, /// image/tiff + [CodeGenSchemaMember("ImageTiff")] Tiff = 4, } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs deleted file mode 100644 index 619d9f44ec17..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.AI.FormRecognizer.Models -{ - internal static class ContentTypeExtensions - { - public static string ToSerialString(this ContentType value) => value switch - { - ContentType.ApplicationPdf => "application/pdf", - ContentType.ImageJpeg => "image/jpeg", - ContentType.ImagePng => "image/png", - ContentType.ImageTiff => "image/tiff", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ContentType value.") - }; - - public static ContentType ToContentType(this string value) => value switch - { - "application/pdf" => ContentType.ApplicationPdf, - "image/jpeg" => ContentType.ImageJpeg, - "image/png" => ContentType.ImagePng, - "image/tiff" => ContentType.ImageTiff, - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ContentType value.") - }; - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.cs deleted file mode 100644 index 9d49e26511a4..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -namespace Azure.AI.FormRecognizer.Models -{ - /// Content type for upload. - public enum ContentType - { - /// Content Type 'application/pdf'. - ApplicationPdf, - /// Content Type 'image/jpeg'. - ImageJpeg, - /// Content Type 'image/png'. - ImagePng, - /// Content Type 'image/tiff'. - ImageTiff - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs new file mode 100644 index 000000000000..11d2540da868 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.AI.FormRecognizer.Models +{ + internal static class FormContentTypeExtensions + { + public static string ToSerialString(this FormContentType value) => value switch + { + FormContentType.Pdf => "application/pdf", + FormContentType.Jpeg => "image/jpeg", + FormContentType.Png => "image/png", + FormContentType.Tiff => "image/tiff", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value.") + }; + + public static FormContentType ToFormContentType(this string value) => value switch + { + "application/pdf" => FormContentType.Pdf, + "image/jpeg" => FormContentType.Jpeg, + "image/png" => FormContentType.Png, + "image/tiff" => FormContentType.Tiff, + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value.") + }; + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs index 9b5a326dc320..314bb81f6fc1 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs @@ -82,7 +82,7 @@ public virtual Response DeleteCustomModel(Guid modelId, CancellationToken cancel /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual async Task AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual async Task AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return (await RestClient.AnalyzeWithCustomModelAsync(modelId, includeTextDetails, contentType, fileStream, cancellationToken).ConfigureAwait(false)).GetRawResponse(); } @@ -92,7 +92,7 @@ public virtual async Task AnalyzeWithCustomModelAsync(Guid modelId, bo /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual Response AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual Response AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return RestClient.AnalyzeWithCustomModel(modelId, includeTextDetails, contentType, fileStream, cancellationToken).GetRawResponse(); } @@ -135,7 +135,7 @@ public virtual Response GetAnalyzeFormResult(Gu /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual async Task AnalyzeReceiptAsyncAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual async Task AnalyzeReceiptAsyncAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return (await RestClient.AnalyzeReceiptAsyncAsync(includeTextDetails, contentType, fileStream, cancellationToken).ConfigureAwait(false)).GetRawResponse(); } @@ -144,7 +144,7 @@ public virtual async Task AnalyzeReceiptAsyncAsync(bool? includeTextDe /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual Response AnalyzeReceiptAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual Response AnalyzeReceiptAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return RestClient.AnalyzeReceiptAsync(includeTextDetails, contentType, fileStream, cancellationToken).GetRawResponse(); } @@ -182,7 +182,7 @@ public virtual Response GetAnalyzeReceiptResult /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual async Task AnalyzeLayoutAsyncAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual async Task AnalyzeLayoutAsyncAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return (await RestClient.AnalyzeLayoutAsyncAsync(contentType, fileStream, cancellationToken).ConfigureAwait(false)).GetRawResponse(); } @@ -190,7 +190,7 @@ public virtual async Task AnalyzeLayoutAsyncAsync(ContentType? content /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual Response AnalyzeLayoutAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual Response AnalyzeLayoutAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return RestClient.AnalyzeLayoutAsync(contentType, fileStream, cancellationToken).GetRawResponse(); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs index d91b0a5fbb1e..6bfe717625fa 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs @@ -327,7 +327,7 @@ public Response DeleteCustomModel(Guid modelId, CancellationToken cancellationTo throw; } } - internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream) + internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -356,7 +356,7 @@ internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? inc /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public async ValueTask> AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeWithCustomModel"); scope.Start(); @@ -385,7 +385,7 @@ public async ValueTask> Analy /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public ResponseWithHeaders AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeWithCustomModel"); scope.Start(); @@ -561,7 +561,7 @@ public Response GetAnalyzeFormResult(Guid model throw; } } - internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, ContentType? contentType, Stream fileStream) + internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, FormContentType? contentType, Stream fileStream) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -587,7 +587,7 @@ internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public async ValueTask> AnalyzeReceiptAsyncAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeReceiptAsyncAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeReceiptAsync"); scope.Start(); @@ -615,7 +615,7 @@ public async ValueTask> AnalyzeR /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public ResponseWithHeaders AnalyzeReceiptAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeReceiptAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeReceiptAsync"); scope.Start(); @@ -783,7 +783,7 @@ public Response GetAnalyzeReceiptResult(Guid re throw; } } - internal HttpMessage CreateAnalyzeLayoutAsyncRequest(ContentType? contentType, Stream fileStream) + internal HttpMessage CreateAnalyzeLayoutAsyncRequest(FormContentType? contentType, Stream fileStream) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -804,7 +804,7 @@ internal HttpMessage CreateAnalyzeLayoutAsyncRequest(ContentType? contentType, S /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public async ValueTask> AnalyzeLayoutAsyncAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeLayoutAsyncAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeLayoutAsync"); scope.Start(); @@ -831,7 +831,7 @@ public async ValueTask> AnalyzeLa /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public ResponseWithHeaders AnalyzeLayoutAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeLayoutAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeLayoutAsync"); scope.Start(); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs index d36e72a69e17..3f8f1047be4f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs @@ -64,7 +64,7 @@ public virtual async Task>> StartExtra { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 - ResponseWithHeaders response = await _operations.AnalyzeReceiptAsyncAsync(includeTextDetails: includeRawPageExtractions, stream, contentType, cancellationToken).ConfigureAwait(false); + ResponseWithHeaders response = await _operations.RestClient.AnalyzeReceiptAsyncAsync(includeTextDetails: includeRawPageExtractions, contentType, stream, cancellationToken).ConfigureAwait(false); return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } From 87bf81d185c9649f08be1264908a7223e71a1715 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 16:45:32 -0700 Subject: [PATCH 10/32] regen --- .../Models/ContentType.Serialization.cs | 32 ------------------- .../Models/FormContentType.Serialization.cs | 14 ++++---- 2 files changed, 7 insertions(+), 39 deletions(-) delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs deleted file mode 100644 index 65e338838919..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.AI.FormRecognizer.Models -{ - internal static class ContentTypeExtensions - { - public static string ToSerialString(this ContentType value) => value switch - { - ContentType.ApplicationPdf => "application/pdf", - ContentType.ImageJpeg => "image/jpeg", - ContentType.ImagePng => "image/png", - ContentType.ImageTiff => "image/tiff", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ContentType value.") - }; - - public static ContentType ToContentType(this string value) - { - if (string.Equals(value, "application/pdf", StringComparison.InvariantCultureIgnoreCase)) return ContentType.ApplicationPdf; - if (string.Equals(value, "image/jpeg", StringComparison.InvariantCultureIgnoreCase)) return ContentType.ImageJpeg; - if (string.Equals(value, "image/png", StringComparison.InvariantCultureIgnoreCase)) return ContentType.ImagePng; - if (string.Equals(value, "image/tiff", StringComparison.InvariantCultureIgnoreCase)) return ContentType.ImageTiff; - throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ContentType value."); - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs index 11d2540da868..451041f06702 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs @@ -20,13 +20,13 @@ internal static class FormContentTypeExtensions _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value.") }; - public static FormContentType ToFormContentType(this string value) => value switch + public static FormContentType ToFormContentType(this string value) { - "application/pdf" => FormContentType.Pdf, - "image/jpeg" => FormContentType.Jpeg, - "image/png" => FormContentType.Png, - "image/tiff" => FormContentType.Tiff, - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value.") - }; + if (string.Equals(value, "application/pdf", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Pdf; + if (string.Equals(value, "image/jpeg", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Jpeg; + if (string.Equals(value, "image/png", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Png; + if (string.Equals(value, "image/tiff", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Tiff; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value."); + } } } From 9f587c8a78dac5417cc99cb9ad280470f98fa04e Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 12 Mar 2020 17:06:52 -0700 Subject: [PATCH 11/32] api update --- .../api/Azure.AI.FormRecognizer.netstandard2.0.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 38968872523d..d029fcbae500 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -128,13 +128,6 @@ public partial class BoundingBox internal BoundingBox() { } public System.Drawing.PointF[] Points { get { throw null; } } } - public enum ContentType - { - ApplicationPdf = 0, - ImageJpeg = 1, - ImagePng = 2, - ImageTiff = 3, - } public partial class ExtractedField { internal ExtractedField() { } From 66c81fdc87eb97782c30ebf24cd6bd37ae4d4d4e Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Fri, 13 Mar 2020 07:32:52 -0700 Subject: [PATCH 12/32] api tweaks --- .../api/Azure.AI.FormRecognizer.netstandard2.0.cs | 3 ++- .../Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs | 4 ++++ .../Azure.AI.FormRecognizer/src/ExtractedPage.cs | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index d029fcbae500..bb034859d8db 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -83,7 +83,7 @@ internal CustomModelInfo() { } } public partial class CustomModelLearnedForm { - public CustomModelLearnedForm() { } + internal CustomModelLearnedForm() { } public string FormTypeId { get { throw null; } } public System.Collections.Generic.IReadOnlyList LearnedFields { get { throw null; } } } @@ -175,6 +175,7 @@ public partial class ExtractedPage { internal ExtractedPage() { } public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } + public int? FormTypeId { get { throw null; } } public int PageNumber { get { throw null; } } public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs index a61604324b41..24a24179364a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs @@ -7,6 +7,10 @@ namespace Azure.AI.FormRecognizer.Custom { public class CustomModelLearnedForm { + internal CustomModelLearnedForm() + { + } + /// /// public string FormTypeId { get; internal set; } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs index f5fefa958670..88e841bdb0b1 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs @@ -12,6 +12,7 @@ public class ExtractedPage internal ExtractedPage(PageResult_internal pageResult, ReadResult_internal readResult) { PageNumber = pageResult.Page; + FormTypeId = pageResult.ClusterId; Fields = ConvertFields(pageResult.KeyValuePairs, readResult); Tables = ExtractedLayoutPage.ConvertTables(pageResult.Tables, readResult); @@ -23,13 +24,14 @@ internal ExtractedPage(PageResult_internal pageResult, ReadResult_internal readR public int PageNumber { get; } + public int? FormTypeId { get; } + public IReadOnlyList Fields { get; } public IReadOnlyList Tables { get; } public RawExtractedPage RawExtractedPage { get; } - // TODO: Unmerge Convert Fields private static IReadOnlyList ConvertFields(ICollection keyValuePairs, ReadResult_internal readResult) { List fields = new List(); From 8e116fa8cc62f32075a78bfe028709a49bd485ea Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Fri, 13 Mar 2020 11:20:29 -0700 Subject: [PATCH 13/32] move to custom namespace --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 141 +++++++++--------- .../src/CustomModelInfo.cs | 2 +- .../src/ExtractLabeledFormOperation.cs | 3 +- .../src/ExtractPagesOperation.cs | 3 +- .../src/ExtractedField.cs | 3 +- .../src/ExtractedLabeledField.cs | 3 +- .../src/ExtractedLabeledForm.cs | 20 ++- .../src/ExtractedLabeledTable.cs | 2 +- .../src/ExtractedLayoutPage.cs | 15 -- .../src/ExtractedPage.cs | 3 +- .../src/ExtractedTableCell.cs | 1 + .../Models/AnalyzeOperationResult_internal.cs | 1 + .../ModelInfo_internal.Serialization.cs | 4 +- .../Generated/Models/ModelInfo_internal.cs | 4 +- .../Models/ModelStatus.Serialization.cs | 30 ---- .../src/Generated/Models/ModelStatus.cs | 20 --- .../Models/Model_internal.Serialization.cs | 1 + .../src/Generated/Models/Model_internal.cs | 1 + .../Models/Models_internal.Serialization.cs | 1 - .../src/Generated/Models/Models_internal.cs | 1 - .../Models/OperationStatus.Serialization.cs | 2 +- .../Models/TrainStatus.Serialization.cs | 30 ---- .../src/Generated/Models/TrainStatus.cs | 20 --- .../TrainingDocumentInfo.Serialization.cs | 2 +- .../Generated/Models/TrainingDocumentInfo.cs | 2 +- .../Models/TrainingOutcome.Serialization.cs | 30 ++++ .../Models/TrainingStatus.Serialization.cs | 30 ++++ .../src/Generated/Operations/ServiceClient.cs | 1 + .../src/ModelInfo_internal.cs | 2 +- .../{Generated/Models => }/OperationStatus.cs | 15 +- .../src/TrainingOperation.cs | 2 +- .../src/TrainingOutcome.cs | 17 +++ .../src/TrainingStatus.cs | 22 +++ .../src/TrainingWithLabelsOperation.cs | 2 +- 34 files changed, 219 insertions(+), 217 deletions(-) delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.cs delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.Serialization.cs delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs rename sdk/formrecognizer/Azure.AI.FormRecognizer/src/{Generated/Models => }/OperationStatus.cs (53%) create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index bb034859d8db..6a7390c9c5d4 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -43,14 +43,14 @@ public CustomFormClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.Form public virtual Azure.AsyncPageable GetModelInfosAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSubscriptionProperties(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSubscriptionPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractFormPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractFormPages(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractFormPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractFormPages(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTraining(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> StartTrainingAsync(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTrainingWithLabels(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -79,7 +79,7 @@ internal CustomModelInfo() { } public System.DateTimeOffset? CreatedOn { get { throw null; } } public System.DateTimeOffset? LastUpdatedOn { get { throw null; } } public string ModelId { get { throw null; } } - public Azure.AI.FormRecognizer.Models.ModelStatus TrainingStatus { get { throw null; } } + public Azure.AI.FormRecognizer.Custom.TrainingStatus TrainingStatus { get { throw null; } } } public partial class CustomModelLearnedForm { @@ -87,6 +87,51 @@ internal CustomModelLearnedForm() { } public string FormTypeId { get { throw null; } } public System.Collections.Generic.IReadOnlyList LearnedFields { get { throw null; } } } + public partial class ExtractedField + { + internal ExtractedField() { } + public float Confidence { get { throw null; } } + public string Name { get { throw null; } } + public Azure.AI.FormRecognizer.Models.BoundingBox NameBoundingBox { get { throw null; } } + public System.Collections.Generic.IReadOnlyList NameRawExtractedItems { get { throw null; } } + public string Value { get { throw null; } } + public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } + public System.Collections.Generic.IReadOnlyList ValueRawExtractedItems { get { throw null; } } + } + public partial class ExtractedLabeledField + { + internal ExtractedLabeledField() { } + public float? Confidence { get { throw null; } } + public string Label { get { throw null; } } + public int? PageNumber { get { throw null; } } + public System.Collections.Generic.IReadOnlyList RawExtractedItems { get { throw null; } } + public string Value { get { throw null; } } + public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } + } + public partial class ExtractedLabeledForm + { + internal ExtractedLabeledForm() { } + public int EndPageNumber { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } + public string FormType { get { throw null; } } + public System.Collections.Generic.IReadOnlyList RawExtractedPages { get { throw null; } } + public int StartPageNumber { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + } + public partial class ExtractedLabeledTable : Azure.AI.FormRecognizer.Models.ExtractedTable + { + internal ExtractedLabeledTable() { } + public int PageNumber { get { throw null; } } + } + public partial class ExtractedPage + { + internal ExtractedPage() { } + public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } + public int? FormTypeId { get { throw null; } } + public int PageNumber { get { throw null; } } + public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + } public partial class FieldPredictionAccuracy { public FieldPredictionAccuracy() { } @@ -106,7 +151,7 @@ public TrainingDocumentInfo() { } public string DocumentName { get { throw null; } set { } } public System.Collections.Generic.IList Errors { get { throw null; } set { } } public int PageCount { get { throw null; } set { } } - public Azure.AI.FormRecognizer.Models.TrainStatus Status { get { throw null; } set { } } + public Azure.AI.FormRecognizer.Custom.TrainingOutcome Status { get { throw null; } set { } } } public partial class TrainingFileFilter { @@ -120,6 +165,18 @@ internal TrainingInfo() { } public System.Collections.Generic.IReadOnlyList PerDocumentInfo { get { throw null; } } public System.Collections.Generic.IReadOnlyList TrainingErrors { get { throw null; } } } + public enum TrainingOutcome + { + Succeeded = 0, + PartiallySucceeded = 1, + Failed = 2, + } + public enum TrainingStatus + { + Training = 0, + Ready = 1, + Invalid = 2, + } } namespace Azure.AI.FormRecognizer.Models { @@ -128,42 +185,6 @@ public partial class BoundingBox internal BoundingBox() { } public System.Drawing.PointF[] Points { get { throw null; } } } - public partial class ExtractedField - { - internal ExtractedField() { } - public float Confidence { get { throw null; } } - public string Name { get { throw null; } } - public Azure.AI.FormRecognizer.Models.BoundingBox NameBoundingBox { get { throw null; } } - public System.Collections.Generic.IReadOnlyList NameRawExtractedItems { get { throw null; } } - public string Value { get { throw null; } } - public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } - public System.Collections.Generic.IReadOnlyList ValueRawExtractedItems { get { throw null; } } - } - public partial class ExtractedLabeledField - { - internal ExtractedLabeledField() { } - public float? Confidence { get { throw null; } } - public string Label { get { throw null; } } - public int? PageNumber { get { throw null; } } - public System.Collections.Generic.IReadOnlyList RawExtractedItems { get { throw null; } } - public string Value { get { throw null; } } - public Azure.AI.FormRecognizer.Models.BoundingBox ValueBoundingBox { get { throw null; } } - } - public partial class ExtractedLabeledForm - { - internal ExtractedLabeledForm() { } - public int EndPageNumber { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } - public string FormType { get { throw null; } } - public System.Collections.Generic.IReadOnlyList RawExtractedPages { get { throw null; } } - public int StartPageNumber { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } - } - public partial class ExtractedLabeledTable : Azure.AI.FormRecognizer.Models.ExtractedTable - { - internal ExtractedLabeledTable() { } - public int PageNumber { get { throw null; } } - } public partial class ExtractedLayoutPage { internal ExtractedLayoutPage() { } @@ -171,15 +192,6 @@ internal ExtractedLayoutPage() { } public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } } - public partial class ExtractedPage - { - internal ExtractedPage() { } - public System.Collections.Generic.IReadOnlyList Fields { get { throw null; } } - public int? FormTypeId { get { throw null; } } - public int PageNumber { get { throw null; } } - public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } - } public partial class ExtractedReceipt { internal ExtractedReceipt() { } @@ -275,19 +287,6 @@ public enum LengthUnit Pixel = 0, Inch = 1, } - public enum ModelStatus - { - Creating = 0, - Ready = 1, - Invalid = 2, - } - public enum OperationStatus - { - NotStarted = 0, - Running = 1, - Succeeded = 2, - Failed = 3, - } public partial class RawExtractedItem { internal RawExtractedItem() { } @@ -318,10 +317,4 @@ internal RawExtractedWord() { } public float? Confidence { get { throw null; } } public static implicit operator string (Azure.AI.FormRecognizer.Models.RawExtractedWord word) { throw null; } } - public enum TrainStatus - { - Succeeded = 0, - PartiallySucceeded = 1, - Failed = 2, - } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs index fdb3db22daf4..01760ec0ac86 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs @@ -22,7 +22,7 @@ internal CustomModelInfo(ModelInfo_internal modelInfo) /// /// - public ModelStatus TrainingStatus { get; } + public TrainingStatus TrainingStatus { get; } /// /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs index 9a3922f98e1f..5e503d040ffd 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs @@ -6,10 +6,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Azure.AI.FormRecognizer.Models; using Azure.Core; using Azure.Core.Pipeline; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { /// /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs index f0c547891d63..52a19ec97386 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs @@ -6,10 +6,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Azure.AI.FormRecognizer.Models; using Azure.Core; using Azure.Core.Pipeline; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { /// /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs index aee7d44c1130..d66aa85d0e9c 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedField.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; +using Azure.AI.FormRecognizer.Models; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { // Maps to KeyValuePair public class ExtractedField diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs index 91957b8f7a86..5c12f787ee06 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledField.cs @@ -2,8 +2,9 @@ // Licensed under the MIT License. using System.Collections.Generic; +using Azure.AI.FormRecognizer.Models; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { // Maps to FieldValue in swagger. public class ExtractedLabeledField diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs index 4b5714a4e9e7..29b16a6ba262 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; +using Azure.AI.FormRecognizer.Models; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { public class ExtractedLabeledForm { @@ -20,7 +21,7 @@ internal ExtractedLabeledForm(DocumentResult_internal documentResult, IList ConvertRawPages(IList ConvertLabeledTables(IList pageResults, IList readResults) + { + List tables = new List(); + + foreach (var pageResult in pageResults) + { + foreach (var table in pageResult.Tables) + { + tables.Add(new ExtractedLabeledTable(table, readResults[pageResult.Page - 1], pageResult.Page)); + } + } + + return tables; + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs index 8773c5fd8b74..b5566435e1ef 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledTable.cs @@ -6,7 +6,7 @@ using System.Text; using Azure.AI.FormRecognizer.Models; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { public class ExtractedLabeledTable : ExtractedTable { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs index f1c1cc7b870b..7716d5d1c27a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLayoutPage.cs @@ -35,20 +35,5 @@ internal static IReadOnlyList ConvertTables(ICollection ConvertLabeledTables(IList pageResults, IList readResults) - { - List tables = new List(); - - foreach (var pageResult in pageResults) - { - foreach (var table in pageResult.Tables) - { - tables.Add(new ExtractedLabeledTable(table, readResults[pageResult.Page - 1], pageResult.Page)); - } - } - - return tables; - } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs index 88e841bdb0b1..e9206980035d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs @@ -2,8 +2,9 @@ // Licensed under the MIT License. using System.Collections.Generic; +using Azure.AI.FormRecognizer.Models; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { // Maps to PageResult public class ExtractedPage diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTableCell.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTableCell.cs index d1dd908a5b1c..e6c75bc366f1 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTableCell.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedTableCell.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Collections.Generic; +using Azure.AI.FormRecognizer.Custom; namespace Azure.AI.FormRecognizer.Models { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/AnalyzeOperationResult_internal.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/AnalyzeOperationResult_internal.cs index e3e1f4339674..9229368ee6c2 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/AnalyzeOperationResult_internal.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/AnalyzeOperationResult_internal.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using Azure.AI.FormRecognizer; namespace Azure.AI.FormRecognizer.Models { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs index d4f5f7f706bf..229026260137 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs @@ -8,7 +8,7 @@ using System.Text.Json; using Azure.Core; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { internal partial class ModelInfo_internal : IUtf8JsonSerializable { @@ -37,7 +37,7 @@ internal static ModelInfo_internal DeserializeModelInfo_internal(JsonElement ele } if (property.NameEquals("status")) { - result.Status = property.Value.GetString().ToModelStatus(); + result.Status = property.Value.GetString().ToTrainingStatus(); continue; } if (property.NameEquals("createdDateTime")) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs index 79ef46c082b5..1eb691e2ce9a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs @@ -7,7 +7,7 @@ using System; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { /// Basic custom model information. internal partial class ModelInfo_internal @@ -15,7 +15,7 @@ internal partial class ModelInfo_internal /// Model identifier. public Guid ModelId { get; set; } /// Status of the model. - public ModelStatus Status { get; set; } + public TrainingStatus Status { get; set; } /// Date and time (UTC) when the model was created. public DateTimeOffset CreatedDateTime { get; set; } /// Date and time (UTC) when the status was last updated. diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs deleted file mode 100644 index ca409f3bd7c1..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.AI.FormRecognizer.Models -{ - internal static class ModelStatusExtensions - { - public static string ToSerialString(this ModelStatus value) => value switch - { - ModelStatus.Creating => "creating", - ModelStatus.Ready => "ready", - ModelStatus.Invalid => "invalid", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ModelStatus value.") - }; - - public static ModelStatus ToModelStatus(this string value) - { - if (string.Equals(value, "creating", StringComparison.InvariantCultureIgnoreCase)) return ModelStatus.Creating; - if (string.Equals(value, "ready", StringComparison.InvariantCultureIgnoreCase)) return ModelStatus.Ready; - if (string.Equals(value, "invalid", StringComparison.InvariantCultureIgnoreCase)) return ModelStatus.Invalid; - throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ModelStatus value."); - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.cs deleted file mode 100644 index f1388b9560dc..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -namespace Azure.AI.FormRecognizer.Models -{ - /// Status of the model. - public enum ModelStatus - { - /// creating. - Creating, - /// ready. - Ready, - /// invalid. - Invalid - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.Serialization.cs index e18f954e4305..7c3fc03ccce9 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.Serialization.cs @@ -7,6 +7,7 @@ using System.Text.Json; using Azure.AI.FormRecognizer; +using Azure.AI.FormRecognizer.Custom; using Azure.Core; namespace Azure.AI.FormRecognizer.Models diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.cs index f959b663eb93..40e31c927bdf 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Model_internal.cs @@ -6,6 +6,7 @@ #nullable disable using Azure.AI.FormRecognizer; +using Azure.AI.FormRecognizer.Custom; namespace Azure.AI.FormRecognizer.Models { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.Serialization.cs index 9e40f3c65dc2..ec54971f9f7d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.Serialization.cs @@ -8,7 +8,6 @@ using System.Collections.Generic; using System.Text.Json; using Azure.AI.FormRecognizer; -using Azure.AI.FormRecognizer.Models; using Azure.Core; namespace Azure.AI.FormRecognizer.Custom diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.cs index f650a1bf07d7..1471593d67e7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/Models_internal.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using Azure.AI.FormRecognizer; -using Azure.AI.FormRecognizer.Models; namespace Azure.AI.FormRecognizer.Custom { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.Serialization.cs index c97b388d8bd6..a6cc2500560a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.Serialization.cs @@ -7,7 +7,7 @@ using System; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer { internal static class OperationStatusExtensions { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.Serialization.cs deleted file mode 100644 index 1cd3accb1361..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.Serialization.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.AI.FormRecognizer.Models -{ - internal static class TrainStatusExtensions - { - public static string ToSerialString(this TrainStatus value) => value switch - { - TrainStatus.Succeeded => "succeeded", - TrainStatus.PartiallySucceeded => "partiallySucceeded", - TrainStatus.Failed => "failed", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainStatus value.") - }; - - public static TrainStatus ToTrainStatus(this string value) - { - if (string.Equals(value, "succeeded", StringComparison.InvariantCultureIgnoreCase)) return TrainStatus.Succeeded; - if (string.Equals(value, "partiallySucceeded", StringComparison.InvariantCultureIgnoreCase)) return TrainStatus.PartiallySucceeded; - if (string.Equals(value, "failed", StringComparison.InvariantCultureIgnoreCase)) return TrainStatus.Failed; - throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainStatus value."); - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.cs deleted file mode 100644 index fbf75e098a14..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainStatus.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -namespace Azure.AI.FormRecognizer.Models -{ - /// Status of the training operation. - public enum TrainStatus - { - /// succeeded. - Succeeded, - /// partiallySucceeded. - PartiallySucceeded, - /// failed. - Failed - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs index fd404b5f8032..03cf4f25cb38 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs @@ -56,7 +56,7 @@ internal static TrainingDocumentInfo DeserializeTrainingDocumentInfo(JsonElement } if (property.NameEquals("status")) { - result.Status = property.Value.GetString().ToTrainStatus(); + result.Status = property.Value.GetString().ToTrainingOutcome(); continue; } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs index 4071aec4be5e..56ae97aa96fd 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs @@ -18,6 +18,6 @@ public partial class TrainingDocumentInfo /// List of errors. public IList Errors { get; set; } = new List(); /// Status of the training operation. - public TrainStatus Status { get; set; } + public TrainingOutcome Status { get; set; } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs new file mode 100644 index 000000000000..2dea697242bf --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.AI.FormRecognizer.Custom +{ + internal static class TrainingOutcomeExtensions + { + public static string ToSerialString(this TrainingOutcome value) => value switch + { + TrainingOutcome.Succeeded => "succeeded", + TrainingOutcome.PartiallySucceeded => "partiallySucceeded", + TrainingOutcome.Failed => "failed", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingOutcome value.") + }; + + public static TrainingOutcome ToTrainingOutcome(this string value) + { + if (string.Equals(value, "succeeded", StringComparison.InvariantCultureIgnoreCase)) return TrainingOutcome.Succeeded; + if (string.Equals(value, "partiallySucceeded", StringComparison.InvariantCultureIgnoreCase)) return TrainingOutcome.PartiallySucceeded; + if (string.Equals(value, "failed", StringComparison.InvariantCultureIgnoreCase)) return TrainingOutcome.Failed; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingOutcome value."); + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs new file mode 100644 index 000000000000..4b2561222f09 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.AI.FormRecognizer.Custom +{ + internal static class TrainingStatusExtensions + { + public static string ToSerialString(this TrainingStatus value) => value switch + { + TrainingStatus.Training => "creating", + TrainingStatus.Ready => "ready", + TrainingStatus.Invalid => "invalid", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingStatus value.") + }; + + public static TrainingStatus ToTrainingStatus(this string value) + { + if (string.Equals(value, "creating", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Training; + if (string.Equals(value, "ready", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Ready; + if (string.Equals(value, "invalid", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Invalid; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingStatus value."); + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs index 314bb81f6fc1..35473f54dcc7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Azure; +using Azure.AI.FormRecognizer.Custom; using Azure.AI.FormRecognizer.Models; using Azure.Core; using Azure.Core.Pipeline; diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelInfo_internal.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelInfo_internal.cs index 15c8bd44311c..373a5e5b3a0a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelInfo_internal.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelInfo_internal.cs @@ -3,7 +3,7 @@ using Azure.Core; -namespace Azure.AI.FormRecognizer.Models +namespace Azure.AI.FormRecognizer.Custom { [CodeGenSchema("ModelInfo")] internal partial class ModelInfo_internal diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/OperationStatus.cs similarity index 53% rename from sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.cs rename to sdk/formrecognizer/Azure.AI.FormRecognizer/src/OperationStatus.cs index 089e980475ff..5d2321d10379 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/OperationStatus.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/OperationStatus.cs @@ -1,14 +1,15 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// -#nullable disable - -namespace Azure.AI.FormRecognizer.Models +using System; +using System.Collections.Generic; +using System.Text; +using Azure.Core; +namespace Azure.AI.FormRecognizer { - /// Status of the queued operation. - public enum OperationStatus + [CodeGenSchema("OperationStatus")] + internal enum OperationStatus { /// notStarted. NotStarted, diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs index d756aee62c67..71cb3ae68501 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs @@ -90,7 +90,7 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can // TODO: Handle correctly according to returned status code // https://github.com/Azure/azure-sdk-for-net/issues/10386 - if (update.Value.ModelInfo.Status != ModelStatus.Creating) + if (update.Value.ModelInfo.Status != TrainingStatus.Training) { _hasCompleted = true; _value = new CustomModel(update.Value); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs new file mode 100644 index 000000000000..d6a048d9cfef --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.AI.FormRecognizer.Custom +{ + [CodeGenSchema("TrainStatus")] +#pragma warning disable CA1717 // Only FlagsAttribute enums should have plural names + public enum TrainingOutcome +#pragma warning restore CA1717 // Only FlagsAttribute enums should have plural names + { + Succeeded, + PartiallySucceeded, + Failed, + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs new file mode 100644 index 000000000000..93b78892adac --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + + +using System; +using System.Collections.Generic; +using System.Text; +using Azure.Core; + +namespace Azure.AI.FormRecognizer.Custom +{ + [CodeGenSchema("ModelStatus")] +#pragma warning disable CA1717 // Only FlagsAttribute enums should have plural names + public enum TrainingStatus +#pragma warning restore CA1717 // Only FlagsAttribute enums should have plural names + { + [CodeGenSchemaMember("creating")] + Training, + Ready, + Invalid + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs index fb2f480a0747..2db2b6f1adf4 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs @@ -87,7 +87,7 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can // TODO: Handle correctly according to returned status code // https://github.com/Azure/azure-sdk-for-net/issues/10386 - if (update.Value.ModelInfo.Status != ModelStatus.Creating) + if (update.Value.ModelInfo.Status != TrainingStatus.Training) { _hasCompleted = true; _value = new CustomLabeledModel(update.Value); From 167e71506a95a0d5b5f5cfe81d850c5e5746a4fd Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Fri, 13 Mar 2020 11:52:30 -0700 Subject: [PATCH 14/32] client docstrings --- .../src/CustomFormClient.cs | 135 +++++++++++++++++- .../src/FormLayoutClient.cs | 40 +++++- .../src/ReceiptClient.cs | 35 +++++ 3 files changed, 206 insertions(+), 4 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index ca93d4f2c30e..948850b6d44e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -13,7 +13,9 @@ namespace Azure.AI.FormRecognizer.Custom { /// - /// The sample client. + /// The client to use to with the Form Recognizer Azure Cognitive Service to train custom models from forms, + /// and to extract values from forms using those custom models. It also supports listing and deleting trained + /// models. /// public class CustomFormClient { @@ -52,6 +54,14 @@ public CustomFormClient(Uri endpoint, FormRecognizerApiKeyCredential credential, } #region Training + + /// + /// Trains a model from a collection of custom forms in a blob storage container. + /// + /// An externally accessible Azure storage blob container Uri. + /// Filter to apply to the documents in the source path for training. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation StartTraining(string source, TrainingFileFilter filter = default, CancellationToken cancellationToken = default) { TrainRequest_internal trainRequest = new TrainRequest_internal() { Source = source }; @@ -70,6 +80,13 @@ public virtual Operation StartTraining(string source, TrainingFileF return new TrainingOperation(_operations, response.Headers.Location); } + /// + /// Trains a model from a collection of custom forms in a blob storage container. + /// + /// An externally accessible Azure storage blob container Uri. + /// Filter to apply to the documents in the source path for training. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task> StartTrainingAsync(string source, TrainingFileFilter filter = default, CancellationToken cancellationToken = default) { TrainRequest_internal trainRequest = new TrainRequest_internal() { Source = source }; @@ -85,6 +102,13 @@ public virtual async Task> StartTrainingAsync(string sour return new TrainingOperation(_operations, response.Headers.Location); } + /// + /// Trains a model from a collection of custom forms and a label file in a blob storage container. + /// + /// An externally accessible Azure storage blob container Uri. + /// Filter to apply to the documents in the source path for training. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation StartTrainingWithLabels(string source, TrainingFileFilter filter = default, CancellationToken cancellationToken = default) { TrainRequest_internal trainRequest = new TrainRequest_internal() { Source = source, UseLabelFile = true }; @@ -100,6 +124,13 @@ public virtual Operation StartTrainingWithLabels(string sour return new TrainingWithLabelsOperation(_operations, response.Headers.Location); } + /// + /// Trains a model from a collection of custom forms and a label file in a blob storage container. + /// + /// An externally accessible Azure storage blob container Uri. + /// Filter to apply to the documents in the source path for training. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task> StartTrainingWithLabelsAsync(string source, TrainingFileFilter filter = default, CancellationToken cancellationToken = default) { TrainRequest_internal trainRequest = new TrainRequest_internal() { Source = source, UseLabelFile = true }; @@ -120,6 +151,16 @@ public virtual async Task> StartTrainingWithLabels #region Analyze #region Unsupervised + + /// + /// Extract pages from one or more forms, using a model trained without labels. + /// + /// The id of the model to use for extracting form values. + /// The stream containing one or more forms to extract elements from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractFormPages(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -128,6 +169,14 @@ public virtual Operation> StartExtractFormPages(str return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); } + /// + /// Extract pages from one or more forms, using a model trained without labels. + /// + /// The id of the model to use for extracting form values. + /// The absolute URI of the remote file to extract elements from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractFormPages(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; @@ -135,6 +184,15 @@ public virtual Operation> StartExtractFormPages(str return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); } + /// + /// Extract pages from one or more forms, using a model trained without labels. + /// + /// The id of the model to use for extracting form values. + /// The stream containing one or more forms to extract elements from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractFormPagesAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -143,6 +201,15 @@ public virtual async Task>> StartExtractF return new ExtractPagesOperation(_operations, modelId, response.Headers.OperationLocation); } + + /// + /// Extract pages from one or more forms, using a model trained without labels. + /// + /// The id of the model to use for extracting form values. + /// The absolute URI of the remote file to extract elements from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractFormPagesAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; @@ -152,6 +219,17 @@ public virtual async Task>> StartExtractF #endregion #region Supervised + + + /// + /// Extract form content from one or more forms, using a model trained with labels. + /// + /// The id of the model to use for extracting form values. + /// The stream containing one or more forms to extract elements from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractLabeledForms(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -160,6 +238,14 @@ public virtual Operation> StartExtractLabele return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } + /// + /// Extract form content from one or more forms, using a model trained with labels. + /// + /// The id of the model to use for extracting form values. + /// The absolute URI of the remote file to extract elements from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractLabeledForms(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; @@ -167,6 +253,15 @@ public virtual Operation> StartExtractLabele return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } + /// + /// Extract form content from one or more forms, using a model trained with labels. + /// + /// The id of the model to use for extracting form values. + /// The stream containing one or more forms to extract elements from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractLabeledFormsAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -175,6 +270,14 @@ public virtual async Task>> StartE return new ExtractLabeledFormOperation(_operations, modelId, response.Headers.OperationLocation); } + /// + /// Extract form content from one or more forms, using a model trained with labels. + /// + /// The id of the model to use for extracting form values. + /// The absolute URI of the remote file to extract elements from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractLabeledFormsAsync(string modelId, Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; @@ -186,28 +289,55 @@ public virtual async Task>> StartE #endregion Analyze #region CRUD Ops + /// + /// Delete the model with the specified model ID. + /// + /// The ID of the model to delete. + /// A controlling the request lifetime. + /// public virtual Response DeleteModel(string modelId, CancellationToken cancellationToken = default) { return _operations.DeleteCustomModel(new Guid(modelId), cancellationToken); } + /// + /// Delete the model with the specified model ID. + /// + /// The ID of the model to delete. + /// A controlling the request lifetime. + /// public virtual async Task DeleteModelAsync(string modelId, CancellationToken cancellationToken = default) { return await _operations.DeleteCustomModelAsync(new Guid(modelId), cancellationToken).ConfigureAwait(false); } + /// + /// Get a collection of items describing the models trained on this subscription + /// and their training status. + /// + /// + /// public virtual Pageable GetModelInfos(CancellationToken cancellationToken = default) { return _operations.GetCustomModelsPageableModelInfo(GetModelOptions.Full, cancellationToken); } + /// + /// Get a collection of items describing the models trained on this subscription + /// and their training status. + /// + /// + /// public virtual AsyncPageable GetModelInfosAsync(CancellationToken cancellationToken = default) { return _operations.GetCustomModelsPageableModelInfoAsync(GetModelOptions.Full, cancellationToken); } /// + /// Get the number of models trained on this subscription and the subscription limits. /// + /// + /// public virtual Response GetSubscriptionProperties(CancellationToken cancellationToken = default) { Response response = _operations.RestClient.GetCustomModels(GetModelOptions.Summary, cancellationToken); @@ -215,7 +345,10 @@ public virtual Response GetSubscriptionProperties(Cancel } /// + /// Get the number of models trained on this subscription and the subscription limits. /// + /// + /// public virtual async Task> GetSubscriptionPropertiesAsync(CancellationToken cancellationToken = default) { Response response = await _operations.RestClient.GetCustomModelsAsync(GetModelOptions.Summary, cancellationToken).ConfigureAwait(false); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs index b406baf5032f..f33bbdcd5b94 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs @@ -12,6 +12,10 @@ namespace Azure.AI.FormRecognizer { + + /// + /// The client to use to with the Form Recognizer Azure Cognitive Service, to extract layout elements like tables from forms. + /// public class FormLayoutClient { private readonly ClientDiagnostics _diagnostics; @@ -25,7 +29,7 @@ protected FormLayoutClient() } /// - /// Initializes a new instance of the . + /// Initializes a new instance of the . /// #pragma warning disable AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. public FormLayoutClient(Uri endpoint, FormRecognizerApiKeyCredential credential) : this(endpoint, credential, new FormRecognizerClientOptions()) @@ -34,7 +38,7 @@ protected FormLayoutClient() } /// - /// Initializes a new instance of the . + /// Initializes a new instance of the . /// #pragma warning disable AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. public FormLayoutClient(Uri endpoint, FormRecognizerApiKeyCredential credential, FormRecognizerClientOptions options) @@ -45,14 +49,30 @@ public FormLayoutClient(Uri endpoint, FormRecognizerApiKeyCredential credential, _operations = new ServiceClient(_diagnostics, _pipeline, endpoint.ToString()); } + /// + /// Extracts layout elements from one or more passed-in forms. + /// + /// The stream containing one or more forms to extract elements from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractLayouts(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 - ResponseWithHeaders response = _operations.AnalyzeLayoutAsync(stream, contentType , cancellationToken); + ResponseWithHeaders response = _operations.AnalyzeLayoutAsync(stream, contentType, cancellationToken); return new ExtractLayoutOperation(_operations, response.Headers.OperationLocation); } + /// + /// Extracts layout elements from one or more passed-in forms. + /// + /// The stream containing one or more forms to extract elements from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractLayoutsAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -61,6 +81,13 @@ public virtual async Task>> StartEx return new ExtractLayoutOperation(_operations, response.Headers.OperationLocation); } + /// + /// Extracts layout elements from one or more passed-in forms. + /// + /// The absolute URI of the remote file to extract elements from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// + /// A to wait on this long-running operation. public virtual Operation> StartExtractLayouts(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; @@ -68,6 +95,13 @@ public virtual Operation> StartExtractLayouts return new ExtractLayoutOperation(_operations, response.Headers.OperationLocation); } + /// + /// Extracts layout elements from one or more passed-in forms. + /// + /// The absolute URI of the remote file to extract elements from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// + /// A to wait on this long-running operation. public virtual async Task>> StartExtractLayoutsAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs index 3f8f1047be4f..d7b24a084922 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs @@ -12,6 +12,10 @@ namespace Azure.AI.FormRecognizer { + + /// + /// The client to use to with the Form Recognizer Azure Cognitive Service, to extract values from receipts. + /// public class ReceiptClient { private readonly ClientDiagnostics _diagnostics; @@ -45,6 +49,14 @@ public ReceiptClient(Uri endpoint, FormRecognizerApiKeyCredential credential, Fo _operations = new ServiceClient(_diagnostics, _pipeline, endpoint.ToString()); } + /// + /// Extracts values from one or more receipts. + /// + /// The stream containing the one or more receipts to extract values from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractReceipts(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -53,6 +65,14 @@ public virtual Operation> StartExtractReceipts(S return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } + /// + /// Extracts values from one or more receipts. + /// + /// The stream containing the one or more receipts to extract values from. + /// The content type of the input file. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual Operation> StartExtractReceipts(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; @@ -60,6 +80,14 @@ public virtual Operation> StartExtractReceipts(U return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } + + /// + /// Extracts values from one or more receipts. + /// + /// The absolute URI of the remote file to extract values from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractReceiptsAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection @@ -68,6 +96,13 @@ public virtual async Task>> StartExtra return new ExtractReceiptOperation(_operations, response.Headers.OperationLocation); } + /// + /// Extracts values from one or more receipts. + /// + /// The absolute URI of the remote file to extract values from. + /// Whether or not to include raw page extractions in addition to layout elements. + /// A controlling the request lifetime. + /// A to wait on this long-running operation. public virtual async Task>> StartExtractReceiptsAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; From a3d105bd19e8f3ac5fc75cb55acabfb86f25b9e2 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Sun, 15 Mar 2020 15:08:23 -0700 Subject: [PATCH 15/32] README --- .../Azure.AI.FormRecognizer/README.md | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/README.md diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md new file mode 100644 index 000000000000..0fb41173e275 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -0,0 +1,172 @@ +# Azure Cognitive Services Form Recognizer client library for .NET +Azure Cognitive Services Form Recognizer is a cloud service that uses machine learning to extract text and table data from form documents. It allows you to train custom models using your own forms, to extract field names and values, and table data from them. It also provides a prebuilt models you can use to extract values from receipts, or tables from any form. + +[Source code][formreco_client_src] | [Package (NuGet)][] | [API reference documentation][] | [Product documentation][formreco_docs] | [Samples][] + +## Getting started + +### Prerequisites +* An [Azure subscription][azure_sub]. +* An existing Form Recognizer resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli]. + + + +### Authenticate a Form Recognizer client +In order to interact with the Form Recognizer service, you'll need to select either a ReceiptClient, FormLayoutClient, or CustomFormClient, and create an instance of this class. For the remainder of this README, we will use CustomFormClient as an example. You will need an **endpoint**, and either a **subscription key** or ``TokenCredential`` to instantiate a client object. For more information regarding authenticating with cognitive services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth]. + +#### Get Subscription Key + +You can obtain the endpoint and subscription key from the resource information in the [Azure Portal][azure_portal]. + +Alternatively, you can use the [Azure CLI][azure_cli] snippet below to get the subscription key from the Form Recognizer resource. + +```PowerShell +az cognitiveservices account keys list --resource-group --name +``` + +#### Create CustomFormClient with Subscription Key Credential +Once you have the value for the subscription key, create a `FormRecognizerApiKeyCredential`. This will allow you to update the subscription key by using the `UpdateCredential` method without creating a new client. + + +With the value of the endpoint and a `FormRecognizerApiKeyCredential`, you can create the [CustomFormClient][formreco_custom_client_class]: + +```C# Snippet:CreateCustomFormClient +string endpoint = ""; +string subscriptionKey = ""; +var credential = new FormRecognizerApiKeyCredential(subscriptionKey); +var client = new FormRecognizerClient(new Uri(endpoint), credential); +``` + + + +## Key concepts + +### ReceiptClient +A `ReceiptClient` is the Form Recognizer interface to use for receipt recognition. It provides operations to extract receipt field values and locations. + +### FormLayoutClient +A `FormLayoutClient` is the Form Recognizer interface to extract layout items from forms. It provides operations to extract table data and geometry. + +### CustomFormClient +A `CustomFormClient` is the Form Recognizer interface to use for creating, using, and managing custom machine-learned models. It provides operations for training models on forms you provide, and extracting field values and locations from your custom forms. It also provides operations for viewing and deleting models, as well as understanding how close you are to reaching subscription limits for the number of models you can train. + +### Training models +Using the `CustomFormClient`, you can train a machine-learned model on your own form type. The resulting model will be able to extract values from the types of forms it was trained on. + +#### Training without labels +A model trained without labels uses unsupervised learning to understand the layout and relationships between field names and values in your forms. The learning algorithm clusters the training forms by type and learns what fields and tables are present in each form type. + +This approach doesn't require manual data labeling or intensive coding and maintenance, and we recommend you try this method first. + +#### Training with labels +A model trained with labels uses supervised learning to extract values you specify by adding labels to your training forms. The learning algorithm uses a label file you provide to learn what fields are found at various locations in the form, and typicaly labeled to indicate the value's semantics. + +This approach can result in better-performing models, and those models can work with more complex form structures. + +### Extracting values from forms +Using the `CustomFormClient`, you can use your own trained models to extract field values and locations, as well as table data, from forms of the type you trained the model on. The output of models trained with and without labels differs as described below. + +#### Using models trained without labels +Models trained without labels consider each form page to be a different form type. For example, if you train your model on 3-page forms, it will learn that these are three different types of forms. When you send a form to it for analysis, it will return a collection of three pages, where each page contains the field names, values, and locations, as well as table data, found on that page. + +#### Using models trained with labels +Models trained with labels consider a form as a holistic unit. For example, if you train your model on 3-page forms with labels, it will learn to extract field values from the locations you've labeled. When you send a document containing two forms to it for analysis, it will return a collection of two forms, where each form contains the field names, values, and locations, as well as table data, found in that form. Fields and tables have page numbers to identify the pages where they were found. + +### Managing Custom Models +Using the `CustomFormClient`, you can get, list, and delete the custom models you've trained. You can also view the count of model you've trained and the maximum number of models your subscription will allow you to store. + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla]. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments. + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftextanalytics%2FAzure.AI.TextAnalytics%2FREADME.png) + + + +[formreco_client_src]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/formrecognizer/Azure.AI.FormRecognizer/src +[formreco_docs]: https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/ +[formreco_refdocs]: https://aka.ms/azsdk-net-textanalytics-ref-docs + + +[formreco_rest_api]: https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api-v2-preview +[cognitive_resource]: https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account + + + + +[formreco_custom_client_class]: src/CustomFormClient.cs +[azure_identity]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/identity/Azure.Identity +[cognitive_auth]: https://docs.microsoft.com/en-us/azure/cognitive-services/authentication +[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal +[aad_grant_access]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal +[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain +[DefaultAzureCredential]: ../../identity/Azure.Identity/README.md + + + +[azure_cli]: https://docs.microsoft.com/cli/azure +[azure_sub]: https://azure.microsoft.com/free/ +[nuget]: https://www.nuget.org/ +[azure_portal]: https://portal.azure.com + +[cla]: https://cla.microsoft.com +[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ +[coc_contact]: mailto:opencode@microsoft.com \ No newline at end of file From 1f8e764ec2059b9e6f18b8bf7adb8a2269c924a9 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Sun, 15 Mar 2020 15:10:50 -0700 Subject: [PATCH 16/32] README nits --- sdk/formrecognizer/Azure.AI.FormRecognizer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md index 0fb41173e275..a15262dec46a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -1,7 +1,7 @@ # Azure Cognitive Services Form Recognizer client library for .NET Azure Cognitive Services Form Recognizer is a cloud service that uses machine learning to extract text and table data from form documents. It allows you to train custom models using your own forms, to extract field names and values, and table data from them. It also provides a prebuilt models you can use to extract values from receipts, or tables from any form. -[Source code][formreco_client_src] | [Package (NuGet)][] | [API reference documentation][] | [Product documentation][formreco_docs] | [Samples][] +[Source code][formreco_client_src] | [Package (NuGet)]() | [API reference documentation]() | [Product documentation][formreco_docs] | [Samples]() ## Getting started From 805b55fb702c873efd16d18736f9fb1e26c2347d Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Sun, 15 Mar 2020 15:22:52 -0700 Subject: [PATCH 17/32] README nits --- .../Azure.AI.FormRecognizer/README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md index a15262dec46a..a453679d11c9 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -25,7 +25,7 @@ For other installation methods, please see the package information on [NuGet][nu --> ### Authenticate a Form Recognizer client -In order to interact with the Form Recognizer service, you'll need to select either a ReceiptClient, FormLayoutClient, or CustomFormClient, and create an instance of this class. For the remainder of this README, we will use CustomFormClient as an example. You will need an **endpoint**, and either a **subscription key** or ``TokenCredential`` to instantiate a client object. For more information regarding authenticating with cognitive services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth]. +In order to interact with the Form Recognizer service, you'll need to select either a `ReceiptClient`, `FormLayoutClient`, or `CustomFormClient`, and create an instance of this class. In the following samples, we will use CustomFormClient as an example. You will need an **endpoint**, and either a **subscription key** or ``TokenCredential`` to instantiate a client object. For more information regarding authenticating with cognitive services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth]. #### Get Subscription Key @@ -40,7 +40,6 @@ az cognitiveservices account keys list --resource-group With the value of the endpoint and a `FormRecognizerApiKeyCredential`, you can create the [CustomFormClient][formreco_custom_client_class]: ```C# Snippet:CreateCustomFormClient @@ -73,7 +72,7 @@ var client = new TextAnalyticsClient(new Uri(endpoint), new DefaultAzureCredenti ## Key concepts ### ReceiptClient -A `ReceiptClient` is the Form Recognizer interface to use for receipt recognition. It provides operations to extract receipt field values and locations. +A `ReceiptClient` is the Form Recognizer interface to use for analyzing receipts. It provides operations to extract receipt field values and locations from receipts from the United States. ### FormLayoutClient A `FormLayoutClient` is the Form Recognizer interface to extract layout items from forms. It provides operations to extract table data and geometry. @@ -87,24 +86,24 @@ Using the `CustomFormClient`, you can train a machine-learned model on your own #### Training without labels A model trained without labels uses unsupervised learning to understand the layout and relationships between field names and values in your forms. The learning algorithm clusters the training forms by type and learns what fields and tables are present in each form type. -This approach doesn't require manual data labeling or intensive coding and maintenance, and we recommend you try this method first. +This approach doesn't require manual data labeling or intensive coding and maintenance, and we recommend you try this method first when training custom models. #### Training with labels -A model trained with labels uses supervised learning to extract values you specify by adding labels to your training forms. The learning algorithm uses a label file you provide to learn what fields are found at various locations in the form, and typicaly labeled to indicate the value's semantics. +A model trained with labels uses supervised learning to extract values you specify by adding labels to your training forms. The learning algorithm uses a label file you provide to learn what fields are found at various locations in the form, and learns to extract just those values. This approach can result in better-performing models, and those models can work with more complex form structures. ### Extracting values from forms -Using the `CustomFormClient`, you can use your own trained models to extract field values and locations, as well as table data, from forms of the type you trained the model on. The output of models trained with and without labels differs as described below. +Using the `CustomFormClient`, you can use your own trained models to extract field values and locations, as well as table data, from forms of the type you trained your models on. The output of models trained with and without labels differs as described below. #### Using models trained without labels Models trained without labels consider each form page to be a different form type. For example, if you train your model on 3-page forms, it will learn that these are three different types of forms. When you send a form to it for analysis, it will return a collection of three pages, where each page contains the field names, values, and locations, as well as table data, found on that page. #### Using models trained with labels -Models trained with labels consider a form as a holistic unit. For example, if you train your model on 3-page forms with labels, it will learn to extract field values from the locations you've labeled. When you send a document containing two forms to it for analysis, it will return a collection of two forms, where each form contains the field names, values, and locations, as well as table data, found in that form. Fields and tables have page numbers to identify the pages where they were found. +Models trained with labels consider a form as a single unit. For example, if you train your model on 3-page forms with labels, it will learn to extract field values from the locations you've labeled across all pages in the form. If you sent a document containing two forms to it for analysis, it would return a collection of two forms, where each form contains the field names, values, and locations, as well as table data, found in that form. Fields and tables have page numbers to identify the pages where they were found. ### Managing Custom Models -Using the `CustomFormClient`, you can get, list, and delete the custom models you've trained. You can also view the count of model you've trained and the maximum number of models your subscription will allow you to store. +Using the `CustomFormClient`, you can get, list, and delete the custom models you've trained. You can also view the count of models you've trained and the maximum number of models your subscription will allow you to store. ## Contributing From 432ea3c2728f65251a6074fc9fda61b0850f0528 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Mon, 16 Mar 2020 07:11:29 -0700 Subject: [PATCH 18/32] README nit --- sdk/formrecognizer/Azure.AI.FormRecognizer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md index a453679d11c9..88178decb7cc 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -1,7 +1,7 @@ # Azure Cognitive Services Form Recognizer client library for .NET Azure Cognitive Services Form Recognizer is a cloud service that uses machine learning to extract text and table data from form documents. It allows you to train custom models using your own forms, to extract field names and values, and table data from them. It also provides a prebuilt models you can use to extract values from receipts, or tables from any form. -[Source code][formreco_client_src] | [Package (NuGet)]() | [API reference documentation]() | [Product documentation][formreco_docs] | [Samples]() +[Source code][formreco_client_src] | [Product documentation][formreco_docs] ## Getting started From fcdbe1d58dea1f258c5aca328a75a29f0cafda9f Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Mon, 16 Mar 2020 07:14:55 -0700 Subject: [PATCH 19/32] README nit --- sdk/formrecognizer/Azure.AI.FormRecognizer/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md index 88178decb7cc..de3b203dc1a6 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -46,10 +46,10 @@ With the value of the endpoint and a `FormRecognizerApiKeyCredential`, you can c string endpoint = ""; string subscriptionKey = ""; var credential = new FormRecognizerApiKeyCredential(subscriptionKey); -var client = new FormRecognizerClient(new Uri(endpoint), credential); +var client = new CustomFormClient(new Uri(endpoint), credential); ``` - From 2bc47bf2e1afd466ee604ca807a5b98de1283067 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Mon, 16 Mar 2020 13:42:20 -0700 Subject: [PATCH 25/32] docstring updates --- .../src/FormRecognizerError.cs | 11 +++++++++++ .../src/Generated/Models/FormRecognizerError.cs | 8 -------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerError.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerError.cs index 62e7a73163e2..1626e7843efa 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerError.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerError.cs @@ -5,8 +5,19 @@ namespace Azure.AI.FormRecognizer.Models { + /// + /// [CodeGenSchema("ErrorInformation")] public partial class FormRecognizerError { + /// + /// + [CodeGenSchemaMember("Code")] + public string Code { get; set; } + + /// + /// + [CodeGenSchemaMember("Message")] + public string Message { get; set; } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs index 4585a05f8500..62bbb489a9da 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs @@ -10,13 +10,5 @@ namespace Azure.AI.FormRecognizer.Models /// The ErrorInformation. public partial class FormRecognizerError { - - /// - /// - public string Code { get; set; } - - /// - /// - public string Message { get; set; } } } From 875d4d15429f1be00e3118905002f3d7212b89f7 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Mon, 16 Mar 2020 21:03:59 -0700 Subject: [PATCH 26/32] UX study updates --- .../Azure.AI.FormRecognizer/README.md | 28 ++++++++++++++++++- .../src/CustomFormClient.cs | 12 ++++++++ .../src/ExtractedLabeledForm.cs | 16 +++++++++++ .../src/ExtractedPage.cs | 17 +++++++++++ .../src/FieldNotFoundException.cs | 16 +++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldNotFoundException.cs diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md index 095baa347b37..1d7a601fa323 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -42,7 +42,7 @@ Once you have the value for the subscription key, create a `FormRecognizerApiKey With the value of the endpoint and a `FormRecognizerApiKeyCredential`, you can create the [CustomFormClient][formreco_custom_client_class]: -``` +```C# string endpoint = ""; string subscriptionKey = ""; var credential = new FormRecognizerApiKeyCredential(subscriptionKey); @@ -80,6 +80,11 @@ A `FormLayoutClient` is the Form Recognizer interface to extract layout items fr ### CustomFormClient A `CustomFormClient` is the Form Recognizer interface to use for creating, using, and managing custom machine-learned models. It provides operations for training models on forms you provide, and extracting field values and locations from your custom forms. It also provides operations for viewing and deleting models, as well as understanding how close you are to reaching subscription limits for the number of models you can train. +### Long-Running Operations +Long-running operations are operations which consist of an initial request sent to the service to start an operation,followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has succeeded, to get the result. + +Methods that train models or extract values from forms are modeled as long-running operations. The client exposes a `Start` method that returns an `Operation`. Callers should wait for the operation to complete by calling `WaitForCompletionAsync()` on the operation returned from the `Start` method. A sample code snippet is provided to illustrate using long-running operations [below](#extracting-receipt-values-with-a-long-running-operation). + ### Training models Using the `CustomFormClient`, you can train a machine-learned model on your own form type. The resulting model will be able to extract values from the types of forms it was trained on. @@ -105,6 +110,27 @@ Models trained with labels consider a form as a single unit. For example, if yo ### Managing Custom Models Using the `CustomFormClient`, you can get, list, and delete the custom models you've trained. You can also view the count of models you've trained and the maximum number of models your subscription will allow you to store. +## Examples +The following section provides several code snippets illustrating common patterns used in the Form Recognizer .NET API. + +### Extracting receipt values with a long-running operation +```C# +string endpoint = ""; +string subscriptionKey = ""; +var credential = new FormRecognizerApiKeyCredential(subscriptionKey); +var client = new ReceiptClient(new Uri(endpoint), credential); + +using (FileStream stream = new FileStream(@"C:\path\to\receipt.jpg", FileMode.Open)) +{ + var extractReceiptOperation = client.StartExtractReceipts(stream, FormContentType.Jpeg); + await extractReceiptOperation.WaitForCompletionAsync(); + if (extractReceiptOperation.HasValue) + { + IReadOnlyList result = extractReceiptOperation.Value; + } +} +``` + ## Contributing This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla]. diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index 01476b0d0249..40c283107d8a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -226,6 +226,18 @@ public virtual async Task>> StartExtractF #region Supervised + ///// ```csharp + ///// using (FileStream stream = File.Open(@"c:\path\to\form.pdf")) + ///// { + ///// var extractFormOperation = client.StartExtractLabeledForms(modelId, stream, FormContentType.Pdf); + ///// + ///// await extractFormOperation.WaitForCompletionAsync(TimeSpan.FromSeconds(1), default); + ///// if (extractFormOperation.HasValue) + ///// { + ///// IReadOnlyList<ExtractedLabeledForm> forms = extractFormOperation.Value; + ///// } + ///// } + ///// ``` /// /// Extract form content from one or more forms, using a model trained with labels. diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs index 3dfb3a67651e..34dbccaac40e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedLabeledForm.cs @@ -55,6 +55,22 @@ internal ExtractedLabeledForm(DocumentResult_internal documentResult, IList public IReadOnlyList RawExtractedPages { get; } + /// + /// Return the field value text for a given label. + /// + /// + /// + public string GetFieldValue(string label) + { + var field = Fields.Where(f => f.Label == label).FirstOrDefault(); + if (field == default) + { + throw new FieldNotFoundException($"Field '{label}' not found on form."); + } + + return field.Value; + } + private static IReadOnlyList ConvertFields(IDictionary fields, IList readResults) { List list = new List(); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs index 9e7a97b3e3d6..8a8bbecd60eb 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedPage.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Azure.AI.FormRecognizer.Models; +using System.Linq; namespace Azure.AI.FormRecognizer.Custom { @@ -47,6 +48,22 @@ internal ExtractedPage(PageResult_internal pageResult, ReadResult_internal readR /// public RawExtractedPage RawExtractedPage { get; } + /// + /// Return the field value text for a given fieldName. + /// + /// + /// + public string GetFieldValue(string fieldName) + { + var field = Fields.Where(f => f.Name == fieldName).FirstOrDefault(); + if (field == default) + { + throw new FieldNotFoundException($"Field '{fieldName}' not found on form."); + } + + return field.Value; + } + private static IReadOnlyList ConvertFields(ICollection keyValuePairs, ReadResult_internal readResult) { List fields = new List(); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldNotFoundException.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldNotFoundException.cs new file mode 100644 index 000000000000..ac91ebe555ca --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldNotFoundException.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.AI.FormRecognizer.Models +{ +#pragma warning disable CA1064 // Exceptions should be public + internal class FieldNotFoundException : Exception +#pragma warning restore CA1064 // Exceptions should be public + { + public FieldNotFoundException(string message) : base(message) + { + } + } +} From 46e08edfe271df9dad30f315333ff9217532fa40 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Wed, 18 Mar 2020 15:18:22 -0700 Subject: [PATCH 27/32] updates from ux study --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 2 ++ .../{FormContentType.cs => ContentType.cs} | 2 +- .../src/CustomFormClient.cs | 21 +++--------- .../src/CustomModelInfo.cs | 4 +-- .../src/ExtractLabeledFormOperation.cs | 2 +- .../src/ExtractLayoutOperation.cs | 2 +- .../src/ExtractPagesOperation.cs | 2 +- .../src/ExtractReceiptOperation.cs | 2 +- .../src/FormLayoutClient.cs | 4 +-- .../Models/ContentType.Serialization.cs | 32 +++++++++++++++++++ .../Models/FormContentType.Serialization.cs | 32 ------------------- .../ModelInfo_internal.Serialization.cs | 2 +- .../Generated/Models/ModelInfo_internal.cs | 2 +- .../Models/ModelStatus.Serialization.cs | 30 +++++++++++++++++ .../TrainingDocumentInfo.Serialization.cs | 2 +- .../Generated/Models/TrainingDocumentInfo.cs | 2 +- .../Models/TrainingOutcome.Serialization.cs | 30 ----------------- .../Models/TrainingStatus.Serialization.cs | 12 +++---- .../src/Generated/Operations/ServiceClient.cs | 12 +++---- .../Generated/Operations/ServiceRestClient.cs | 18 +++++------ .../{TrainingOutcome.cs => ModelStatus.cs} | 16 +++++++--- .../src/ReceiptClient.cs | 4 +-- .../src/ServiceClient.cs | 10 +++--- .../src/ServiceRestClient.cs | 16 +++++----- .../src/TrainingOperation.cs | 4 +-- .../src/TrainingStatus.cs | 14 +++----- .../src/TrainingWithLabelsOperation.cs | 4 +-- 27 files changed, 136 insertions(+), 147 deletions(-) rename sdk/formrecognizer/Azure.AI.FormRecognizer/src/{FormContentType.cs => ContentType.cs} (95%) create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs create mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs delete mode 100644 sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs rename sdk/formrecognizer/Azure.AI.FormRecognizer/src/{TrainingOutcome.cs => ModelStatus.cs} (69%) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 6a7390c9c5d4..03b848c9b641 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -117,6 +117,7 @@ internal ExtractedLabeledForm() { } public System.Collections.Generic.IReadOnlyList RawExtractedPages { get { throw null; } } public int StartPageNumber { get { throw null; } } public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + public string GetFieldValue(string label) { throw null; } } public partial class ExtractedLabeledTable : Azure.AI.FormRecognizer.Models.ExtractedTable { @@ -131,6 +132,7 @@ internal ExtractedPage() { } public int PageNumber { get { throw null; } } public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } public System.Collections.Generic.IReadOnlyList Tables { get { throw null; } } + public string GetFieldValue(string fieldName) { throw null; } } public partial class FieldPredictionAccuracy { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs similarity index 95% rename from sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs rename to sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs index 77dbbf60a05d..61f6bef813e0 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormContentType.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs @@ -9,7 +9,7 @@ namespace Azure.AI.FormRecognizer.Models /// Form content type for local files. /// [CodeGenSchema("ContentType")] - public enum FormContentType + public enum ContentType { /// application/pdf [CodeGenSchemaMember("ApplicationPdf")] diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs index 40c283107d8a..b51f677b9835 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomFormClient.cs @@ -164,7 +164,7 @@ public virtual async Task> StartTrainingWithLabels /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedPage>>.Value upon successful /// completion will contain extracted pages from the input document. - public virtual Operation> StartExtractFormPages(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractFormPages(string modelId, Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -198,7 +198,7 @@ public virtual Operation> StartExtractFormPages(str /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedPage>>.Value upon successful /// completion will contain extracted pages from the input document. - public virtual async Task>> StartExtractFormPagesAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractFormPagesAsync(string modelId, Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -226,19 +226,6 @@ public virtual async Task>> StartExtractF #region Supervised - ///// ```csharp - ///// using (FileStream stream = File.Open(@"c:\path\to\form.pdf")) - ///// { - ///// var extractFormOperation = client.StartExtractLabeledForms(modelId, stream, FormContentType.Pdf); - ///// - ///// await extractFormOperation.WaitForCompletionAsync(TimeSpan.FromSeconds(1), default); - ///// if (extractFormOperation.HasValue) - ///// { - ///// IReadOnlyList<ExtractedLabeledForm> forms = extractFormOperation.Value; - ///// } - ///// } - ///// ``` - /// /// Extract form content from one or more forms, using a model trained with labels. /// @@ -249,7 +236,7 @@ public virtual async Task>> StartExtractF /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedPage>>.Value upon successful /// completion will contain extracted forms from the input document. - public virtual Operation> StartExtractLabeledForms(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLabeledForms(string modelId, Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -283,7 +270,7 @@ public virtual Operation> StartExtractLabele /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedPage>>.Value upon successful /// completion will contain extracted forms from the input document. - public virtual async Task>> StartExtractLabeledFormsAsync(string modelId, Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLabeledFormsAsync(string modelId, Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs index 5ac2ebc3b31a..3b38f5f4eb04 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelInfo.cs @@ -15,7 +15,7 @@ internal CustomModelInfo(ModelInfo_internal modelInfo) ModelId = modelInfo.ModelId.ToString(); CreatedOn = modelInfo.CreatedDateTime; LastUpdatedOn = modelInfo.LastUpdatedDateTime; - TrainingStatus = modelInfo.Status; + Status = modelInfo.Status; } /// @@ -24,7 +24,7 @@ internal CustomModelInfo(ModelInfo_internal modelInfo) /// /// - public TrainingStatus TrainingStatus { get; } + public ModelStatus Status { get; } /// /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs index 5e503d040ffd..c5b056f1e66b 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs @@ -65,7 +65,7 @@ public override Response UpdateStatus(CancellationToken cancellationToken = defa public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); - private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) { if (!_hasCompleted) { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLayoutOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLayoutOperation.cs index d13b8b206377..ba38ea02655b 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLayoutOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLayoutOperation.cs @@ -56,7 +56,7 @@ public override Response UpdateStatus(CancellationToken cancellationToken = defa public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); - private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) { if (!_hasCompleted) { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs index 52a19ec97386..e679efb357e0 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractPagesOperation.cs @@ -65,7 +65,7 @@ public override Response UpdateStatus(CancellationToken cancellationToken = defa public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); - private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) { if (!_hasCompleted) { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs index 944930e87fdd..f90cc9efc3de 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs @@ -55,7 +55,7 @@ public override Response UpdateStatus(CancellationToken cancellationToken = defa public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); - private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) { if (!_hasCompleted) { diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs index 144e3e026b34..af9aa45354f8 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs @@ -60,7 +60,7 @@ public FormLayoutClient(Uri endpoint, FormRecognizerApiKeyCredential credential, /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain layout elements extracted from the form. - public virtual Operation> StartExtractLayouts(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLayouts(Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -77,7 +77,7 @@ public virtual Operation> StartExtractLayouts /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain layout elements extracted from the form. - public virtual async Task>> StartExtractLayoutsAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLayoutsAsync(Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs new file mode 100644 index 000000000000..4845ce94ddf8 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ContentType.Serialization.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.AI.FormRecognizer.Models +{ + internal static class ContentTypeExtensions + { + public static string ToSerialString(this ContentType value) => value switch + { + ContentType.Pdf => "application/pdf", + ContentType.Jpeg => "image/jpeg", + ContentType.Png => "image/png", + ContentType.Tiff => "image/tiff", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ContentType value.") + }; + + public static ContentType ToContentType(this string value) + { + if (string.Equals(value, "application/pdf", StringComparison.InvariantCultureIgnoreCase)) return ContentType.Pdf; + if (string.Equals(value, "image/jpeg", StringComparison.InvariantCultureIgnoreCase)) return ContentType.Jpeg; + if (string.Equals(value, "image/png", StringComparison.InvariantCultureIgnoreCase)) return ContentType.Png; + if (string.Equals(value, "image/tiff", StringComparison.InvariantCultureIgnoreCase)) return ContentType.Tiff; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ContentType value."); + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs deleted file mode 100644 index 451041f06702..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormContentType.Serialization.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.AI.FormRecognizer.Models -{ - internal static class FormContentTypeExtensions - { - public static string ToSerialString(this FormContentType value) => value switch - { - FormContentType.Pdf => "application/pdf", - FormContentType.Jpeg => "image/jpeg", - FormContentType.Png => "image/png", - FormContentType.Tiff => "image/tiff", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value.") - }; - - public static FormContentType ToFormContentType(this string value) - { - if (string.Equals(value, "application/pdf", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Pdf; - if (string.Equals(value, "image/jpeg", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Jpeg; - if (string.Equals(value, "image/png", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Png; - if (string.Equals(value, "image/tiff", StringComparison.InvariantCultureIgnoreCase)) return FormContentType.Tiff; - throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown FormContentType value."); - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs index 229026260137..02636318bfcc 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.Serialization.cs @@ -37,7 +37,7 @@ internal static ModelInfo_internal DeserializeModelInfo_internal(JsonElement ele } if (property.NameEquals("status")) { - result.Status = property.Value.GetString().ToTrainingStatus(); + result.Status = property.Value.GetString().ToModelStatus(); continue; } if (property.NameEquals("createdDateTime")) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs index 1eb691e2ce9a..4245af9bca3f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelInfo_internal.cs @@ -15,7 +15,7 @@ internal partial class ModelInfo_internal /// Model identifier. public Guid ModelId { get; set; } /// Status of the model. - public TrainingStatus Status { get; set; } + public ModelStatus Status { get; set; } /// Date and time (UTC) when the model was created. public DateTimeOffset CreatedDateTime { get; set; } /// Date and time (UTC) when the status was last updated. diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs new file mode 100644 index 000000000000..c8eff7f04e18 --- /dev/null +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/ModelStatus.Serialization.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.AI.FormRecognizer.Custom +{ + internal static class ModelStatusExtensions + { + public static string ToSerialString(this ModelStatus value) => value switch + { + ModelStatus.Training => "creating", + ModelStatus.Ready => "ready", + ModelStatus.Invalid => "invalid", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ModelStatus value.") + }; + + public static ModelStatus ToModelStatus(this string value) + { + if (string.Equals(value, "creating", StringComparison.InvariantCultureIgnoreCase)) return ModelStatus.Training; + if (string.Equals(value, "ready", StringComparison.InvariantCultureIgnoreCase)) return ModelStatus.Ready; + if (string.Equals(value, "invalid", StringComparison.InvariantCultureIgnoreCase)) return ModelStatus.Invalid; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ModelStatus value."); + } + } +} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs index 03cf4f25cb38..99744521164f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.Serialization.cs @@ -56,7 +56,7 @@ internal static TrainingDocumentInfo DeserializeTrainingDocumentInfo(JsonElement } if (property.NameEquals("status")) { - result.Status = property.Value.GetString().ToTrainingOutcome(); + result.Status = property.Value.GetString().ToTrainingStatus(); continue; } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs index 56ae97aa96fd..4f590e258b64 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs @@ -18,6 +18,6 @@ public partial class TrainingDocumentInfo /// List of errors. public IList Errors { get; set; } = new List(); /// Status of the training operation. - public TrainingOutcome Status { get; set; } + public TrainingStatus Status { get; set; } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs deleted file mode 100644 index 2dea697242bf..000000000000 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingOutcome.Serialization.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.AI.FormRecognizer.Custom -{ - internal static class TrainingOutcomeExtensions - { - public static string ToSerialString(this TrainingOutcome value) => value switch - { - TrainingOutcome.Succeeded => "succeeded", - TrainingOutcome.PartiallySucceeded => "partiallySucceeded", - TrainingOutcome.Failed => "failed", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingOutcome value.") - }; - - public static TrainingOutcome ToTrainingOutcome(this string value) - { - if (string.Equals(value, "succeeded", StringComparison.InvariantCultureIgnoreCase)) return TrainingOutcome.Succeeded; - if (string.Equals(value, "partiallySucceeded", StringComparison.InvariantCultureIgnoreCase)) return TrainingOutcome.PartiallySucceeded; - if (string.Equals(value, "failed", StringComparison.InvariantCultureIgnoreCase)) return TrainingOutcome.Failed; - throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingOutcome value."); - } - } -} diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs index 4b2561222f09..f6434033b9df 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingStatus.Serialization.cs @@ -13,17 +13,17 @@ internal static class TrainingStatusExtensions { public static string ToSerialString(this TrainingStatus value) => value switch { - TrainingStatus.Training => "creating", - TrainingStatus.Ready => "ready", - TrainingStatus.Invalid => "invalid", + TrainingStatus.Succeeded => "succeeded", + TrainingStatus.PartiallySucceeded => "partiallySucceeded", + TrainingStatus.Failed => "failed", _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingStatus value.") }; public static TrainingStatus ToTrainingStatus(this string value) { - if (string.Equals(value, "creating", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Training; - if (string.Equals(value, "ready", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Ready; - if (string.Equals(value, "invalid", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Invalid; + if (string.Equals(value, "succeeded", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Succeeded; + if (string.Equals(value, "partiallySucceeded", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.PartiallySucceeded; + if (string.Equals(value, "failed", StringComparison.InvariantCultureIgnoreCase)) return TrainingStatus.Failed; throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TrainingStatus value."); } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs index 35473f54dcc7..60a2816efa92 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceClient.cs @@ -83,7 +83,7 @@ public virtual Response DeleteCustomModel(Guid modelId, CancellationToken cancel /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual async Task AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual async Task AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return (await RestClient.AnalyzeWithCustomModelAsync(modelId, includeTextDetails, contentType, fileStream, cancellationToken).ConfigureAwait(false)).GetRawResponse(); } @@ -93,7 +93,7 @@ public virtual async Task AnalyzeWithCustomModelAsync(Guid modelId, bo /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual Response AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual Response AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return RestClient.AnalyzeWithCustomModel(modelId, includeTextDetails, contentType, fileStream, cancellationToken).GetRawResponse(); } @@ -136,7 +136,7 @@ public virtual Response GetAnalyzeFormResult(Gu /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual async Task AnalyzeReceiptAsyncAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual async Task AnalyzeReceiptAsyncAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return (await RestClient.AnalyzeReceiptAsyncAsync(includeTextDetails, contentType, fileStream, cancellationToken).ConfigureAwait(false)).GetRawResponse(); } @@ -145,7 +145,7 @@ public virtual async Task AnalyzeReceiptAsyncAsync(bool? includeTextDe /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual Response AnalyzeReceiptAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual Response AnalyzeReceiptAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return RestClient.AnalyzeReceiptAsync(includeTextDetails, contentType, fileStream, cancellationToken).GetRawResponse(); } @@ -183,7 +183,7 @@ public virtual Response GetAnalyzeReceiptResult /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual async Task AnalyzeLayoutAsyncAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual async Task AnalyzeLayoutAsyncAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return (await RestClient.AnalyzeLayoutAsyncAsync(contentType, fileStream, cancellationToken).ConfigureAwait(false)).GetRawResponse(); } @@ -191,7 +191,7 @@ public virtual async Task AnalyzeLayoutAsyncAsync(FormContentType? con /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public virtual Response AnalyzeLayoutAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public virtual Response AnalyzeLayoutAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { return RestClient.AnalyzeLayoutAsync(contentType, fileStream, cancellationToken).GetRawResponse(); } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs index 6bfe717625fa..d91b0a5fbb1e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Operations/ServiceRestClient.cs @@ -327,7 +327,7 @@ public Response DeleteCustomModel(Guid modelId, CancellationToken cancellationTo throw; } } - internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream) + internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -356,7 +356,7 @@ internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? inc /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public async ValueTask> AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeWithCustomModel"); scope.Start(); @@ -385,7 +385,7 @@ public async ValueTask> Analy /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public ResponseWithHeaders AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeWithCustomModel"); scope.Start(); @@ -561,7 +561,7 @@ public Response GetAnalyzeFormResult(Guid model throw; } } - internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, FormContentType? contentType, Stream fileStream) + internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, ContentType? contentType, Stream fileStream) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -587,7 +587,7 @@ internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public async ValueTask> AnalyzeReceiptAsyncAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeReceiptAsyncAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeReceiptAsync"); scope.Start(); @@ -615,7 +615,7 @@ public async ValueTask> AnalyzeR /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public ResponseWithHeaders AnalyzeReceiptAsync(bool? includeTextDetails, FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeReceiptAsync(bool? includeTextDetails, ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeReceiptAsync"); scope.Start(); @@ -783,7 +783,7 @@ public Response GetAnalyzeReceiptResult(Guid re throw; } } - internal HttpMessage CreateAnalyzeLayoutAsyncRequest(FormContentType? contentType, Stream fileStream) + internal HttpMessage CreateAnalyzeLayoutAsyncRequest(ContentType? contentType, Stream fileStream) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -804,7 +804,7 @@ internal HttpMessage CreateAnalyzeLayoutAsyncRequest(FormContentType? contentTyp /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public async ValueTask> AnalyzeLayoutAsyncAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeLayoutAsyncAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeLayoutAsync"); scope.Start(); @@ -831,7 +831,7 @@ public async ValueTask> AnalyzeLa /// Upload file type. /// .json, .pdf, .jpg, .png or .tiff type file stream. /// The cancellation token to use. - public ResponseWithHeaders AnalyzeLayoutAsync(FormContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeLayoutAsync(ContentType? contentType, Stream fileStream, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("ServiceClient.AnalyzeLayoutAsync"); scope.Start(); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelStatus.cs similarity index 69% rename from sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs rename to sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelStatus.cs index 1efc08dae7eb..9a7fdc3b22d0 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOutcome.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ModelStatus.cs @@ -1,27 +1,33 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; using Azure.Core; namespace Azure.AI.FormRecognizer.Custom { + /// /// - [CodeGenSchema("TrainStatus")] + [CodeGenSchema("ModelStatus")] #pragma warning disable CA1717 // Only FlagsAttribute enums should have plural names - public enum TrainingOutcome + public enum ModelStatus #pragma warning restore CA1717 // Only FlagsAttribute enums should have plural names { /// /// - Succeeded, + [CodeGenSchemaMember("creating")] + Training, /// /// - PartiallySucceeded, + Ready, /// /// - Failed, + Invalid } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs index 0e4be6fd0613..a7d5017c7c43 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ReceiptClient.cs @@ -59,7 +59,7 @@ public ReceiptClient(Uri endpoint, FormRecognizerApiKeyCredential credential, Fo /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain the extracted receipt. - public virtual Operation> StartExtractReceipts(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractReceipts(Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -92,7 +92,7 @@ public virtual Operation> StartExtractReceipts(U /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain the extracted receipt. - public virtual async Task>> StartExtractReceiptsAsync(Stream stream, FormContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractReceiptsAsync(Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceClient.cs index 7ba35c46e344..59c9f00cfc44 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceClient.cs @@ -17,7 +17,7 @@ internal partial class ServiceClient { #region Custom - internal ResponseWithHeaders AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, Stream stream, FormContentType contentType, CancellationToken cancellationToken = default) + internal ResponseWithHeaders AnalyzeWithCustomModel(Guid modelId, bool? includeTextDetails, Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("AllOperations.AnalyzeWithCustomModel"); scope.Start(); @@ -42,7 +42,7 @@ internal ResponseWithHeaders AnalyzeWithCustomMod } } - internal async ValueTask> AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, Stream stream, FormContentType contentType, CancellationToken cancellationToken = default) + internal async ValueTask> AnalyzeWithCustomModelAsync(Guid modelId, bool? includeTextDetails, Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("AllOperations.AnalyzeWithCustomModel"); scope.Start(); @@ -107,7 +107,7 @@ async Task> NextPageFunc(string nextLink, int? pageSizeHin #region Receipt - public ResponseWithHeaders AnalyzeReceiptAsync(bool? includeTextDetails, Stream stream, FormContentType contentType, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeReceiptAsync(bool? includeTextDetails, Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("AllOperations.AnalyzeReceiptAsync"); @@ -138,7 +138,7 @@ public ResponseWithHeaders AnalyzeReceiptAsync(bool? // TODO: Is it ok that includeTextDetails is missing here? Or is it an issue with the Swagger? // This is missing from the swagger -- following up with service team. - public async ValueTask> AnalyzeLayoutAsyncAsync(Stream stream, FormContentType contentType, CancellationToken cancellationToken = default) + public async ValueTask> AnalyzeLayoutAsyncAsync(Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("AllOperations.AnalyzeLayoutAsync"); scope.Start(); @@ -162,7 +162,7 @@ public async ValueTask> AnalyzeLa } } - public ResponseWithHeaders AnalyzeLayoutAsync(Stream stream, FormContentType contentType, CancellationToken cancellationToken = default) + public ResponseWithHeaders AnalyzeLayoutAsync(Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { using var scope = clientDiagnostics.CreateScope("AllOperations.AnalyzeLayoutAsync"); scope.Start(); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceRestClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceRestClient.cs index 09f2fcfd3198..88efddd43063 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceRestClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ServiceRestClient.cs @@ -12,19 +12,19 @@ namespace Azure.AI.FormRecognizer { internal partial class ServiceRestClient { - internal static string GetContentTypeString(FormContentType contentType) + internal static string GetContentTypeString(ContentType contentType) { return contentType switch { - FormContentType.Pdf => "application/pdf", - FormContentType.Png => "image/png", - FormContentType.Jpeg => "image/jpeg", - FormContentType.Tiff => "image/tiff", + ContentType.Pdf => "application/pdf", + ContentType.Png => "image/png", + ContentType.Jpeg => "image/jpeg", + ContentType.Tiff => "image/tiff", _ => throw new NotSupportedException($"The content type {contentType} is not supported."), }; } - internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, Stream stream, FormContentType contentType) + internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, Stream stream, ContentType contentType) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -48,7 +48,7 @@ internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? inc return message; } - internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, Stream stream, FormContentType contentType) + internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, Stream stream, ContentType contentType) { var message = pipeline.CreateMessage(); var request = message.Request; @@ -73,7 +73,7 @@ internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, // TODO: Is it ok that includeTextDetails is missing here? Or is it an issue with the Swagger? // This is missing from the swagger -- following up with service team. - internal HttpMessage CreateAnalyzeLayoutAsyncRequest(Stream stream, FormContentType contentType) + internal HttpMessage CreateAnalyzeLayoutAsyncRequest(Stream stream, ContentType contentType) { var message = pipeline.CreateMessage(); var request = message.Request; diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs index 71cb3ae68501..909b23276026 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingOperation.cs @@ -79,7 +79,7 @@ public override Response UpdateStatus(CancellationToken cancellationToken = defa public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); - private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) { if (!_hasCompleted) { @@ -90,7 +90,7 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can // TODO: Handle correctly according to returned status code // https://github.com/Azure/azure-sdk-for-net/issues/10386 - if (update.Value.ModelInfo.Status != TrainingStatus.Training) + if (update.Value.ModelInfo.Status != ModelStatus.Training) { _hasCompleted = true; _value = new CustomModel(update.Value); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs index 65c55f9ba83b..6edd1ccd2583 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingStatus.cs @@ -1,33 +1,27 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Text; using Azure.Core; namespace Azure.AI.FormRecognizer.Custom { - /// /// - [CodeGenSchema("ModelStatus")] + [CodeGenSchema("TrainStatus")] #pragma warning disable CA1717 // Only FlagsAttribute enums should have plural names public enum TrainingStatus #pragma warning restore CA1717 // Only FlagsAttribute enums should have plural names { /// /// - [CodeGenSchemaMember("creating")] - Training, + Succeeded, /// /// - Ready, + PartiallySucceeded, /// /// - Invalid + Failed, } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs index 2db2b6f1adf4..061f54a5fe8e 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingWithLabelsOperation.cs @@ -76,7 +76,7 @@ public override Response UpdateStatus(CancellationToken cancellationToken = defa public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); - private async Task UpdateStatusAsync(bool async, CancellationToken cancellationToken) + private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) { if (!_hasCompleted) { @@ -87,7 +87,7 @@ private async Task UpdateStatusAsync(bool async, CancellationToken can // TODO: Handle correctly according to returned status code // https://github.com/Azure/azure-sdk-for-net/issues/10386 - if (update.Value.ModelInfo.Status != TrainingStatus.Training) + if (update.Value.ModelInfo.Status != ModelStatus.Training) { _hasCompleted = true; _value = new CustomLabeledModel(update.Value); From 18317006cfc76d9d9e428cd921a01699e67cdd07 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Wed, 18 Mar 2020 15:25:34 -0700 Subject: [PATCH 28/32] api update --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 03b848c9b641..60a2deea5faf 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -5,9 +5,9 @@ public partial class FormLayoutClient protected FormLayoutClient() { } public FormLayoutClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential) { } public FormLayoutClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential, Azure.AI.FormRecognizer.FormRecognizerClientOptions options) { } - public virtual Azure.Operation> StartExtractLayouts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLayouts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation> StartExtractLayouts(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class FormRecognizerClientOptions : Azure.Core.ClientOptions @@ -24,9 +24,9 @@ public partial class ReceiptClient protected ReceiptClient() { } public ReceiptClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential) { } public ReceiptClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential, Azure.AI.FormRecognizer.FormRecognizerClientOptions options) { } - public virtual Azure.Operation> StartExtractReceipts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractReceipts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation> StartExtractReceipts(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractReceiptsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractReceiptsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> StartExtractReceiptsAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } @@ -43,13 +43,13 @@ public CustomFormClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.Form public virtual Azure.AsyncPageable GetModelInfosAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSubscriptionProperties(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSubscriptionPropertiesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractFormPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractFormPages(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation> StartExtractFormPages(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> StartExtractFormPagesAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation> StartExtractLabeledForms(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.FormContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> StartExtractLabeledFormsAsync(string modelId, System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Operation StartTraining(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> StartTrainingAsync(string source, Azure.AI.FormRecognizer.Custom.TrainingFileFilter filter = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -79,7 +79,7 @@ internal CustomModelInfo() { } public System.DateTimeOffset? CreatedOn { get { throw null; } } public System.DateTimeOffset? LastUpdatedOn { get { throw null; } } public string ModelId { get { throw null; } } - public Azure.AI.FormRecognizer.Custom.TrainingStatus TrainingStatus { get { throw null; } } + public Azure.AI.FormRecognizer.Custom.ModelStatus Status { get { throw null; } } } public partial class CustomModelLearnedForm { @@ -140,6 +140,12 @@ public FieldPredictionAccuracy() { } public float Accuracy { get { throw null; } set { } } public string Label { get { throw null; } } } + public enum ModelStatus + { + Training = 0, + Ready = 1, + Invalid = 2, + } public partial class SubscriptionProperties { internal SubscriptionProperties() { } @@ -153,7 +159,7 @@ public TrainingDocumentInfo() { } public string DocumentName { get { throw null; } set { } } public System.Collections.Generic.IList Errors { get { throw null; } set { } } public int PageCount { get { throw null; } set { } } - public Azure.AI.FormRecognizer.Custom.TrainingOutcome Status { get { throw null; } set { } } + public Azure.AI.FormRecognizer.Custom.TrainingStatus Status { get { throw null; } set { } } } public partial class TrainingFileFilter { @@ -167,18 +173,12 @@ internal TrainingInfo() { } public System.Collections.Generic.IReadOnlyList PerDocumentInfo { get { throw null; } } public System.Collections.Generic.IReadOnlyList TrainingErrors { get { throw null; } } } - public enum TrainingOutcome + public enum TrainingStatus { Succeeded = 0, PartiallySucceeded = 1, Failed = 2, } - public enum TrainingStatus - { - Training = 0, - Ready = 1, - Invalid = 2, - } } namespace Azure.AI.FormRecognizer.Models { @@ -187,6 +187,13 @@ public partial class BoundingBox internal BoundingBox() { } public System.Drawing.PointF[] Points { get { throw null; } } } + public enum ContentType + { + Pdf = 1, + Png = 2, + Jpeg = 3, + Tiff = 4, + } public partial class ExtractedLayoutPage { internal ExtractedLayoutPage() { } @@ -266,13 +273,6 @@ public enum FieldValueType Array = 6, Object = 7, } - public enum FormContentType - { - Pdf = 1, - Png = 2, - Jpeg = 3, - Tiff = 4, - } public partial class FormRecognizerApiKeyCredential { public FormRecognizerApiKeyCredential(string apiKey) { } From 2fbf2a55066a3c0c516c511a684c67497a2d0a8e Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Wed, 18 Mar 2020 15:29:48 -0700 Subject: [PATCH 29/32] learned form-> page --- .../api/Azure.AI.FormRecognizer.netstandard2.0.cs | 6 +++--- .../Azure.AI.FormRecognizer/src/CustomModel.cs | 10 +++++----- ...stomModelKnownForm.cs => CustomModelLearnedPage.cs} | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) rename sdk/formrecognizer/Azure.AI.FormRecognizer/src/{CustomModelKnownForm.cs => CustomModelLearnedPage.cs} (85%) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 60a2deea5faf..173326409310 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -68,7 +68,7 @@ internal CustomLabeledModel() { } public partial class CustomModel { internal CustomModel() { } - public System.Collections.Generic.IReadOnlyList LearnedForms { get { throw null; } } + public System.Collections.Generic.IReadOnlyList LearnedPages { get { throw null; } } public string ModelId { get { throw null; } } public Azure.AI.FormRecognizer.Custom.CustomModelInfo ModelInfo { get { throw null; } } public Azure.AI.FormRecognizer.Custom.TrainingInfo TrainingInfo { get { throw null; } } @@ -81,9 +81,9 @@ internal CustomModelInfo() { } public string ModelId { get { throw null; } } public Azure.AI.FormRecognizer.Custom.ModelStatus Status { get { throw null; } } } - public partial class CustomModelLearnedForm + public partial class CustomModelLearnedPage { - internal CustomModelLearnedForm() { } + internal CustomModelLearnedPage() { } public string FormTypeId { get { throw null; } } public System.Collections.Generic.IReadOnlyList LearnedFields { get { throw null; } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModel.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModel.cs index 332183d60110..b0e112be44a6 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModel.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModel.cs @@ -15,7 +15,7 @@ public class CustomModel internal CustomModel(Model_internal model) { ModelId = model.ModelInfo.ModelId.ToString(); - LearnedForms = ConvertLearnedForms(model.Keys); + LearnedPages = ConvertLearnedForms(model.Keys); ModelInfo = new CustomModelInfo(model.ModelInfo); TrainingInfo = new TrainingInfo(model.TrainResult); } @@ -28,7 +28,7 @@ internal CustomModel(Model_internal model) /// /// List of forms the model learned to recognize, including form fields found in each form. /// - public IReadOnlyList LearnedForms { get; internal set; } + public IReadOnlyList LearnedPages { get; internal set; } /// /// Information about the trained model, including model ID and training completion status. @@ -41,13 +41,13 @@ internal CustomModel(Model_internal model) public TrainingInfo TrainingInfo { get; internal set; } - private static IReadOnlyList ConvertLearnedForms(KeysResult_internal keys) + private static IReadOnlyList ConvertLearnedForms(KeysResult_internal keys) { - List forms = new List(); + List forms = new List(); foreach (var key in keys.Clusters) { - CustomModelLearnedForm form = new CustomModelLearnedForm() + CustomModelLearnedPage form = new CustomModelLearnedPage() { FormTypeId = key.Key, // TODO: Q3 diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelLearnedPage.cs similarity index 85% rename from sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs rename to sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelLearnedPage.cs index 1c9d2c6d92eb..12a99ee58cd8 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelKnownForm.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/CustomModelLearnedPage.cs @@ -7,9 +7,9 @@ namespace Azure.AI.FormRecognizer.Custom { /// /// - public class CustomModelLearnedForm + public class CustomModelLearnedPage { - internal CustomModelLearnedForm() + internal CustomModelLearnedPage() { } From 70429ddb351dcd0fe9d055886db24cdaea5fa60e Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 19 Mar 2020 11:26:12 -0700 Subject: [PATCH 30/32] api updates --- .../api/Azure.AI.FormRecognizer.netstandard2.0.cs | 4 ++-- .../Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs | 3 +++ .../Azure.AI.FormRecognizer/src/TrainingDocumentInfo.cs | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 173326409310..5647229a3427 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -136,7 +136,7 @@ internal ExtractedPage() { } } public partial class FieldPredictionAccuracy { - public FieldPredictionAccuracy() { } + internal FieldPredictionAccuracy() { } public float Accuracy { get { throw null; } set { } } public string Label { get { throw null; } } } @@ -155,7 +155,7 @@ internal SubscriptionProperties() { } } public partial class TrainingDocumentInfo { - public TrainingDocumentInfo() { } + internal TrainingDocumentInfo() { } public string DocumentName { get { throw null; } set { } } public System.Collections.Generic.IList Errors { get { throw null; } set { } } public int PageCount { get { throw null; } set { } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs index f7e2531204f4..a32f21f14a69 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs @@ -9,6 +9,9 @@ namespace Azure.AI.FormRecognizer.Custom [CodeGenSchema("FormFieldsReport")] public partial class FieldPredictionAccuracy { + internal FieldPredictionAccuracy() + { + } /// /// diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingDocumentInfo.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingDocumentInfo.cs index 872202a193ba..cad1dda5ca20 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingDocumentInfo.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/TrainingDocumentInfo.cs @@ -10,6 +10,10 @@ namespace Azure.AI.FormRecognizer.Custom [CodeGenSchema("TrainingDocumentInfo")] public partial class TrainingDocumentInfo { + internal TrainingDocumentInfo() + { + } + /// /// [CodeGenSchemaMember("pages")] From 2998efcd29361fecd210452ed7793da602c35838 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 19 Mar 2020 15:24:42 -0700 Subject: [PATCH 31/32] updates for rebase --- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 22 +++++++++---------- .../src/ContentType.cs | 8 +++---- .../src/ExtractedReceiptType.cs | 4 ++-- .../src/FieldPredictionAccuracy.cs | 4 ---- .../Generated/Models/FormRecognizerError.cs | 13 +++++++++++ .../Generated/Models/TrainingDocumentInfo.cs | 19 +++++++++++++--- 6 files changed, 46 insertions(+), 24 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index 5647229a3427..fd14b47a88c4 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -137,7 +137,7 @@ internal ExtractedPage() { } public partial class FieldPredictionAccuracy { internal FieldPredictionAccuracy() { } - public float Accuracy { get { throw null; } set { } } + public float Accuracy { get { throw null; } } public string Label { get { throw null; } } } public enum ModelStatus @@ -156,10 +156,10 @@ internal SubscriptionProperties() { } public partial class TrainingDocumentInfo { internal TrainingDocumentInfo() { } - public string DocumentName { get { throw null; } set { } } - public System.Collections.Generic.IList Errors { get { throw null; } set { } } + public string DocumentName { get { throw null; } } + public System.Collections.Generic.IList Errors { get { throw null; } } public int PageCount { get { throw null; } set { } } - public Azure.AI.FormRecognizer.Custom.TrainingStatus Status { get { throw null; } set { } } + public Azure.AI.FormRecognizer.Custom.TrainingStatus Status { get { throw null; } } } public partial class TrainingFileFilter { @@ -189,10 +189,10 @@ internal BoundingBox() { } } public enum ContentType { - Pdf = 1, - Png = 2, - Jpeg = 3, - Tiff = 4, + Pdf = 0, + Png = 1, + Jpeg = 2, + Tiff = 3, } public partial class ExtractedLayoutPage { @@ -237,8 +237,8 @@ internal ExtractedReceiptItem() { } } public enum ExtractedReceiptType { - Unrecognized = 1, - Itemized = 2, + Unrecognized = 0, + Itemized = 1, } public partial class ExtractedTable { @@ -280,7 +280,7 @@ public void UpdateCredential(string apiKey) { } } public partial class FormRecognizerError { - public FormRecognizerError() { } + internal FormRecognizerError() { } public string Code { get { throw null; } set { } } public string Message { get { throw null; } set { } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs index 61f6bef813e0..939fc566f77c 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ContentType.cs @@ -13,18 +13,18 @@ public enum ContentType { /// application/pdf [CodeGenSchemaMember("ApplicationPdf")] - Pdf = 1, + Pdf, /// image/png [CodeGenSchemaMember("ImagePng")] - Png = 2, + Png, /// image/jpeg [CodeGenSchemaMember("ImageJpeg")] - Jpeg = 3, + Jpeg, /// image/tiff [CodeGenSchemaMember("ImageTiff")] - Tiff = 4, + Tiff, } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceiptType.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceiptType.cs index 4955aebf6b3c..8d2a4dc60c43 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceiptType.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceiptType.cs @@ -9,10 +9,10 @@ public enum ExtractedReceiptType { /// /// - Unrecognized = 1, + Unrecognized = 0, /// /// - Itemized = 2, + Itemized = 1, } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs index a32f21f14a69..52c9a8844f27 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldPredictionAccuracy.cs @@ -9,10 +9,6 @@ namespace Azure.AI.FormRecognizer.Custom [CodeGenSchema("FormFieldsReport")] public partial class FieldPredictionAccuracy { - internal FieldPredictionAccuracy() - { - } - /// /// [CodeGenSchemaMember("FieldName")] diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs index 62bbb489a9da..5a5a29ea5b58 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/FormRecognizerError.cs @@ -10,5 +10,18 @@ namespace Azure.AI.FormRecognizer.Models /// The ErrorInformation. public partial class FormRecognizerError { + /// Initializes a new instance of FormRecognizerError. + internal FormRecognizerError() + { + } + + /// Initializes a new instance of FormRecognizerError. + /// . + /// . + internal FormRecognizerError(string code, string message) + { + Code = code; + Message = message; + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs index 4f590e258b64..8a2136048fde 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/Generated/Models/TrainingDocumentInfo.cs @@ -13,11 +13,24 @@ namespace Azure.AI.FormRecognizer.Custom /// Report for a custom model training document. public partial class TrainingDocumentInfo { + /// Initializes a new instance of TrainingDocumentInfo. + /// Training document name. + /// Total number of pages trained. + /// List of errors. + /// Status of the training operation. + internal TrainingDocumentInfo(string documentName, int pageCount, IList errors, TrainingStatus status) + { + DocumentName = documentName; + PageCount = pageCount; + Errors = errors; + Status = status; + } + /// Training document name. - public string DocumentName { get; set; } + public string DocumentName { get; internal set; } /// List of errors. - public IList Errors { get; set; } = new List(); + public IList Errors { get; internal set; } = new List(); /// Status of the training operation. - public TrainingStatus Status { get; set; } + public TrainingStatus Status { get; internal set; } } } From 6408aa19a12bd3f5ca0a39420988cd7ca184ea77 Mon Sep 17 00:00:00 2001 From: Anne Loomis Thompson Date: Thu, 19 Mar 2020 21:31:01 -0700 Subject: [PATCH 32/32] pr feedback --- .../Azure.AI.FormRecognizer/README.md | 2 +- .../Azure.AI.FormRecognizer.netstandard2.0.cs | 12 +++++------- .../src/ExtractReceiptOperation.cs | 2 +- .../src/ExtractedReceipt.cs | 18 ++++++++++++++---- .../src/FormLayoutClient.cs | 12 ++++-------- .../src/RawExtractedLine.cs | 5 ----- .../src/RawExtractedPage.cs | 6 ------ 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md index 1d7a601fa323..766d958e7952 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/README.md @@ -25,7 +25,7 @@ For other installation methods, please see the package information on [NuGet][nu --> ### Authenticate a Form Recognizer client -In order to interact with the Form Recognizer service, you'll need to select either a `ReceiptClient`, `FormLayoutClient`, or `CustomFormClient`, and create an instance of this class. In the following samples, we will use CustomFormClient as an example. You will need an **endpoint**, and either a **subscription key** or ``TokenCredential`` to instantiate a client object. For more information regarding authenticating with cognitive services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth]. +In order to interact with the Form Recognizer service, you'll need to select either a `ReceiptClient`, `FormLayoutClient`, or `CustomFormClient`, and create an instance of this class. In the following samples, we will use CustomFormClient as an example. You will need an **endpoint**, and either an **API key** or ``TokenCredential`` to instantiate a client object. For more information regarding authenticating with cognitive services, see [Authenticate requests to Azure Cognitive Services][cognitive_auth]. #### Get Subscription Key diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs index fd14b47a88c4..77cd2284d10a 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs @@ -5,10 +5,10 @@ public partial class FormLayoutClient protected FormLayoutClient() { } public FormLayoutClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential) { } public FormLayoutClient(System.Uri endpoint, Azure.AI.FormRecognizer.Models.FormRecognizerApiKeyCredential credential, Azure.AI.FormRecognizer.FormRecognizerClientOptions options) { } - public virtual Azure.Operation> StartExtractLayouts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Operation> StartExtractLayouts(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.Uri uri, bool includeRawPageExtractions = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLayouts(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation> StartExtractLayouts(System.Uri uri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.IO.Stream stream, Azure.AI.FormRecognizer.Models.ContentType contentType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> StartExtractLayoutsAsync(System.Uri uri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class FormRecognizerClientOptions : Azure.Core.ClientOptions { @@ -210,7 +210,7 @@ internal ExtractedReceipt() { } public string MerchantAddress { get { throw null; } } public string MerchantName { get { throw null; } } public string MerchantPhoneNumber { get { throw null; } } - public Azure.AI.FormRecognizer.Models.RawExtractedPage RawExtractedPage { get { throw null; } } + public System.Collections.Generic.IReadOnlyList RawExtractedPage { get { throw null; } } public Azure.AI.FormRecognizer.Models.ExtractedReceiptType ReceiptType { get { throw null; } } public int StartPageNumber { get { throw null; } } public float? Subtotal { get { throw null; } } @@ -298,7 +298,6 @@ internal RawExtractedItem() { } public partial class RawExtractedLine : Azure.AI.FormRecognizer.Models.RawExtractedItem { internal RawExtractedLine() { } - public string Language { get { throw null; } } public System.Collections.Generic.IReadOnlyList Words { get { throw null; } } public static implicit operator string (Azure.AI.FormRecognizer.Models.RawExtractedLine line) { throw null; } } @@ -307,7 +306,6 @@ public partial class RawExtractedPage internal RawExtractedPage() { } public float Angle { get { throw null; } set { } } public float Height { get { throw null; } set { } } - public string Language { get { throw null; } set { } } public System.Collections.Generic.ICollection Lines { get { throw null; } set { } } public int Page { get { throw null; } set { } } public Azure.AI.FormRecognizer.Models.LengthUnit Unit { get { throw null; } set { } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs index f90cc9efc3de..a6c57bc819b7 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractReceiptOperation.cs @@ -87,7 +87,7 @@ private static IReadOnlyList ConvertToExtractedReceipts(IList< List receipts = new List(); for (int i = 0; i < documentResults.Count; i++) { - receipts.Add(new ExtractedReceipt(documentResults[i], readResults[i])); + receipts.Add(new ExtractedReceipt(documentResults[i], readResults)); } return receipts; } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs index 3fcc9378bce4..e3c63a57bb26 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractedReceipt.cs @@ -13,16 +13,16 @@ namespace Azure.AI.FormRecognizer.Models /// public class ExtractedReceipt { - internal ExtractedReceipt(DocumentResult_internal documentResult, ReadResult_internal readResult) + internal ExtractedReceipt(DocumentResult_internal documentResult, IList readResults) { StartPageNumber = documentResult.PageRange.First(); EndPageNumber = documentResult.PageRange.Last(); SetReceiptValues(documentResult.Fields); - if (readResult != null) + if (readResults != null) { - RawExtractedPage = new RawExtractedPage(readResult); + RawExtractedPage = ConvertRawPages(StartPageNumber, EndPageNumber, readResults); } } /// @@ -88,7 +88,7 @@ internal ExtractedReceipt(DocumentResult_internal documentResult, ReadResult_int /// /// - public RawExtractedPage RawExtractedPage { get; } + public IReadOnlyList RawExtractedPage { get; } private void SetReceiptValues(IDictionary fields) { @@ -258,5 +258,15 @@ private static IReadOnlyList ConvertReceiptItems(IDictiona return items; } + + private static IReadOnlyList ConvertRawPages(int startPageNumber, int endPageNumber, IList readResults) + { + List rawPages = new List(); + for (int i = startPageNumber - 1; i < endPageNumber - 1; i++) + { + rawPages.Add(new RawExtractedPage(readResults[i])); + } + return rawPages; + } } } diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs index af9aa45354f8..dc8d6190a78d 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLayoutClient.cs @@ -56,11 +56,10 @@ public FormLayoutClient(Uri endpoint, FormRecognizerApiKeyCredential credential, /// /// The stream containing one or more forms to extract elements from. /// The content type of the input file. - /// Whether or not to include raw page extractions in addition to layout elements. /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain layout elements extracted from the form. - public virtual Operation> StartExtractLayouts(Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLayouts(Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -73,11 +72,10 @@ public virtual Operation> StartExtractLayouts /// /// The stream containing one or more forms to extract elements from. /// The content type of the input file. - /// Whether or not to include raw page extractions in addition to layout elements. /// A controlling the request lifetime. /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain layout elements extracted from the form. - public virtual async Task>> StartExtractLayoutsAsync(Stream stream, ContentType contentType, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLayoutsAsync(Stream stream, ContentType contentType, CancellationToken cancellationToken = default) { // TODO: automate content-type detection // https://github.com/Azure/azure-sdk-for-net/issues/10329 @@ -89,11 +87,10 @@ public virtual async Task>> StartEx /// Extracts layout elements from one or more passed-in forms. /// /// The absolute URI of the remote file to extract elements from. - /// Whether or not to include raw page extractions in addition to layout elements. /// /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain layout elements extracted from the form. - public virtual Operation> StartExtractLayouts(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual Operation> StartExtractLayouts(Uri uri, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = _operations.RestClient.AnalyzeLayoutAsync(sourcePath, cancellationToken); @@ -104,11 +101,10 @@ public virtual Operation> StartExtractLayouts /// Extracts layout elements from one or more passed-in forms. /// /// The absolute URI of the remote file to extract elements from. - /// Whether or not to include raw page extractions in addition to layout elements. /// /// A Operation<IReadOnlyList<ExtractedLayoutPage>> to wait on this long-running operation. Its Operation<IReadOnlyList<ExtractedLayoutPage>>.Value upon successful /// completion will contain layout elements extracted from the form. - public virtual async Task>> StartExtractLayoutsAsync(Uri uri, bool includeRawPageExtractions = false, CancellationToken cancellationToken = default) + public virtual async Task>> StartExtractLayoutsAsync(Uri uri, CancellationToken cancellationToken = default) { SourcePath_internal sourcePath = new SourcePath_internal() { Source = uri.ToString() }; ResponseWithHeaders response = await _operations.RestClient.AnalyzeLayoutAsyncAsync(sourcePath, cancellationToken).ConfigureAwait(false); diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedLine.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedLine.cs index 3507af170a34..7f3de05a3757 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedLine.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedLine.cs @@ -13,17 +13,12 @@ internal RawExtractedLine(TextLine_internal textLine) { Text = textLine.Text; BoundingBox = new BoundingBox(textLine.BoundingBox); - Language = textLine.Language.ToString(); Words = ConvertWords(textLine.Words); } - /// Language code. - //public Language_internal? Language { get; internal set; } - public string Language { get; internal set; } /// List of words in the text line. public IReadOnlyList Words { get; internal set; } - /// /// public static implicit operator string(RawExtractedLine line) => line.Text; diff --git a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedPage.cs b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedPage.cs index e18789b0885f..ad3768051e6f 100644 --- a/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedPage.cs +++ b/sdk/formrecognizer/Azure.AI.FormRecognizer/src/RawExtractedPage.cs @@ -16,7 +16,6 @@ internal RawExtractedPage(ReadResult_internal readResult) Width = readResult.Width; Height = readResult.Height; Unit = readResult.Unit; - Language = readResult.Language.ToString(); if (readResult.Lines != null) { @@ -35,11 +34,6 @@ internal RawExtractedPage(ReadResult_internal readResult) /// The unit used by the width, height and boundingBox properties. For images, the unit is "pixel". For PDF, the unit is "inch". public LengthUnit Unit { get; set; } - // TODO: Make language nullable? - // https://github.com/Azure/azure-sdk-for-net/issues/10361 - - /// Language code. - public string Language { get; set; } /// When includeTextDetails is set to true, a list of recognized text lines. The maximum number of lines returned is 300 per page. The lines are sorted top to bottom, left to right, although in certain cases proximity is treated with higher priority. As the sorting order depends on the detected text, it may change across images and OCR version updates. Thus, business logic should be built upon the actual line location instead of order. public ICollection Lines { get; set; }