From 64a89170ee476421ffc5310260ee50f243cff735 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Mon, 27 Sep 2021 18:35:03 -0700 Subject: [PATCH 1/2] print fields in samples --- .../sample_analyze_custom_documents_async.py | 17 +++++++++++++++++ .../sample_analyze_custom_documents.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py index ebebd0aceec4..b05d2d540146 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py @@ -34,6 +34,17 @@ import asyncio +def format_bounding_region(bounding_regions): + if not bounding_regions: + return "N/A" + return ", ".join("Page #{}: {}".format(region.page_number, format_bounding_box(region.bounding_box)) for region in bounding_regions) + +def format_bounding_box(bounding_box): + if not bounding_box: + return "N/A" + return ", ".join(["[{}, {}]".format(p.x, p.y) for p in bounding_box]) + + async def analyze_custom_documents_async(custom_model_id): path_to_sample_documents = os.path.abspath( os.path.join( @@ -69,6 +80,12 @@ async def analyze_custom_documents_async(custom_model_id): print("Document has type {}".format(document.doc_type)) print("Document has document type confidence {}".format(document.confidence)) print("Document was analyzed with model with ID {}".format(result.model_id)) + print("...within {} bounding regions".format(format_bounding_region(document.bounding_regions))) + for key, value in document.fields.items(): + field_value = value.content + if value.value: + field_value = value.value + print("......found field of type '{}' with value '{}' within '{}' bounding regions and with confidence {}".format(value.value_type, field_value, format_bounding_region(value.bounding_regions), value.confidence)) # iterate over tables, lines, and selection marks on each page for page in result.pages: diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py index 6ee58663c097..fdd3b45c9457 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py @@ -33,6 +33,17 @@ import os +def format_bounding_region(bounding_regions): + if not bounding_regions: + return "N/A" + return ", ".join("Page #{}: {}".format(region.page_number, format_bounding_box(region.bounding_box)) for region in bounding_regions) + +def format_bounding_box(bounding_box): + if not bounding_box: + return "N/A" + return ", ".join(["[{}, {}]".format(p.x, p.y) for p in bounding_box]) + + def analyze_custom_documents(custom_model_id): path_to_sample_documents = os.path.abspath( os.path.join( @@ -63,6 +74,13 @@ def analyze_custom_documents(custom_model_id): print("Document has type {}".format(document.doc_type)) print("Document has document type confidence {}".format(document.confidence)) print("Document was analyzed with model with ID {}".format(result.model_id)) + print("...within {} bounding regions".format(format_bounding_region(document.bounding_regions))) + for key, value in document.fields.items(): + field_value = value.content + if value.value: + field_value = value.value + print("......found field of type '{}' with value '{}' within '{}' bounding regions and with confidence {}".format(value.value_type, field_value, format_bounding_region(value.bounding_regions), value.confidence)) + # iterate over tables, lines, and selection marks on each page for page in result.pages: From af5ac5e0e59888c0cccd18379bc7bc7018a24433 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Wed, 29 Sep 2021 14:27:17 -0700 Subject: [PATCH 2/2] review feedback --- .../sample_analyze_custom_documents_async.py | 20 +++---------------- .../sample_analyze_custom_documents.py | 20 +++---------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py index b05d2d540146..5a21313ff053 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/async_samples/sample_analyze_custom_documents_async.py @@ -34,17 +34,6 @@ import asyncio -def format_bounding_region(bounding_regions): - if not bounding_regions: - return "N/A" - return ", ".join("Page #{}: {}".format(region.page_number, format_bounding_box(region.bounding_box)) for region in bounding_regions) - -def format_bounding_box(bounding_box): - if not bounding_box: - return "N/A" - return ", ".join(["[{}, {}]".format(p.x, p.y) for p in bounding_box]) - - async def analyze_custom_documents_async(custom_model_id): path_to_sample_documents = os.path.abspath( os.path.join( @@ -80,12 +69,9 @@ async def analyze_custom_documents_async(custom_model_id): print("Document has type {}".format(document.doc_type)) print("Document has document type confidence {}".format(document.confidence)) print("Document was analyzed with model with ID {}".format(result.model_id)) - print("...within {} bounding regions".format(format_bounding_region(document.bounding_regions))) - for key, value in document.fields.items(): - field_value = value.content - if value.value: - field_value = value.value - print("......found field of type '{}' with value '{}' within '{}' bounding regions and with confidence {}".format(value.value_type, field_value, format_bounding_region(value.bounding_regions), value.confidence)) + for name, field in document.fields.items(): + field_value = field.value if field.value else field.content + print("......found field of type '{}' with value '{}' and with confidence {}".format(field.value_type, field_value, field.confidence)) # iterate over tables, lines, and selection marks on each page for page in result.pages: diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py index fdd3b45c9457..3a6dd7c403ca 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/v3.2-beta/sample_analyze_custom_documents.py @@ -33,17 +33,6 @@ import os -def format_bounding_region(bounding_regions): - if not bounding_regions: - return "N/A" - return ", ".join("Page #{}: {}".format(region.page_number, format_bounding_box(region.bounding_box)) for region in bounding_regions) - -def format_bounding_box(bounding_box): - if not bounding_box: - return "N/A" - return ", ".join(["[{}, {}]".format(p.x, p.y) for p in bounding_box]) - - def analyze_custom_documents(custom_model_id): path_to_sample_documents = os.path.abspath( os.path.join( @@ -74,12 +63,9 @@ def analyze_custom_documents(custom_model_id): print("Document has type {}".format(document.doc_type)) print("Document has document type confidence {}".format(document.confidence)) print("Document was analyzed with model with ID {}".format(result.model_id)) - print("...within {} bounding regions".format(format_bounding_region(document.bounding_regions))) - for key, value in document.fields.items(): - field_value = value.content - if value.value: - field_value = value.value - print("......found field of type '{}' with value '{}' within '{}' bounding regions and with confidence {}".format(value.value_type, field_value, format_bounding_region(value.bounding_regions), value.confidence)) + for name, field in document.fields.items(): + field_value = field.value if field.value else field.content + print("......found field of type '{}' with value '{}' and with confidence {}".format(field.value_type, field_value, field.confidence)) # iterate over tables, lines, and selection marks on each page