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] Expose code generated properties #16841

Merged
merged 6 commits into from
Nov 11, 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
8 changes: 6 additions & 2 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
## 3.1.0-beta.1 (Unreleased)

### Breaking changes
- It defaults to the latest supported API version, which currently is `2.1-preview.1`.
- It defaults to the latest supported API version, which currently is `2.1-preview.2`.

### 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 support to `StartRecognizeContent` to recognize selection marks such as check boxes and radio buttons.
- Added ability to create a composed model from the `FormTrainingClient` by calling method `StartCreateComposedModel`.
- Added ability to pass parameter `ModelName` to `StartTraining` methods.
- Added the properties `ModelName` and `Properties` to types `CustomFormModel` and `CustomFormModelInfo`.
- Added type `CustomFormModelProperties` that includes information like if a model is a composed model.
- Added property `ModelId` to `CustomFormSubmodel` and `TrainingDocumentInfo`.
- Added properties `ModelId` and `FormTypeConfidence` to `RecognizedForm`.
- Added support to `StartRecognizeContent` to recognize selection marks such as check boxes and radio buttons.
- Added property `Appearance` to `FormLine` to indicate the style of the extracted text. for example, "handwriting" or "other".
- Added property `BoundingBox` to `FormTable`.
- Added support for `ContentType` `image/bmp` in recognize content and prebuilt models.
- Added property `Pages` to `RecognizeContentOptions` to specify the page numbers to analyze.
maririos marked this conversation as resolved.
Show resolved Hide resolved

## 3.0.0 (2020-08-20)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace Azure.AI.FormRecognizer
{
public partial class Appearance
{
internal Appearance() { }
public Azure.AI.FormRecognizer.Style Style { get { throw null; } }
}
public enum FormContentType
{
Json = 0,
Expand Down Expand Up @@ -68,6 +73,7 @@ public partial class RecognizeContentOptions
{
public RecognizeContentOptions() { }
public Azure.AI.FormRecognizer.FormContentType? ContentType { get { throw null; } set { } }
public System.Collections.Generic.IEnumerable<string> Pages { get { throw null; } set { } }
}
public partial class RecognizeCustomFormsOptions
{
Expand All @@ -89,6 +95,12 @@ public RecognizeReceiptsOptions() { }
public bool IncludeFieldElements { get { throw null; } set { } }
public string Locale { get { throw null; } set { } }
}
public partial class Style
{
internal Style() { }
public float Confidence { get { throw null; } }
public Azure.AI.FormRecognizer.Models.TextStyle Name { get { throw null; } }
}
}
namespace Azure.AI.FormRecognizer.Models
{
Expand Down Expand Up @@ -163,6 +175,7 @@ public FormField(Azure.AI.FormRecognizer.Models.FormField field, T value) { }
public partial class FormLine : Azure.AI.FormRecognizer.Models.FormElement
{
internal FormLine() { }
public Azure.AI.FormRecognizer.Appearance Appearance { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.AI.FormRecognizer.Models.FormWord> Words { get { throw null; } }
}
public partial class FormPage
Expand Down Expand Up @@ -248,6 +261,7 @@ internal FormSelectionMark() { }
public partial class FormTable
{
internal FormTable() { }
public Azure.AI.FormRecognizer.Models.FieldBoundingBox BoundingBox { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.AI.FormRecognizer.Models.FormTableCell> Cells { get { throw null; } }
public int ColumnCount { get { throw null; } }
public int PageNumber { get { throw null; } }
Expand Down Expand Up @@ -356,8 +370,26 @@ public RecognizeReceiptsOperation(string operationId, Azure.AI.FormRecognizer.Fo
}
public enum SelectionMarkState
{
Selected = 0,
Unselected = 1,
Unselected = 0,
Selected = 1,
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct TextStyle : System.IEquatable<Azure.AI.FormRecognizer.Models.TextStyle>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public TextStyle(string value) { throw null; }
public static Azure.AI.FormRecognizer.Models.TextStyle Handwriting { get { throw null; } }
public static Azure.AI.FormRecognizer.Models.TextStyle Other { get { throw null; } }
public bool Equals(Azure.AI.FormRecognizer.Models.TextStyle other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public static bool operator ==(Azure.AI.FormRecognizer.Models.TextStyle left, Azure.AI.FormRecognizer.Models.TextStyle right) { throw null; }
public static implicit operator Azure.AI.FormRecognizer.Models.TextStyle (string value) { throw null; }
public static bool operator !=(Azure.AI.FormRecognizer.Models.TextStyle left, Azure.AI.FormRecognizer.Models.TextStyle right) { throw null; }
public override string ToString() { throw null; }
}
}
namespace Azure.AI.FormRecognizer.Training
Expand Down
15 changes: 15 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/Appearance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Azure.Core;

namespace Azure.AI.FormRecognizer
{
/// <inheritdoc />
[CodeGenModel("Appearance")]
[SuppressMessage("Usage", "AZC0012:Avoid single word type names", Justification = "Will fix name in future release")]
public partial class Appearance
{
}
}
4 changes: 4 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal FormLine(TextLine textLine, int pageNumber)
: base(new FieldBoundingBox(textLine.BoundingBox), pageNumber, textLine.Text)
{
Words = ConvertWords(textLine.Words, pageNumber);
Appearance = textLine.Appearance;
}

/// <summary>
Expand Down Expand Up @@ -45,5 +46,8 @@ private static IReadOnlyList<FormWord> ConvertWords(IReadOnlyList<TextWord> text

return rawWords;
}

/// <summary> Text appearance properties. </summary>
public Appearance Appearance { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ public virtual RecognizeContentOperation StartRecognizeContent(Stream form, Reco
{
FormContentType formContentType = recognizeContentOptions.ContentType ?? DetectContentType(form, nameof(form));

Response response = ServiceClient.AnalyzeLayoutAsync(formContentType.ConvertToContentType1(), form, null, null, cancellationToken);
Response response = ServiceClient.AnalyzeLayoutAsync(
formContentType.ConvertToContentType1(),
form,
null,
recognizeContentOptions.Pages,
cancellationToken);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeContentOperation(ServiceClient, Diagnostics, location);
Expand Down Expand Up @@ -170,7 +175,12 @@ public virtual async Task<RecognizeContentOperation> StartRecognizeContentAsync(
{
FormContentType formContentType = recognizeContentOptions.ContentType ?? DetectContentType(form, nameof(form));

Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(formContentType.ConvertToContentType1(), form, null, null, cancellationToken).ConfigureAwait(false);
Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(
formContentType.ConvertToContentType1(),
form,
null,
recognizeContentOptions.Pages,
cancellationToken).ConfigureAwait(false);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeContentOperation(ServiceClient, Diagnostics, location);
Expand Down Expand Up @@ -202,7 +212,11 @@ public virtual RecognizeContentOperation StartRecognizeContentFromUri(Uri formUr
try
{
SourcePath sourcePath = new SourcePath() { Source = formUri.AbsoluteUri };
Response response = ServiceClient.AnalyzeLayoutAsync(null, null, sourcePath, cancellationToken);
Response response = ServiceClient.AnalyzeLayoutAsync(
null,
recognizeContentOptions.Pages,
sourcePath,
cancellationToken);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeContentOperation(ServiceClient, Diagnostics, location);
Expand Down Expand Up @@ -234,7 +248,11 @@ public virtual async Task<RecognizeContentOperation> StartRecognizeContentFromUr
try
{
SourcePath sourcePath = new SourcePath() { Source = formUri.AbsoluteUri };
Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(null, null, sourcePath, cancellationToken).ConfigureAwait(false);
Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(
null,
recognizeContentOptions.Pages,
sourcePath,
cancellationToken).ConfigureAwait(false);
string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader);

return new RecognizeContentOperation(ServiceClient, Diagnostics, location);
Expand Down
6 changes: 6 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ internal FormTable(DataTable table, IReadOnlyList<ReadResult> readResults, int p
ColumnCount = table.Columns;
RowCount = table.Rows;
Cells = ConvertCells(table.Cells, readResults, readResult.Page);
// Need to verify why Bounding Box is not returned from the service
// https://github.com/Azure/azure-sdk-for-net/issues/16827
BoundingBox = table.BoundingBox == null ? new FieldBoundingBox(new List<float>()) : new FieldBoundingBox(table.BoundingBox);
}

/// <summary>
Expand Down Expand Up @@ -56,6 +59,9 @@ internal FormTable(int pageNumber, int columnCount, int rowCount, IReadOnlyList<
/// </summary>
public int RowCount { get; }

/// <summary> Bounding box of the table. </summary>
public FieldBoundingBox BoundingBox { get; }

// TODO: implement table indexer
// TODO: Handling column-span?
// https://github.com/Azure/azure-sdk-for-net/issues/9975
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace Azure.AI.FormRecognizer
{
/// <summary>
Expand All @@ -21,5 +23,12 @@ public RecognizeContentOptions()
/// content type detection.
/// </summary>
public FormContentType? ContentType { get; set; } = null;

/// <summary>
/// Custom page numbers for multi-page documents(PDF/TIFF). Input the number of the
/// pages you want to get OCR result. For a range of pages, use a hyphen.
/// Separate each page or range with a comma.
/// </summary>
public IEnumerable<string> Pages { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ namespace Azure.AI.FormRecognizer.Models
public enum SelectionMarkState
{
/// <summary>
/// Value is selected.
/// Value is unselected.
/// </summary>
Selected,
Unselected,

/// <summary>
/// Value is unselected.
/// Value is selected.
/// </summary>
Unselected
Selected
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ internal static class StreamExtensions
/// <summary>The set of bytes expected to be present at the start of TIFF (big-endian) files.</summary>
private static byte[] TiffBeHeader = new byte[] { 0x4D, 0x4D, 0x00, 0x2A };

/// <summary>The set of bytes expected to be present at the start of BMP files.</summary>
private static byte[] BmpHeader = new byte[] { 0x42, 0x4D };

/// <summary>
/// Attemps to detect the <see cref="FormContentType"/> of a stream of bytes. The algorithm searches through
/// the first set of bytes in the stream and compares it to well-known file signatures.
Expand All @@ -50,6 +53,10 @@ public static bool TryGetContentType(this Stream stream, out FormContentType con
{
contentType = FormContentType.Tiff;
}
else if (stream.BeginsWithHeader(BmpHeader))
{
contentType = FormContentType.Bmp;
}
else
{
contentType = default;
Expand Down
15 changes: 15 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/Style.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Azure.Core;

namespace Azure.AI.FormRecognizer
{
/// <inheritdoc />
[CodeGenModel("Style")]
[SuppressMessage("Usage", "AZC0012:Avoid single word type names", Justification = "Will fix name in future release")]
public partial class Style
{
}
}
4 changes: 3 additions & 1 deletion sdk/formrecognizer/Azure.AI.FormRecognizer/src/TextStyle.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using Azure.Core;

namespace Azure.AI.FormRecognizer.Models
{
[CodeGenModel("TextStyle")]
internal partial struct TextStyle
[SuppressMessage("Usage", "AZC0012:Avoid single word type names", Justification = "Will fix name in future release")]
public partial struct TextStyle
{ }
}
Binary file not shown.
Loading