Skip to content

Commit 7921a42

Browse files
chore(python): run blacken session for all directories with a noxfile (#241)
Source-Link: googleapis/synthtool@bc0de6e Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:39ad8c0570e4f5d2d3124a509de4fe975e799e2b97e0f58aed88f8880d5a8b60 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 102553b commit 7921a42

7 files changed

+38
-32
lines changed

documentai/snippets/batch_process_documents_sample.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def batch_process_documents(
6363
# Location can be 'us' or 'eu'
6464
name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"
6565
request = documentai.types.document_processor_service.BatchProcessRequest(
66-
name=name,
67-
input_documents=input_config,
68-
document_output_config=output_config,
66+
name=name, input_documents=input_config, document_output_config=output_config,
6967
)
7068

7169
operation = client.batch_process_documents(request)

documentai/snippets/process_document_form_sample.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console
2222
# file_path = '/path/to/local/pdf'
2323

24+
2425
def process_document_form_sample(
2526
project_id: str, location: str, processor_id: str, file_path: str
2627
):
@@ -69,9 +70,9 @@ def process_document_form_sample(
6970
for table in page.tables:
7071
num_collumns = len(table.header_rows[0].cells)
7172
num_rows = len(table.body_rows)
72-
print(f'Table with {num_collumns} columns and {num_rows} rows:')
73+
print(f"Table with {num_collumns} columns and {num_rows} rows:")
7374
print_table_info(table, text)
74-
print(f'Found {len(page.form_fields)} form fields:')
75+
print(f"Found {len(page.form_fields)} form fields:")
7576
for field in page.form_fields:
7677
name = layout_to_text(field.field_name, text)
7778
value = layout_to_text(field.field_value, text)
@@ -80,17 +81,17 @@ def process_document_form_sample(
8081

8182
def print_table_info(table: dict, text: str) -> None:
8283
# Print header row
83-
header_row_text = ''
84+
header_row_text = ""
8485
for header_cell in table.header_rows[0].cells:
8586
header_cell_text = layout_to_text(header_cell.layout, text)
86-
header_row_text += f'{repr(header_cell_text.strip())} | '
87-
print(f'Collumns: {header_row_text[:-3]}')
87+
header_row_text += f"{repr(header_cell_text.strip())} | "
88+
print(f"Collumns: {header_row_text[:-3]}")
8889
# Print first body row
89-
body_row_text = ''
90+
body_row_text = ""
9091
for body_cell in table.body_rows[0].cells:
9192
body_cell_text = layout_to_text(body_cell.layout, text)
92-
body_row_text += f'{repr(body_cell_text.strip())} | '
93-
print(f'First row data: {body_row_text[:-3]}\n')
93+
body_row_text += f"{repr(body_cell_text.strip())} | "
94+
print(f"First row data: {body_row_text[:-3]}\n")
9495

9596

9697
def layout_to_text(layout: dict, text: str) -> str:

documentai/snippets/process_document_ocr_sample.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console
2222
# file_path = '/path/to/local/pdf'
2323

24+
2425
def process_document_ocr_sample(
2526
project_id: str, location: str, processor_id: str, file_path: str
2627
) -> None:
@@ -78,7 +79,7 @@ def print_detected_langauges(detected_languages: dict) -> None:
7879
print(" Detected languages:")
7980
for lang in detected_languages:
8081
code = lang.language_code
81-
conf_percent = '{:.1%}'.format(lang.confidence)
82+
conf_percent = "{:.1%}".format(lang.confidence)
8283
print(f" {code} ({conf_percent} confidence)")
8384

8485

documentai/snippets/process_document_quality_sample.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console
2222
# file_path = '/path/to/local/pdf'
2323

24+
2425
def process_document_quality_sample(
2526
project_id: str, location: str, processor_id: str, file_path: str
2627
):
@@ -60,17 +61,18 @@ def process_document_quality_sample(
6061
# response.
6162
document = result.document
6263
for entity in document.entities:
63-
conf_percent = '{:.1%}'.format(entity.confidence)
64-
page_num = ''
64+
conf_percent = "{:.1%}".format(entity.confidence)
65+
page_num = ""
6566
try:
6667
page_num = str(int(entity.page_anchor.page_refs.page) + 1)
6768
except AttributeError:
6869
page_num = "1"
6970

70-
print(f'Page {page_num} has a quality score of {conf_percent}:')
71+
print(f"Page {page_num} has a quality score of {conf_percent}:")
7172

7273
for prop in entity.properties:
73-
conf_percent = '{:.1%}'.format(prop.confidence)
74-
print(f' * {prop.type_} score of {conf_percent}')
74+
conf_percent = "{:.1%}".format(prop.confidence)
75+
print(f" * {prop.type_} score of {conf_percent}")
76+
7577

7678
# [END documentai_process_quality_document]

documentai/snippets/process_document_quality_sample_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_process_documents(capsys):
3636
expected_strings = [
3737
"Page 1 has a quality score of",
3838
"defect_blurry score of 9",
39-
"defect_noisy"
39+
"defect_noisy",
4040
]
4141
for expected_string in expected_strings:
4242
assert expected_string in out

documentai/snippets/process_document_specialized_sample.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console
2222
# file_path = '/path/to/local/pdf'
2323

24+
2425
def process_document_specialized_sample(
2526
project_id: str, location: str, processor_id: str, file_path: str
2627
):
@@ -62,7 +63,7 @@ def process_document_specialized_sample(
6263
# Please see the OCR and other samples for how to parse other data in the
6364
# response.
6465
document = result.document
65-
print(f'Found {len(document.entities)} entities:')
66+
print(f"Found {len(document.entities)} entities:")
6667
for entity in document.entities:
6768
# Fields detected. For a full list of fields for each processor see
6869
# the processor documentation:
@@ -71,7 +72,8 @@ def process_document_specialized_sample(
7172
# some other value formats in addition to text are availible
7273
# e.g. dates: `entity.normalized_value.date_value.year`
7374
text_value = entity.text_anchor.content
74-
conf_percent = '{:.1%}'.format(entity.confidence)
75-
print(f' * {repr(key)}: {repr(text_value)}({conf_percent} confident)')
75+
conf_percent = "{:.1%}".format(entity.confidence)
76+
print(f" * {repr(key)}: {repr(text_value)}({conf_percent} confident)")
77+
7678

7779
# [END documentai_process_specialized_document]

documentai/snippets/process_document_splitter_sample.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor in Cloud Console
2222
# file_path = '/path/to/local/pdf'
2323

24+
2425
def process_document_splitter_sample(
25-
project_id: str,
26-
location: str,
27-
processor_id: str,
28-
file_path: str):
26+
project_id: str, location: str, processor_id: str, file_path: str
27+
):
2928
from google.cloud import documentai_v1beta3 as documentai
3029

3130
# You must set the api_endpoint if you use a location other than 'us', e.g.:
@@ -61,26 +60,29 @@ def process_document_splitter_sample(
6160
# form elements, and entities please see other processors like the OCR, form,
6261
# and specalized processors.
6362
document = result.document
64-
print(f'Found {len(document.entities)} subdocuments:')
63+
print(f"Found {len(document.entities)} subdocuments:")
6564
for entity in document.entities:
66-
conf_percent = '{:.1%}'.format(entity.confidence)
65+
conf_percent = "{:.1%}".format(entity.confidence)
6766
pages_range = page_refs_to_string(entity.page_anchor.page_refs)
6867
# Print subdocument type information, if available
6968
try:
7069
doctype = entity.type
71-
print(f'{conf_percent} confident that {pages_range} a "{doctype}" subdocument.')
70+
print(
71+
f'{conf_percent} confident that {pages_range} a "{doctype}" subdocument.'
72+
)
7273
except AttributeError:
73-
print(f'{conf_percent} confident that {pages_range} a subdocument.')
74+
print(f"{conf_percent} confident that {pages_range} a subdocument.")
7475

7576

7677
def page_refs_to_string(page_refs: dict) -> str:
77-
''' Converts a page ref to a string describing the page or page range.'''
78+
""" Converts a page ref to a string describing the page or page range."""
7879
if len(page_refs) == 1:
7980
num = str(int(page_refs[0].page) + 1)
80-
return f'page {num} is'
81+
return f"page {num} is"
8182
else:
8283
start = str(int(page_refs[0].page) + 1)
8384
end = str(int(page_refs[1].page) + 1)
84-
return f'pages {start} to {end} are'
85+
return f"pages {start} to {end} are"
86+
8587

8688
# [END documentai_process_splitter_document]

0 commit comments

Comments
 (0)