Skip to content

Commit 5d94378

Browse files
[formrecognizer] renames line appearance/style and adds to samples (Azure#16334)
* prefix appearance/style model with Text and expose models * add line appearance to sample with signature * feedback
1 parent 223d948 commit 5d94378

File tree

6 files changed

+61
-13
lines changed

6 files changed

+61
-13
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## 3.1.0b3 (Unreleased)
44

5+
**Breaking Changes**
6+
7+
- `Appearance` is renamed to `TextAppearance`
8+
- `Style` is renamed to `TextStyle`
9+
510

611
## 3.1.0b2 (2021-01-12)
712

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/__init__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
from ._version import VERSION
88
from ._form_recognizer_client import FormRecognizerClient
99
from ._form_training_client import FormTrainingClient
10-
11-
from ._generated.v2_1_preview_2.models import (
12-
Appearance,
13-
Style
14-
)
15-
16-
1710
from ._models import (
1811
FormElement,
1912
LengthUnit,
@@ -40,6 +33,8 @@
4033
FieldValueType,
4134
CustomFormModelProperties,
4235
FormSelectionMark,
36+
TextAppearance,
37+
TextStyle
4338
)
4439
from ._api_versions import FormRecognizerApiVersion
4540

@@ -73,8 +68,8 @@
7368
'FieldValueType',
7469
'CustomFormModelProperties',
7570
'FormSelectionMark',
76-
'Appearance',
77-
'Style'
71+
'TextAppearance',
72+
'TextStyle'
7873
]
7974

8075
__VERSION__ = VERSION

sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class FormLine(FormElement):
414414
:ivar int page_number:
415415
The 1-based number of the page in which this content is present.
416416
:ivar str kind: For FormLine, this is "line".
417-
:ivar appearance: Text appearance properties.
417+
:ivar appearance: An object representing the appearance of the line.
418418
:vartype appearance: ~azure.ai.formrecognizer.Appearance
419419
420420
.. versionadded:: v2.1-preview
@@ -428,7 +428,7 @@ def __init__(self, **kwargs):
428428

429429
@classmethod
430430
def _from_generated(cls, line, page):
431-
line_appearance = line.appearance if hasattr(line, "appearance") else None
431+
line_appearance = TextAppearance._from_generated(line.appearance) if hasattr(line, "appearance") else None
432432
return cls(
433433
text=line.text,
434434
bounding_box=get_bounding_box(line),
@@ -1056,3 +1056,46 @@ def _from_generated(cls, model_info):
10561056

10571057
def __repr__(self):
10581058
return "CustomFormModelProperties(is_composed_model={})".format(self.is_composed_model)
1059+
1060+
1061+
class TextAppearance(object):
1062+
"""An object representing the appearance of the text line.
1063+
1064+
:param style: An object representing the style of the text line.
1065+
:type style: ~azure.ai.formrecognizer.TextStyle
1066+
"""
1067+
1068+
def __init__(self, **kwargs):
1069+
self.style = kwargs.get('style', None)
1070+
1071+
@classmethod
1072+
def _from_generated(cls, appearance):
1073+
if appearance is None:
1074+
return appearance
1075+
return cls(
1076+
style=TextStyle(
1077+
name=appearance.style.name,
1078+
confidence=appearance.style.confidence
1079+
)
1080+
)
1081+
1082+
def __repr__(self):
1083+
return "TextAppearance(style={})".format(repr(self.style))
1084+
1085+
1086+
class TextStyle(object):
1087+
"""An object representing the style of the text line.
1088+
1089+
:param name: The text line style name.
1090+
Possible values include: "other", "handwriting".
1091+
:type name: str
1092+
:param confidence: The confidence of text line style.
1093+
:type confidence: float
1094+
"""
1095+
1096+
def __init__(self, **kwargs):
1097+
self.name = kwargs.get('name', None)
1098+
self.confidence = kwargs.get('confidence', None)
1099+
1100+
def __repr__(self):
1101+
return "TextStyle(name={}, confidence={})".format(self.name, self.confidence)

sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_content_async.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ async def recognize_content(self):
8181
line.text,
8282
format_bounding_box(line.bounding_box)
8383
))
84+
if line.appearance:
85+
if line.appearance.style.name == "handwriting" and line.appearance.style.confidence > 0.8:
86+
print("Text line '{}' is handwritten and might be a signature.".format(line.text))
8487
for word in line.words:
8588
print("...Word '{}' has a confidence of {}".format(word.text, word.confidence))
8689

sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def recognize_content(self):
7676
line.text,
7777
format_bounding_box(line.bounding_box)
7878
))
79+
if line.appearance:
80+
if line.appearance.style.name == "handwriting" and line.appearance.style.confidence > 0.8:
81+
print("Text line '{}' is handwritten and might be a signature.".format(line.text))
7982
for word in line.words:
8083
print("...Word '{}' has a confidence of {}".format(word.text, word.confidence))
8184

sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99
import datetime
1010
from azure.ai.formrecognizer import _models
11-
from azure.ai.formrecognizer import Appearance, Style
1211

1312
# All features return a tuple of the object and the repr of the obejct
1413

@@ -36,7 +35,7 @@ def form_word(bounding_box):
3635

3736
@pytest.fixture
3837
def form_line(bounding_box, form_word):
39-
appearance = Appearance(style=Style(name="other", confidence=1.0))
38+
appearance = _models.TextAppearance(style=_models.TextStyle(name="other", confidence=1.0))
4039
model = _models.FormLine(text="Word Word", bounding_box=bounding_box[0], words=[form_word[0], form_word[0]], page_number=1, appearance=appearance)
4140
model_repr = "FormLine(text=Word Word, bounding_box={}, words=[{}, {}], page_number=1, kind=line, appearance={})".format(bounding_box[1], form_word[1], form_word[1], appearance)[:1024]
4241
assert repr(model) == model_repr

0 commit comments

Comments
 (0)