Skip to content

Commit d18a797

Browse files
authored
[FormRecognizer] Implemented page range selection feature for prebuilt and custom models (Azure#19906)
1 parent dc87111 commit d18a797

File tree

40 files changed

+52627
-16
lines changed

40 files changed

+52627
-16
lines changed

sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66
- Expanded the set of document languages that can be provided to the `StartRecognizeContent` API.
7+
- Added property `Pages` to `RecognizeBusinessCardsOptions`, `RecognizeCustomFormsOptions`, `RecognizeInvoicesOptions`, and `RecognizeReceiptsOptions` to specify the page numbers to recognize.
78

89
### Breaking changes
910
- The client defaults to the latest supported service version, which currently is `2.1-preview.3`.

sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public RecognizeBusinessCardsOptions() { }
174174
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
175175
public bool IncludeFieldElements { get { throw null; } set { } }
176176
public Azure.AI.FormRecognizer.FormRecognizerLocale? Locale { get { throw null; } set { } }
177+
public System.Collections.Generic.IList<string> Pages { get { throw null; } }
177178
}
178179
public partial class RecognizeContentOptions
179180
{
@@ -187,20 +188,23 @@ public partial class RecognizeCustomFormsOptions
187188
public RecognizeCustomFormsOptions() { }
188189
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
189190
public bool IncludeFieldElements { get { throw null; } set { } }
191+
public System.Collections.Generic.IList<string> Pages { get { throw null; } }
190192
}
191193
public partial class RecognizeInvoicesOptions
192194
{
193195
public RecognizeInvoicesOptions() { }
194196
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
195197
public bool IncludeFieldElements { get { throw null; } set { } }
196198
public Azure.AI.FormRecognizer.FormRecognizerLocale? Locale { get { throw null; } set { } }
199+
public System.Collections.Generic.IList<string> Pages { get { throw null; } }
197200
}
198201
public partial class RecognizeReceiptsOptions
199202
{
200203
public RecognizeReceiptsOptions() { }
201204
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
202205
public bool IncludeFieldElements { get { throw null; } set { } }
203206
public Azure.AI.FormRecognizer.FormRecognizerLocale? Locale { get { throw null; } set { } }
207+
public System.Collections.Generic.IList<string> Pages { get { throw null; } }
204208
}
205209
}
206210
namespace Azure.AI.FormRecognizer.Models

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public virtual async Task<RecognizeReceiptsOperation> StartRecognizeReceiptsAsyn
303303
formContentType,
304304
recognizeReceiptsOptions.IncludeFieldElements,
305305
recognizeReceiptsOptions.Locale,
306-
null, // TODO: pass pages.
306+
recognizeReceiptsOptions.Pages.Count == 0 ? null : recognizeReceiptsOptions.Pages,
307307
receipt,
308308
cancellationToken).ConfigureAwait(false);
309309
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -344,7 +344,7 @@ public virtual RecognizeReceiptsOperation StartRecognizeReceipts(Stream receipt,
344344
formContentType,
345345
recognizeReceiptsOptions.IncludeFieldElements,
346346
recognizeReceiptsOptions.Locale,
347-
null, // TODO: pass pages.
347+
recognizeReceiptsOptions.Pages.Count == 0 ? null : recognizeReceiptsOptions.Pages,
348348
receipt,
349349
cancellationToken);
350350
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -383,7 +383,7 @@ public virtual async Task<RecognizeReceiptsOperation> StartRecognizeReceiptsFrom
383383
Response response = await ServiceClient.AnalyzeReceiptAsyncAsync(
384384
recognizeReceiptsOptions.IncludeFieldElements,
385385
recognizeReceiptsOptions.Locale,
386-
null, // TODO: pass pages.
386+
recognizeReceiptsOptions.Pages.Count == 0 ? null : recognizeReceiptsOptions.Pages,
387387
sourcePath,
388388
cancellationToken).ConfigureAwait(false);
389389
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -422,7 +422,7 @@ public virtual RecognizeReceiptsOperation StartRecognizeReceiptsFromUri(Uri rece
422422
Response response = ServiceClient.AnalyzeReceiptAsync(
423423
recognizeReceiptsOptions.IncludeFieldElements,
424424
recognizeReceiptsOptions.Locale,
425-
null, // TODO: pass pages.
425+
recognizeReceiptsOptions.Pages.Count == 0 ? null : recognizeReceiptsOptions.Pages,
426426
sourcePath,
427427
cancellationToken);
428428
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -467,7 +467,7 @@ public virtual async Task<RecognizeBusinessCardsOperation> StartRecognizeBusines
467467
formContentType,
468468
recognizeBusinessCardsOptions.IncludeFieldElements,
469469
recognizeBusinessCardsOptions.Locale,
470-
null, // TODO: pass pages.
470+
recognizeBusinessCardsOptions.Pages.Count == 0 ? null : recognizeBusinessCardsOptions.Pages,
471471
businessCard,
472472
cancellationToken).ConfigureAwait(false);
473473
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -508,7 +508,7 @@ public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCards(Strea
508508
formContentType,
509509
recognizeBusinessCardsOptions.IncludeFieldElements,
510510
recognizeBusinessCardsOptions.Locale,
511-
null, // TODO: pass pages.
511+
recognizeBusinessCardsOptions.Pages.Count == 0 ? null : recognizeBusinessCardsOptions.Pages,
512512
businessCard,
513513
cancellationToken);
514514
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -547,7 +547,7 @@ public virtual async Task<RecognizeBusinessCardsOperation> StartRecognizeBusines
547547
Response response = await ServiceClient.AnalyzeBusinessCardAsyncAsync(
548548
recognizeBusinessCardsOptions.IncludeFieldElements,
549549
recognizeBusinessCardsOptions.Locale,
550-
null, // TODO: pass pages.
550+
recognizeBusinessCardsOptions.Pages.Count == 0 ? null : recognizeBusinessCardsOptions.Pages,
551551
sourcePath,
552552
cancellationToken).ConfigureAwait(false);
553553
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -586,7 +586,7 @@ public virtual RecognizeBusinessCardsOperation StartRecognizeBusinessCardsFromUr
586586
Response response = ServiceClient.AnalyzeBusinessCardAsync(
587587
recognizeBusinessCardsOptions.IncludeFieldElements,
588588
recognizeBusinessCardsOptions.Locale,
589-
null, // TODO: pass pages.
589+
recognizeBusinessCardsOptions.Pages.Count == 0 ? null : recognizeBusinessCardsOptions.Pages,
590590
sourcePath,
591591
cancellationToken);
592592
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -631,7 +631,7 @@ public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesAsyn
631631
formContentType,
632632
recognizeInvoicesOptions.IncludeFieldElements,
633633
recognizeInvoicesOptions.Locale,
634-
null, // TODO: pass pages.
634+
recognizeInvoicesOptions.Pages.Count == 0 ? null : recognizeInvoicesOptions.Pages,
635635
invoice,
636636
cancellationToken).ConfigureAwait(false);
637637
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -672,7 +672,7 @@ public virtual RecognizeInvoicesOperation StartRecognizeInvoices(Stream invoice,
672672
formContentType,
673673
recognizeInvoicesOptions.IncludeFieldElements,
674674
recognizeInvoicesOptions.Locale,
675-
null, // TODO: pass pages.
675+
recognizeInvoicesOptions.Pages.Count == 0 ? null : recognizeInvoicesOptions.Pages,
676676
invoice,
677677
cancellationToken);
678678
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -711,7 +711,7 @@ public virtual async Task<RecognizeInvoicesOperation> StartRecognizeInvoicesFrom
711711
Response response = await ServiceClient.AnalyzeInvoiceAsyncAsync(
712712
recognizeInvoicesOptions.IncludeFieldElements,
713713
recognizeInvoicesOptions.Locale,
714-
null, // TODO: pass pages.
714+
recognizeInvoicesOptions.Pages.Count == 0 ? null : recognizeInvoicesOptions.Pages,
715715
sourcePath,
716716
cancellationToken).ConfigureAwait(false);
717717
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -750,7 +750,7 @@ public virtual RecognizeInvoicesOperation StartRecognizeInvoicesFromUri(Uri invo
750750
Response response = ServiceClient.AnalyzeInvoiceAsync(
751751
recognizeInvoicesOptions.IncludeFieldElements,
752752
recognizeInvoicesOptions.Locale,
753-
null, // TODO: pass pages.
753+
recognizeInvoicesOptions.Pages.Count == 0 ? null : recognizeInvoicesOptions.Pages,
754754
sourcePath,
755755
cancellationToken);
756756
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -796,7 +796,7 @@ public virtual RecognizeCustomFormsOperation StartRecognizeCustomForms(string mo
796796
guid,
797797
formContentType,
798798
includeTextDetails: recognizeCustomFormsOptions.IncludeFieldElements,
799-
null, // TODO: pass pages.
799+
recognizeCustomFormsOptions.Pages.Count == 0 ? null : recognizeCustomFormsOptions.Pages,
800800
form,
801801
cancellationToken);
802802
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -838,7 +838,7 @@ public virtual RecognizeCustomFormsOperation StartRecognizeCustomFormsFromUri(st
838838
Response response = ServiceClient.AnalyzeWithCustomModel(
839839
guid,
840840
includeTextDetails: recognizeCustomFormsOptions.IncludeFieldElements,
841-
null, // TODO: pass pages.
841+
recognizeCustomFormsOptions.Pages.Count == 0 ? null : recognizeCustomFormsOptions.Pages,
842842
sourcePath,
843843
cancellationToken);
844844
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -881,7 +881,7 @@ public virtual async Task<RecognizeCustomFormsOperation> StartRecognizeCustomFor
881881
guid,
882882
formContentType,
883883
includeTextDetails: recognizeCustomFormsOptions.IncludeFieldElements,
884-
null, // TODO: pass pages.
884+
recognizeCustomFormsOptions.Pages.Count == 0 ? null : recognizeCustomFormsOptions.Pages,
885885
form,
886886
cancellationToken).ConfigureAwait(false);
887887
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);
@@ -923,7 +923,7 @@ public virtual async Task<RecognizeCustomFormsOperation> StartRecognizeCustomFor
923923
Response response = await ServiceClient.AnalyzeWithCustomModelAsync(
924924
guid,
925925
includeTextDetails: recognizeCustomFormsOptions.IncludeFieldElements,
926-
null, // TODO: pass pages.
926+
recognizeCustomFormsOptions.Pages.Count == 0 ? null : recognizeCustomFormsOptions.Pages,
927927
sourcePath,
928928
cancellationToken).ConfigureAwait(false);
929929
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

sdk/formrecognizer/Azure.AI.FormRecognizer/src/RecognizeBusinessCardsOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
5+
46
namespace Azure.AI.FormRecognizer
57
{
68
/// <summary>
@@ -37,5 +39,18 @@ public RecognizeBusinessCardsOptions()
3739
/// Supported locales include: en-AU, en-CA, en-GB, en-IN, en-US.
3840
/// </summary>
3941
public FormRecognizerLocale? Locale { get; set; }
42+
43+
/// <summary>
44+
/// <para>
45+
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
46+
/// and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
47+
/// `Pages = { "1-3", "5-6" }`. Separate each page number or range with a comma.
48+
/// </para>
49+
/// <para>
50+
/// Although this collection cannot be set, it can be modified.
51+
/// See <a href="https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers">collection initializer</a>.
52+
/// </para>
53+
/// </summary>
54+
public IList<string> Pages { get; } = new List<string>();
4055
}
4156
}

sdk/formrecognizer/Azure.AI.FormRecognizer/src/RecognizeCustomFormsOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
5+
46
namespace Azure.AI.FormRecognizer
57
{
68
/// <summary>
@@ -31,5 +33,18 @@ public RecognizeCustomFormsOptions()
3133
/// content type detection.
3234
/// </summary>
3335
public FormContentType? ContentType { get; set; }
36+
37+
/// <summary>
38+
/// <para>
39+
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
40+
/// and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
41+
/// `Pages = { "1-3", "5-6" }`. Separate each page number or range with a comma.
42+
/// </para>
43+
/// <para>
44+
/// Although this collection cannot be set, it can be modified.
45+
/// See <a href="https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers">collection initializer</a>.
46+
/// </para>
47+
/// </summary>
48+
public IList<string> Pages { get; } = new List<string>();
3449
}
3550
}

sdk/formrecognizer/Azure.AI.FormRecognizer/src/RecognizeInvoicesOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
5+
46
namespace Azure.AI.FormRecognizer
57
{
68
/// <summary>
@@ -37,5 +39,18 @@ public RecognizeInvoicesOptions()
3739
/// Supported locales include: en-US.
3840
/// </summary>
3941
public FormRecognizerLocale? Locale { get; set; }
42+
43+
/// <summary>
44+
/// <para>
45+
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
46+
/// and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
47+
/// `Pages = { "1-3", "5-6" }`. Separate each page number or range with a comma.
48+
/// </para>
49+
/// <para>
50+
/// Although this collection cannot be set, it can be modified.
51+
/// See <a href="https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers">collection initializer</a>.
52+
/// </para>
53+
/// </summary>
54+
public IList<string> Pages { get; } = new List<string>();
4055
}
4156
}

sdk/formrecognizer/Azure.AI.FormRecognizer/src/RecognizeReceiptsOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
5+
46
namespace Azure.AI.FormRecognizer
57
{
68
/// <summary>
@@ -37,5 +39,18 @@ public RecognizeReceiptsOptions()
3739
/// Supported locales include: en-AU, en-CA, en-GB, en-IN, en-US.
3840
/// </summary>
3941
public FormRecognizerLocale? Locale { get; set; }
42+
43+
/// <summary>
44+
/// <para>
45+
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the page numbers
46+
/// and/or ranges of pages you want to get in the result. For a range of pages, use a hyphen, like
47+
/// `Pages = { "1-3", "5-6" }`. Separate each page number or range with a comma.
48+
/// </para>
49+
/// <para>
50+
/// Although this collection cannot be set, it can be modified.
51+
/// See <a href="https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#collection-initializers">collection initializer</a>.
52+
/// </para>
53+
/// </summary>
54+
public IList<string> Pages { get; } = new List<string>();
4055
}
4156
}

0 commit comments

Comments
 (0)