Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Add invoices functionality #16522

Merged
merged 4 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### New Features
- Added support for pre-built business card recognition.
- Added support for pre-built invoices recognition.
- Added support for providing locale info when recognizing receipts and business cards. Supported locales include support EN-US, EN-AU, EN-CA, EN-GB, EN-IN.
- Added support to train and recognize custom forms with selection marks such as check boxes and radio buttons. This functionality is only available in train with labels scenarios.
- Added ability to create a composed model from the `FormTrainingClient` by calling method `StartCreateComposedModel`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public FormRecognizerClient(System.Uri endpoint, Azure.Core.TokenCredential cred
public virtual System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeCustomFormsOperation> StartRecognizeCustomFormsAsync(string modelId, System.IO.Stream form, Azure.AI.FormRecognizer.RecognizeCustomFormsOptions recognizeCustomFormsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AI.FormRecognizer.Models.RecognizeCustomFormsOperation StartRecognizeCustomFormsFromUri(string modelId, System.Uri formUri, Azure.AI.FormRecognizer.RecognizeCustomFormsOptions recognizeCustomFormsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeCustomFormsOperation> StartRecognizeCustomFormsFromUriAsync(string modelId, System.Uri formUri, Azure.AI.FormRecognizer.RecognizeCustomFormsOptions recognizeCustomFormsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AI.FormRecognizer.Models.RecognizeInvoicesOperation StartRecognizeInvoices(System.IO.Stream invoice, Azure.AI.FormRecognizer.RecognizeInvoicesOptions recognizeInvoicesOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeInvoicesOperation> StartRecognizeInvoicesAsync(System.IO.Stream invoice, Azure.AI.FormRecognizer.RecognizeInvoicesOptions recognizeInvoicesOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AI.FormRecognizer.Models.RecognizeInvoicesOperation StartRecognizeInvoicesFromUri(System.Uri invoiceUri, Azure.AI.FormRecognizer.RecognizeInvoicesOptions recognizeInvoicesOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeInvoicesOperation> StartRecognizeInvoicesFromUriAsync(System.Uri invoiceUri, Azure.AI.FormRecognizer.RecognizeInvoicesOptions recognizeInvoicesOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AI.FormRecognizer.Models.RecognizeReceiptsOperation StartRecognizeReceipts(System.IO.Stream receipt, Azure.AI.FormRecognizer.RecognizeReceiptsOptions recognizeReceiptsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeReceiptsOperation> StartRecognizeReceiptsAsync(System.IO.Stream receipt, Azure.AI.FormRecognizer.RecognizeReceiptsOptions recognizeReceiptsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AI.FormRecognizer.Models.RecognizeReceiptsOperation StartRecognizeReceiptsFromUri(System.Uri receiptUri, Azure.AI.FormRecognizer.RecognizeReceiptsOptions recognizeReceiptsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand All @@ -47,6 +51,7 @@ public static partial class OperationExtensions
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeBusinessCardsOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Models.FormPageCollection>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeContentOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeCustomFormsOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeInvoicesOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Models.RecognizeReceiptsOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Training.CustomFormModelInfo>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Training.CopyModelOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.Training.CustomFormModel>> WaitForCompletionAsync(this System.Threading.Tasks.Task<Azure.AI.FormRecognizer.Training.CreateComposedModelOperation> operation, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand All @@ -70,6 +75,13 @@ public RecognizeCustomFormsOptions() { }
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
public bool IncludeFieldElements { get { throw null; } set { } }
}
public partial class RecognizeInvoicesOptions
{
public RecognizeInvoicesOptions() { }
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
public bool IncludeFieldElements { get { throw null; } set { } }
public string Locale { get { throw null; } set { } }
}
public partial class RecognizeReceiptsOptions
{
public RecognizeReceiptsOptions() { }
Expand Down Expand Up @@ -316,6 +328,19 @@ public partial class RecognizedFormCollection : System.Collections.ObjectModel.R
{
internal RecognizedFormCollection() : base (default(System.Collections.Generic.IList<Azure.AI.FormRecognizer.Models.RecognizedForm>)) { }
}
public partial class RecognizeInvoicesOperation : Azure.Operation<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>
{
public RecognizeInvoicesOperation(string operationId, Azure.AI.FormRecognizer.FormRecognizerClient client) { }
public override bool HasCompleted { get { throw null; } }
public override bool HasValue { get { throw null; } }
public override string Id { get { throw null; } }
public override Azure.AI.FormRecognizer.Models.RecognizedFormCollection Value { get { throw null; } }
public override Azure.Response GetRawResponse() { throw null; }
public override Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public override System.Threading.Tasks.ValueTask<Azure.Response> UpdateStatusAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public override System.Threading.Tasks.ValueTask<Azure.Response<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>> WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public override System.Threading.Tasks.ValueTask<Azure.Response<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>> WaitForCompletionAsync(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class RecognizeReceiptsOperation : Azure.Operation<Azure.AI.FormRecognizer.Models.RecognizedFormCollection>
{
public RecognizeReceiptsOperation(string operationId, Azure.AI.FormRecognizer.FormRecognizerClient client) { }
Expand Down
138 changes: 138 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,144 @@ public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCardsFromUr

#endregion

#region Invoices

/// <summary>
/// Recognizes values from one or more invoices.
/// <para>See <a href="https://aka.ms/formrecognizer/invoicefields"/> for a list of available fields on an invoice.</para>
/// </summary>
/// <param name="invoice">The stream containing the one or more invoices to recognize values from.</param>
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesAsync(Stream invoice, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(invoice, nameof(invoice));

recognizeInvoicesOptions ??= new RecognizeInvoicesOptions();

using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeInvoices)}");
scope.Start();

try
{
FormContentType contentType = recognizeInvoicesOptions.ContentType ?? DetectContentType(invoice, nameof(invoice));

Response response = await ServiceClient.AnalyzeInvoiceAsyncAsync(contentType, invoice, recognizeInvoicesOptions.IncludeFieldElements, recognizeInvoicesOptions.Locale, cancellationToken).ConfigureAwait(false);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeInvoicesOperation(ServiceClient, Diagnostics, location);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}

/// <summary>
/// Recognizes values from one or more invoices.
/// <para>See <a href="https://aka.ms/formrecognizer/invoicefields"/> for a list of available fields on an invoice.</para>
/// </summary>
/// <param name="invoice">The stream containing the one or more invoices to recognize values from.</param>
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual RecognizeInvoicesOperation StartRecognizeInvoices(Stream invoice, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(invoice, nameof(invoice));

recognizeInvoicesOptions ??= new RecognizeInvoicesOptions();

using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeInvoices)}");
scope.Start();

try
{
FormContentType contentType = recognizeInvoicesOptions.ContentType ?? DetectContentType(invoice, nameof(invoice));

Response response = ServiceClient.AnalyzeInvoiceAsync(contentType, invoice, recognizeInvoicesOptions.IncludeFieldElements, recognizeInvoicesOptions.Locale, cancellationToken);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeInvoicesOperation(ServiceClient, Diagnostics, location);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}

/// <summary>
/// Recognizes values from one or more invoices.
/// <para>See <a href="https://aka.ms/formrecognizer/invoicefields"/> for a list of available fields on an invoice.</para>
/// </summary>
/// <param name="invoiceUri">The absolute URI of the remote file to recognize values from.</param>
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesFromUriAsync(Uri invoiceUri, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(invoiceUri, nameof(invoiceUri));

recognizeInvoicesOptions ??= new RecognizeInvoicesOptions();

using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeInvoicesFromUri)}");
scope.Start();

try
{
SourcePath sourcePath = new SourcePath() { Source = invoiceUri.AbsoluteUri };
Response response = await ServiceClient.AnalyzeInvoiceAsyncAsync(includeTextDetails: recognizeInvoicesOptions.IncludeFieldElements, locale: recognizeInvoicesOptions.Locale, fileStream: sourcePath, cancellationToken).ConfigureAwait(false);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeInvoicesOperation(ServiceClient, Diagnostics, location);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}

/// <summary>
/// Recognizes values from one or more invoices.
/// <para>See <a href="https://aka.ms/formrecognizer/invoicefields"/> for a list of available fields on an invoice.</para>
/// </summary>
/// <param name="invoiceUri">The absolute URI of the remote file to recognize values from.</param>
/// <param name="recognizeInvoicesOptions">A set of options available for configuring the recognize request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>A <see cref="RecognizeInvoicesOperation"/> to wait on this long-running operation. Its <see cref="RecognizeInvoicesOperation.Value"/> upon successful
/// completion will contain the extracted invoices.</returns>
public virtual RecognizeInvoicesOperation StartRecognizeInvoicesFromUri(Uri invoiceUri, RecognizeInvoicesOptions recognizeInvoicesOptions = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(invoiceUri, nameof(invoiceUri));

recognizeInvoicesOptions ??= new RecognizeInvoicesOptions();

using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeInvoicesFromUri)}");
scope.Start();

try
{
SourcePath sourcePath = new SourcePath() { Source = invoiceUri.AbsoluteUri };
Response response = ServiceClient.AnalyzeInvoiceAsync(includeTextDetails: recognizeInvoicesOptions.IncludeFieldElements, locale: recognizeInvoicesOptions.Locale, fileStream: sourcePath, cancellationToken);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeInvoicesOperation(ServiceClient, Diagnostics, location);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
#endregion


#region Custom Forms

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ public static async Task<Response<RecognizedFormCollection>> WaitForCompletionAs
return await o.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Periodically calls the server until the long-running operation completes.
/// </summary>
/// <param name="operation">The instance that this method was invoked on.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>A <see cref="Response{T}"/> representing the result of the operation. It can be cast to a <see cref="IReadOnlyList{T}"/>
/// containing the recognized business cards.</returns>
public static async Task<Response<RecognizedFormCollection>> WaitForCompletionAsync(this Task<RecognizeInvoicesOperation> operation, CancellationToken cancellationToken = default)
{
var o = await operation.ConfigureAwait(false);
return await o.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Periodically calls the server until the long-running operation completes.
/// </summary>
Expand Down
Loading