From 68fa94ce5ba14c917e0eefe2ae9c61bf0f3721ac Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Thu, 6 May 2021 19:15:35 -0700 Subject: [PATCH 1/3] flatten style properties on text appearance model --- .../azure-ai-formrecognizer/CHANGELOG.md | 2 ++ .../azure/ai/formrecognizer/__init__.py | 2 -- .../azure/ai/formrecognizer/_models.py | 33 +++++-------------- .../sample_recognize_content_async.py | 2 +- .../samples/sample_recognize_content.py | 2 +- .../tests/test_repr.py | 2 +- .../azure-ai-formrecognizer/tests/testcase.py | 8 ++--- 7 files changed, 17 insertions(+), 34 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index c2a8658ef1b2..65f39d637a6d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -6,6 +6,8 @@ - `begin_recognize_id_documents` renamed to `begin_recognize_identity_documents` - `begin_recognize_id_documents_from_url` renamed to `begin_recognize_identity_documents_from_url` +- The model `TextAppearance` now includes the properties `style_name` and `style_confidence` that were part of the `TextStyle` object. +- Removed the model `TextStyle`. ## 3.1.0b4 (2021-04-06) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/__init__.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/__init__.py index 4c3b85a60f4d..b79b4a288654 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/__init__.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/__init__.py @@ -34,7 +34,6 @@ CustomFormModelProperties, FormSelectionMark, TextAppearance, - TextStyle, ) from ._api_versions import FormRecognizerApiVersion @@ -69,7 +68,6 @@ "CustomFormModelProperties", "FormSelectionMark", "TextAppearance", - "TextStyle", ] __VERSION__ = VERSION diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py index 850c1c6c8638..679c7b00ff86 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py @@ -1130,40 +1130,23 @@ def __repr__(self): class TextAppearance(object): """An object representing the appearance of the text line. - :param style: An object representing the style of the text line. - :type style: ~azure.ai.formrecognizer.TextStyle + :ivar str name: The text line style name. + Possible values include: "other", "handwriting". + :ivar float confidence: The confidence of text line style. """ def __init__(self, **kwargs): - self.style = kwargs.get("style", None) + self.style_name = kwargs.get("style_name", None) + self.style_confidence = kwargs.get("style_confidence", None) @classmethod def _from_generated(cls, appearance): if appearance is None: return appearance return cls( - style=TextStyle( - name=appearance.style.name, confidence=appearance.style.confidence - ) + style_name=appearance.style.name, + style_confidence=appearance.style.confidence ) def __repr__(self): - return "TextAppearance(style={})".format(repr(self.style)) - - -class TextStyle(object): - """An object representing the style of the text line. - - :param name: The text line style name. - Possible values include: "other", "handwriting". - :type name: str - :param confidence: The confidence of text line style. - :type confidence: float - """ - - def __init__(self, **kwargs): - self.name = kwargs.get("name", None) - self.confidence = kwargs.get("confidence", None) - - def __repr__(self): - return "TextStyle(name={}, confidence={})".format(self.name, self.confidence) + return "TextAppearance(style_name={}, style_confidence={})".format(self.style_name, self.style_confidence) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_content_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_content_async.py index 438ccd0432a3..1f1762b4427c 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_content_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_content_async.py @@ -82,7 +82,7 @@ async def recognize_content(self): format_bounding_box(line.bounding_box) )) if line.appearance: - if line.appearance.style.name == "handwriting" and line.appearance.style.confidence > 0.8: + if line.appearance.style_name == "handwriting" and line.appearance.style_confidence > 0.8: print("Text line '{}' is handwritten and might be a signature.".format(line.text)) for word in line.words: print("...Word '{}' has a confidence of {}".format(word.text, word.confidence)) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py index 2cd8084db43a..8edf250df55b 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py @@ -77,7 +77,7 @@ def recognize_content(self): format_bounding_box(line.bounding_box) )) if line.appearance: - if line.appearance.style.name == "handwriting" and line.appearance.style.confidence > 0.8: + if line.appearance.style_name == "handwriting" and line.appearance.style_confidence > 0.8: print("Text line '{}' is handwritten and might be a signature.".format(line.text)) for word in line.words: print("...Word '{}' has a confidence of {}".format(word.text, word.confidence)) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py index 7bb2b0ec87e8..a9876806aef6 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_repr.py @@ -35,7 +35,7 @@ def form_word(bounding_box): @pytest.fixture def form_line(bounding_box, form_word): - appearance = _models.TextAppearance(style=_models.TextStyle(name="other", confidence=1.0)) + appearance = _models.TextAppearance(style_name="other", style_confidence=1.0) model = _models.FormLine(text="Word Word", bounding_box=bounding_box[0], words=[form_word[0], form_word[0]], page_number=1, appearance=appearance) 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] assert repr(model) == model_repr diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py index 85ddd7a1d6ba..22a0085242b0 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/testcase.py @@ -296,8 +296,8 @@ def assertFormLineTransformCorrect(self, line, expected): self.assertEqual(line.text, expected.text) self.assertBoundingBoxTransformCorrect(line.bounding_box, expected.bounding_box) if expected.appearance: - self.assertEqual(line.appearance.style.name, expected.appearance.style.name) - self.assertEqual(line.appearance.style.confidence, expected.appearance.style.confidence) + self.assertEqual(line.appearance.style_name, expected.appearance.style.name) + self.assertEqual(line.appearance.style_confidence, expected.appearance.style.confidence) for word, expected_word in zip(line.words, expected.words): self.assertFormWordTransformCorrect(word, expected_word) @@ -558,8 +558,8 @@ def assertFormLineHasValues(self, line, page_number): self.assertIsNotNone(line.text) self.assertBoundingBoxHasPoints(line.bounding_box) if line.appearance: - self.assertIsNotNone(line.appearance.style.name) - self.assertIsNotNone(line.appearance.style.confidence) + self.assertIsNotNone(line.appearance.style_name) + self.assertIsNotNone(line.appearance.style_confidence) self.assertEqual(line.page_number, page_number) for word in line.words: self.assertFormWordHasValues(word, page_number) From 95794488265962c6fd536d89e2731d0a7f558db7 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Fri, 7 May 2021 17:55:29 -0700 Subject: [PATCH 2/3] fix docstring --- .../azure/ai/formrecognizer/_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py index 679c7b00ff86..4a1f8aeea0b9 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_models.py @@ -1130,9 +1130,9 @@ def __repr__(self): class TextAppearance(object): """An object representing the appearance of the text line. - :ivar str name: The text line style name. + :ivar str style_name: The text line style name. Possible values include: "other", "handwriting". - :ivar float confidence: The confidence of text line style. + :ivar float style_confidence: The confidence of text line style. """ def __init__(self, **kwargs): From ac1ecc587271f6987742dd1421138150150aa854 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Fri, 7 May 2021 18:16:06 -0700 Subject: [PATCH 3/3] adjust tests --- .../tests/test_to_dict.py | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_to_dict.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_to_dict.py index bc3c968cbc30..af4610bb7180 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_to_dict.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_to_dict.py @@ -92,7 +92,7 @@ def test_form_line_to_dict(self): ], page_number=2, appearance=_models.TextAppearance( - style=_models.TextStyle(name="other", confidence=0.90) + style_name="other", style_confidence=0.90 ), ) @@ -133,7 +133,7 @@ def test_form_line_to_dict(self): ], "page_number": 2, "kind": "line", - "appearance": {"style": {"name": "other", "confidence": 0.90}}, + "appearance": {"style_name": "other", "style_confidence": 0.90}, } assert d == final @@ -196,18 +196,11 @@ def test_form_element_to_dict(self): def test_text_appearance_to_dict(self): model = _models.TextAppearance( - style=_models.TextStyle(name="other", confidence=0.98) + style_name="other", style_confidence=0.98 ) d = model.to_dict() - final = {"style": {"name": "other", "confidence": 0.98}} - assert d == final - - def test_text_style_to_dict(self): - model = _models.TextStyle(name="other", confidence=0.98) - - d = model.to_dict() - final = {"name": "other", "confidence": 0.98} + final = {"style_name": "other", "style_confidence": 0.98} assert d == final def test_field_data_to_dict(self): @@ -395,7 +388,7 @@ def test_recognized_form_to_dict(self): ], page_number=2, appearance=_models.TextAppearance( - style=_models.TextStyle(name="other", confidence=0.90) + style_name="other", style_confidence=0.90 ), )], ) @@ -480,7 +473,7 @@ def test_recognized_form_to_dict(self): ], "page_number": 2, "kind": "line", - "appearance": {"style": {"name": "other", "confidence": 0.90}}, + "appearance": {"style_name": "other", "style_confidence": 0.90}, }], "selection_marks": [], "tables": [], @@ -574,7 +567,7 @@ def test_form_page_to_dict(self): ], page_number=2, appearance=_models.TextAppearance( - style=_models.TextStyle(name="other", confidence=0.90) + style_name="other", style_confidence=0.90 ), ), ], @@ -680,7 +673,7 @@ def test_form_page_to_dict(self): ], "page_number": 2, "kind": "line", - "appearance": {"style": {"name": "other", "confidence": 0.90}}, + "appearance": {"style_name": "other", "style_confidence": 0.90}, }], "selection_marks": [{ "text": "checkbox",