@@ -7,7 +7,7 @@ manager: nitinme
7
7
ms.service : applied-ai-services
8
8
ms.subservice : forms-recognizer
9
9
ms.topic : quickstart
10
- ms.date : 03/31 /2022
10
+ ms.date : 06/23 /2022
11
11
ms.author : lajanuar
12
12
recommendations : false
13
13
---
@@ -107,12 +107,12 @@ key = "<your-key>"
107
107
def format_bounding_region (bounding_regions ):
108
108
if not bounding_regions:
109
109
return " N/A"
110
- return " , " .join(" Page #{} : {} " .format(region.page_number, format_bounding_box (region.bounding_box )) for region in bounding_regions)
110
+ return " , " .join(" Page #{} : {} " .format(region.page_number, format_polygon (region.polygon )) for region in bounding_regions)
111
111
112
- def format_bounding_box ( bounding_box ):
113
- if not bounding_box :
112
+ def format_polygon ( polygon ):
113
+ if not polygon :
114
114
return " N/A"
115
- return " , " .join([" [{} , {} ]" .format(p.x, p.y) for p in bounding_box ])
115
+ return " , " .join([" [{} , {} ]" .format(p.x, p.y) for p in polygon ])
116
116
117
117
118
118
def analyze_general_documents ():
@@ -148,13 +148,6 @@ def analyze_general_documents():
148
148
)
149
149
)
150
150
151
- print (" ----Entities found in document----" )
152
- for entity in result.entities:
153
- print (" Entity of category '{} ' with sub-category '{} '" .format(entity.category, entity.sub_category))
154
- print (" ...has content '{} '" .format(entity.content))
155
- print (" ...within '{} ' bounding regions" .format(format_bounding_region(entity.bounding_regions)))
156
- print (" ...with confidence {} \n " .format(entity.confidence))
157
-
158
151
for page in result.pages:
159
152
print (" ----Analyzing document from page #{} ----" .format(page.page_number))
160
153
print (
@@ -168,7 +161,7 @@ def analyze_general_documents():
168
161
" ...Line # {} has text content '{} ' within bounding box '{} '" .format(
169
162
line_idx,
170
163
line.content,
171
- format_bounding_box (line.bounding_box ),
164
+ format_polygon (line.polygon ),
172
165
)
173
166
)
174
167
@@ -183,7 +176,7 @@ def analyze_general_documents():
183
176
print (
184
177
" ...Selection mark is '{} ' within bounding box '{} ' and has a confidence of {} " .format(
185
178
selection_mark.state,
186
- format_bounding_box (selection_mark.bounding_box ),
179
+ format_polygon (selection_mark.polygon ),
187
180
selection_mark.confidence,
188
181
)
189
182
)
@@ -199,7 +192,7 @@ def analyze_general_documents():
199
192
" Table # {} location on page: {} is {} " .format(
200
193
table_idx,
201
194
region.page_number,
202
- format_bounding_box (region.bounding_box ),
195
+ format_polygon (region.polygon ),
203
196
)
204
197
)
205
198
for cell in table.cells:
@@ -214,7 +207,7 @@ def analyze_general_documents():
214
207
print (
215
208
" ...content on page {} is within bounding box '{} '\n " .format(
216
209
region.page_number,
217
- format_bounding_box (region.bounding_box ),
210
+ format_polygon (region.polygon ),
218
211
)
219
212
)
220
213
print (" ----------------------------------------" )
@@ -274,17 +267,18 @@ from azure.core.credentials import AzureKeyCredential
274
267
endpoint = " <your-endpoint>"
275
268
key = " <your-key>"
276
269
277
- def format_bounding_box ( bounding_box ):
278
- if not bounding_box :
270
+ def format_polygon ( polygon ):
271
+ if not polygon :
279
272
return " N/A"
280
- return " , " .join([" [{} , {} ]" .format(p.x, p.y) for p in bounding_box ])
273
+ return " , " .join([" [{} , {} ]" .format(p.x, p.y) for p in polygon ])
281
274
282
275
def analyze_layout ():
283
276
# sample form document
284
277
formUrl = " https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf"
285
278
286
- # create your `DocumentAnalysisClient` instance and `AzureKeyCredential` variable
287
- document_analysis_client = DocumentAnalysisClient(endpoint = endpoint, credential = AzureKeyCredential(key))
279
+ document_analysis_client = DocumentAnalysisClient(
280
+ endpoint = endpoint, credential = AzureKeyCredential(key)
281
+ )
288
282
289
283
poller = document_analysis_client.begin_analyze_document_from_url(
290
284
" prebuilt-layout" , formUrl)
@@ -312,7 +306,7 @@ def analyze_layout():
312
306
line_idx,
313
307
len (words),
314
308
line.content,
315
- format_bounding_box (line.bounding_box ),
309
+ format_polygon (line.polygon ),
316
310
)
317
311
)
318
312
@@ -327,7 +321,7 @@ def analyze_layout():
327
321
print (
328
322
" ...Selection mark is '{} ' within bounding box '{} ' and has a confidence of {} " .format(
329
323
selection_mark.state,
330
- format_bounding_box (selection_mark.bounding_box ),
324
+ format_polygon (selection_mark.polygon ),
331
325
selection_mark.confidence,
332
326
)
333
327
)
@@ -343,7 +337,7 @@ def analyze_layout():
343
337
" Table # {} location on page: {} is {} " .format(
344
338
table_idx,
345
339
region.page_number,
346
- format_bounding_box (region.bounding_box ),
340
+ format_polygon (region.polygon ),
347
341
)
348
342
)
349
343
for cell in table.cells:
@@ -358,7 +352,7 @@ def analyze_layout():
358
352
print (
359
353
" ...content on page {} is within bounding box '{} '" .format(
360
354
region.page_number,
361
- format_bounding_box (region.bounding_box ),
355
+ format_polygon (region.polygon ),
362
356
)
363
357
)
364
358
@@ -434,20 +428,21 @@ key = "<your-key>"
434
428
def format_bounding_region (bounding_regions ):
435
429
if not bounding_regions:
436
430
return " N/A"
437
- return " , " .join(" Page #{} : {} " .format(region.page_number, format_bounding_box (region.bounding_box )) for region in bounding_regions)
431
+ return " , " .join(" Page #{} : {} " .format(region.page_number, format_polygon (region.polygon )) for region in bounding_regions)
438
432
439
- def format_bounding_box ( bounding_box ):
440
- if not bounding_box :
433
+ def format_polygon ( polygon ):
434
+ if not polygon :
441
435
return " N/A"
442
- return " , " .join([" [{} , {} ]" .format(p.x, p.y) for p in bounding_box ])
436
+ return " , " .join([" [{} , {} ]" .format(p.x, p.y) for p in polygon ])
443
437
444
438
445
439
def analyze_invoice ():
446
440
447
441
invoiceUrl = " https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf"
448
442
449
- # create your `DocumentAnalysisClient` instance and `AzureKeyCredential` variable
450
- document_analysis_client = DocumentAnalysisClient(endpoint = endpoint, credential = AzureKeyCredential(key))
443
+ document_analysis_client = DocumentAnalysisClient(
444
+ endpoint = endpoint, credential = AzureKeyCredential(key)
445
+ )
451
446
452
447
poller = document_analysis_client.begin_analyze_document_from_url(
453
448
" prebuilt-invoice" , invoiceUrl)
@@ -702,6 +697,8 @@ def analyze_invoice():
702
697
703
698
if __name__ == " __main__" :
704
699
analyze_invoice()
700
+
701
+ print (" ----------------------------------------" )
705
702
```
706
703
707
704
** Run the application**
0 commit comments