diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py index ab22ce475a2c..addaaeca5b8e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py @@ -62,7 +62,6 @@ async def get_bounding_boxes(self): print("Form has type: {}".format(form.form_type)) for name, field in form.fields.items(): # each field is of type FormField - # The value of the field can also be a Dict[str, FormField], or a List[FormField] - in our sample, it is not. print("...Field '{}' has label '{}' with value '{}' within bounding box '{}', with a confidence score of {}".format( name, field.label_data.text if field.label_data else name, @@ -82,9 +81,8 @@ async def get_bounding_boxes(self): "...Cell[{}][{}] has text '{}' with confidence {} based on the following words: ".format( cell.row_index, cell.column_index, cell.text, cell.confidence )) - # field_elements is only populated if you set include_field_elements to True in your call - # to begin_recognize_custom_forms - # It is a heterogeneous list of FormWord and FormLine. + # field_elements is only populated if you set include_field_elements=True + # It is a heterogeneous list of FormWord, FormLine, and FormSelectionMark for element in cell.field_elements: if element.kind == "word": print("......Word '{}' within bounding box '{}' has a confidence of {}".format( 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 b955749058ce..df5aacaaefb4 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 @@ -10,7 +10,7 @@ FILE: sample_recognize_content_async.py DESCRIPTION: - This sample demonstrates how to extract text and content information from a document + This sample demonstrates how to extract text, selection marks, and content information from a document given through a file. USAGE: @@ -35,7 +35,7 @@ class RecognizeContentSampleAsync(object): async def recognize_content(self): path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__), - "..", "..", "./sample_forms/forms/Invoice_1.pdf")) + "..", "..", "./sample_forms/forms/selection_mark_form.pdf")) # [START recognize_content_async] from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import FormRecognizerClient @@ -68,7 +68,7 @@ async def recognize_content(self): cell.text, format_bounding_box(cell.bounding_box) )) - # [END recognize_content_async] + for line_idx, line in enumerate(content.lines): print("Line # {} has word count '{}' and text '{}' within bounding box '{}'".format( line_idx, @@ -78,6 +78,7 @@ async def recognize_content(self): )) for word in line.words: print("...Word '{}' has a confidence of {}".format(word.text, word.confidence)) + for selection_mark in content.selection_marks: print("Selection mark is '{}' within bounding box '{}' and has a confidence of {}".format( selection_mark.state, @@ -86,6 +87,8 @@ async def recognize_content(self): )) print("----------------------------------------") + # [END recognize_content_async] + async def main(): sample = RecognizeContentSampleAsync() diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py index e22c99e6327f..3b333d8544d8 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py @@ -67,7 +67,7 @@ async def recognize_custom_forms(self): field.label_data.text, field.confidence )) - # The value of the field can also be a Dict[str, FormField], or a List[FormField] - in our sample, it is not. + print("...Label '{}' has value '{}' with a confidence score of {}".format( field.label_data.text if field.label_data else name, field.value, field.confidence )) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/forms/selection_mark_form.pdf b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/forms/selection_mark_form.pdf new file mode 100644 index 000000000000..0721647fa52b Binary files /dev/null and b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/forms/selection_mark_form.pdf differ diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py index ddde99fbb9af..46d819ca62be 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py @@ -60,7 +60,6 @@ def get_bounding_boxes(self): print("Form has type: {}".format(form.form_type)) for name, field in form.fields.items(): # each field is of type FormField - # The value of the field can also be a Dict[str, FormField], or a List[FormField] - in our sample, it is not. print("...Field '{}' has label '{}' with value '{}' within bounding box '{}', with a confidence score of {}".format( name, field.label_data.text if field.label_data else name, @@ -79,9 +78,8 @@ def get_bounding_boxes(self): print("...Cell[{}][{}] has text '{}' with confidence {} based on the following words: ".format( cell.row_index, cell.column_index, cell.text, cell.confidence )) - # field_elements is only populated if you set include_field_elements to True in your call - # to begin_recognize_custom_forms - # It is a heterogeneous list of FormWord and FormLine. + # field_elements is only populated if you set include_field_elements=True + # It is a heterogeneous list of FormWord, FormLine, and FormSelectionMark for element in cell.field_elements: if element.kind == "word": print("......Word '{}' within bounding box '{}' has a confidence of {}".format( 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 0e3d55ca84aa..42c7543e624d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_content.py @@ -10,7 +10,7 @@ FILE: sample_recognize_content.py DESCRIPTION: - This sample demonstrates how to extract text and content information from a document + This sample demonstrates how to extract text, selection marks, and content information from a document given through a file. USAGE: python sample_recognize_content.py @@ -33,7 +33,7 @@ class RecognizeContentSample(object): def recognize_content(self): path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__), - "..", "./sample_forms/forms/Invoice_1.pdf")) + "..", "./sample_forms/forms/selection_mark_form.pdf")) # [START recognize_content] from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import FormRecognizerClient @@ -62,7 +62,7 @@ def recognize_content(self): cell.text, format_bounding_box(cell.bounding_box) )) - # [END recognize_content] + for line_idx, line in enumerate(content.lines): print("Line # {} has word count '{}' and text '{}' within bounding box '{}'".format( line_idx, @@ -72,6 +72,7 @@ def recognize_content(self): )) for word in line.words: print("...Word '{}' has a confidence of {}".format(word.text, word.confidence)) + for selection_mark in content.selection_marks: print("Selection mark is '{}' within bounding box '{}' and has a confidence of {}".format( selection_mark.state, @@ -80,6 +81,8 @@ def recognize_content(self): )) print("----------------------------------------") + # [END recognize_content] + if __name__ == '__main__': sample = RecognizeContentSample() diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py index 6e55a8764007..bea8eb964df5 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py @@ -66,7 +66,7 @@ def recognize_custom_forms(self): field.label_data.text, field.confidence )) - # The value of the field can also be a Dict[str, FormField], or a List[FormField] - in our sample, it is not. + print("...Label '{}' has value '{}' with a confidence score of {}".format( field.label_data.text if field.label_data else name, field.value, field.confidence ))