google-cloud-documentai-toolbox 0.15.2__tar.gz → 0.16.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_cloud_documentai_toolbox-0.15.2/google_cloud_documentai_toolbox.egg-info → google_cloud_documentai_toolbox-0.16.0}/PKG-INFO +1 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/__init__.py +8 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/converters/config/bbox_conversion.py +23 -9
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/converters/config/block.py +23 -25
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/converters/converter.py +1 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/converters/vision_helpers.py +6 -6
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/utilities/gcs_utilities.py +5 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/version.py +1 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/wrappers/document.py +5 -4
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/wrappers/entity.py +4 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/wrappers/page.py +4 -4
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0/google_cloud_documentai_toolbox.egg-info}/PKG-INFO +1 -1
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/LICENSE +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/MANIFEST.in +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/README.rst +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/constants.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/converters/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/converters/config/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/py.typed +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/templates/hocr_document_template.xml.j2 +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/utilities/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/utilities/docai_utilities.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google/cloud/documentai_toolbox/wrappers/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google_cloud_documentai_toolbox.egg-info/SOURCES.txt +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google_cloud_documentai_toolbox.egg-info/dependency_links.txt +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google_cloud_documentai_toolbox.egg-info/not-zip-safe +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google_cloud_documentai_toolbox.egg-info/requires.txt +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/google_cloud_documentai_toolbox.egg-info/top_level.txt +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/setup.cfg +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/setup.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/__init__.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/0/toolbox_invoice_test-0.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/1/toolbox_large_document_test-0.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/1/toolbox_large_document_test-1.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/1/toolbox_large_document_test-2.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/1/toolbox_large_document_test-3.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/1/toolbox_large_document_test-4.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/blank_document.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/classifier/custom_classifier_output.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/converters/test_config_type_1.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/converters/test_config_type_2.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/converters/test_config_type_3.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/converters/test_type_1.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/converters/test_type_2.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/converters/test_type_3.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/form_parser/pretrained-form-parser-v1.0-2020-09-23_full-output.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/hex_ids/patent.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/images/dl3-0.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/layout_parser/layout_parser.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/merged_document/merged_shards.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-0.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-1.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-3.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/missing_shard/Winnie_the_Pooh_50_Pages-4.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/multi_page/pretrained-ocr-v1.0-2020-09-23_output.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/pretrained-ocr-v2.0-2023-06-02_math_output.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/procurement_multi_document.pdf +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/splitter/procurement_splitter_output.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_invoice_test-0-hocr-escape.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_invoice_test-0-hocr-escape.xml +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_invoice_test-0-vision.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_invoice_test-with-symbols.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_invoice_test.pdf +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_invoice_test_0_hocr.xml +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/toolbox_large_document_test.pdf +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-0.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-1.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-2.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-3.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/resources/unordered_shards/Winnie_the_Pooh_50_Pages-4.json +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_bbox_conversion.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_block.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_converter.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_document.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_entity.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_gcs_utilities.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_packaging.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_page.py +0 -0
- {google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/unit/test_vision_helper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-cloud-documentai-toolbox
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.0
|
|
4
4
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-documentai-toolbox
|
|
5
5
|
Author: Google LLC
|
|
6
6
|
Author-email: googleapis-packages@google.com
|
|
@@ -25,7 +25,14 @@ from .converters import converter
|
|
|
25
25
|
from .utilities import docai_utilities, gcs_utilities
|
|
26
26
|
from .wrappers import document, entity, page
|
|
27
27
|
|
|
28
|
-
__all__ = (
|
|
28
|
+
__all__ = (
|
|
29
|
+
"document",
|
|
30
|
+
"page",
|
|
31
|
+
"entity",
|
|
32
|
+
"converter",
|
|
33
|
+
"docai_utilities",
|
|
34
|
+
"gcs_utilities",
|
|
35
|
+
)
|
|
29
36
|
|
|
30
37
|
|
|
31
38
|
class Python37DeprecationWarning(DeprecationWarning): # pragma: NO COVER
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
from typing import Callable, List, Optional
|
|
18
19
|
|
|
19
20
|
from intervaltree import intervaltree
|
|
@@ -190,16 +191,21 @@ def convert_bbox_to_docproto_bbox(block: Block) -> documentai.BoundingPoly:
|
|
|
190
191
|
y_multiplier = 1.0
|
|
191
192
|
normalized_vertices: List[documentai.NormalizedVertex] = []
|
|
192
193
|
|
|
193
|
-
if
|
|
194
|
+
if (
|
|
195
|
+
block.page_width
|
|
196
|
+
and block.page_height
|
|
197
|
+
and block.docproto_width is not None
|
|
198
|
+
and block.docproto_height is not None
|
|
199
|
+
):
|
|
194
200
|
x_multiplier = _get_multiplier(
|
|
195
201
|
docproto_coordinate=block.docproto_width,
|
|
196
202
|
external_coordinate=block.page_width,
|
|
197
|
-
input_bbox_units=block.bounding_unit,
|
|
203
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
198
204
|
)
|
|
199
205
|
y_multiplier = _get_multiplier(
|
|
200
206
|
docproto_coordinate=block.docproto_height,
|
|
201
207
|
external_coordinate=block.page_height,
|
|
202
|
-
input_bbox_units=block.bounding_unit,
|
|
208
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
203
209
|
)
|
|
204
210
|
|
|
205
211
|
if block.bounding_type == "1":
|
|
@@ -208,13 +214,13 @@ def convert_bbox_to_docproto_bbox(block: Block) -> documentai.BoundingPoly:
|
|
|
208
214
|
for coordinate in block.bounding_box:
|
|
209
215
|
x = _convert_bbox_units(
|
|
210
216
|
coordinate[f"{block.bounding_x}"],
|
|
211
|
-
input_bbox_units=block.bounding_unit,
|
|
217
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
212
218
|
width=block.docproto_width,
|
|
213
219
|
multiplier=x_multiplier,
|
|
214
220
|
)
|
|
215
221
|
y = _convert_bbox_units(
|
|
216
222
|
coordinate[f"{block.bounding_y}"],
|
|
217
|
-
input_bbox_units=block.bounding_unit,
|
|
223
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
218
224
|
height=block.docproto_height,
|
|
219
225
|
multiplier=y_multiplier,
|
|
220
226
|
)
|
|
@@ -224,18 +230,24 @@ def convert_bbox_to_docproto_bbox(block: Block) -> documentai.BoundingPoly:
|
|
|
224
230
|
elif block.bounding_type == "2":
|
|
225
231
|
# Type 2 : bounding box has 1 (x,y) coordinates for the top left corner
|
|
226
232
|
# and (width, height)
|
|
233
|
+
if not isinstance(block.bounding_box, dict):
|
|
234
|
+
raise TypeError("Expected dict for bounding_box in Type 2")
|
|
227
235
|
x_min = _convert_bbox_units(
|
|
228
236
|
block.bounding_box[f"{block.bounding_x}"],
|
|
229
|
-
input_bbox_units=block.bounding_unit,
|
|
237
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
230
238
|
width=block.page_width,
|
|
231
239
|
multiplier=x_multiplier,
|
|
232
240
|
)
|
|
233
241
|
y_min = _convert_bbox_units(
|
|
234
242
|
block.bounding_box[f"{block.bounding_y}"],
|
|
235
|
-
input_bbox_units=block.bounding_unit,
|
|
243
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
236
244
|
width=block.page_height,
|
|
237
245
|
multiplier=y_multiplier,
|
|
238
246
|
)
|
|
247
|
+
if block.bounding_width is None or block.bounding_height is None:
|
|
248
|
+
raise ValueError(
|
|
249
|
+
"bounding_width and bounding_height must be set for Type 2"
|
|
250
|
+
)
|
|
239
251
|
x_max = x_min + block.bounding_width
|
|
240
252
|
y_max = y_min + block.bounding_height
|
|
241
253
|
normalized_vertices.extend(
|
|
@@ -249,16 +261,18 @@ def convert_bbox_to_docproto_bbox(block: Block) -> documentai.BoundingPoly:
|
|
|
249
261
|
|
|
250
262
|
elif block.bounding_type == "3":
|
|
251
263
|
# Type 3 : bounding_box: [x1, y1, x2, y2, x3, y3, x4, y4]
|
|
264
|
+
if not isinstance(block.bounding_box, list):
|
|
265
|
+
raise TypeError("Expected list for bounding_box in Type 3")
|
|
252
266
|
for idx in range(0, len(block.bounding_box), 2):
|
|
253
267
|
x = _convert_bbox_units(
|
|
254
268
|
block.bounding_box[idx],
|
|
255
|
-
input_bbox_units=block.bounding_unit,
|
|
269
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
256
270
|
width=block.docproto_width,
|
|
257
271
|
multiplier=x_multiplier,
|
|
258
272
|
)
|
|
259
273
|
y = _convert_bbox_units(
|
|
260
274
|
block.bounding_box[idx + 1],
|
|
261
|
-
input_bbox_units=block.bounding_unit,
|
|
275
|
+
input_bbox_units=block.bounding_unit or "normalized",
|
|
262
276
|
width=block.docproto_height,
|
|
263
277
|
multiplier=y_multiplier,
|
|
264
278
|
)
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
import dataclasses
|
|
18
18
|
import json
|
|
19
19
|
from types import SimpleNamespace
|
|
20
|
-
from typing import List, Optional, Type
|
|
20
|
+
from typing import Any, List, Optional, Type, Union
|
|
21
21
|
|
|
22
22
|
from google.cloud import documentai
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def _get_target_object(json_data:
|
|
25
|
+
def _get_target_object(json_data: Any, target_object: str) -> Any:
|
|
26
26
|
r"""Returns SimpleNamespace of target_object.
|
|
27
27
|
|
|
28
28
|
Args:
|
|
@@ -72,45 +72,39 @@ class Block:
|
|
|
72
72
|
page_number:
|
|
73
73
|
Optional.
|
|
74
74
|
"""
|
|
75
|
-
type_:
|
|
76
|
-
text:
|
|
77
|
-
bounding_box: Optional[SimpleNamespace] = dataclasses.field(
|
|
75
|
+
type_: Any = dataclasses.field(init=True, repr=False)
|
|
76
|
+
text: str = dataclasses.field(init=True, repr=False)
|
|
77
|
+
bounding_box: Optional[Union[SimpleNamespace, List[Any]]] = dataclasses.field(
|
|
78
78
|
init=True, repr=False, default=None
|
|
79
79
|
)
|
|
80
|
-
block_references:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
block_id: Optional[SimpleNamespace] = dataclasses.field(
|
|
84
|
-
init=False, repr=False, default=None
|
|
85
|
-
)
|
|
86
|
-
confidence: Optional[SimpleNamespace] = dataclasses.field(
|
|
87
|
-
init=False, repr=False, default=None
|
|
88
|
-
)
|
|
89
|
-
page_number: Optional[SimpleNamespace] = dataclasses.field(
|
|
80
|
+
block_references: Any = dataclasses.field(init=True, repr=False, default=None)
|
|
81
|
+
block_id: Optional[str] = dataclasses.field(init=False, repr=False, default=None)
|
|
82
|
+
confidence: Optional[float] = dataclasses.field(
|
|
90
83
|
init=False, repr=False, default=None
|
|
91
84
|
)
|
|
92
|
-
|
|
85
|
+
page_number: Optional[int] = dataclasses.field(init=False, repr=False, default=None)
|
|
86
|
+
page_width: Optional[float] = dataclasses.field(
|
|
93
87
|
init=False, repr=False, default=None
|
|
94
88
|
)
|
|
95
|
-
page_height: Optional[
|
|
89
|
+
page_height: Optional[float] = dataclasses.field(
|
|
96
90
|
init=False, repr=False, default=None
|
|
97
91
|
)
|
|
98
|
-
bounding_width: Optional[
|
|
92
|
+
bounding_width: Optional[float] = dataclasses.field(
|
|
99
93
|
init=False, repr=False, default=None
|
|
100
94
|
)
|
|
101
|
-
bounding_height: Optional[
|
|
95
|
+
bounding_height: Optional[float] = dataclasses.field(
|
|
102
96
|
init=False, repr=False, default=None
|
|
103
97
|
)
|
|
104
|
-
bounding_type: Optional[
|
|
98
|
+
bounding_type: Optional[str] = dataclasses.field(
|
|
105
99
|
init=False, repr=False, default=None
|
|
106
100
|
)
|
|
107
|
-
bounding_unit: Optional[
|
|
101
|
+
bounding_unit: Optional[str] = dataclasses.field(
|
|
108
102
|
init=False, repr=False, default=None
|
|
109
103
|
)
|
|
110
|
-
bounding_x: Optional[
|
|
104
|
+
bounding_x: Optional[float] = dataclasses.field(
|
|
111
105
|
init=False, repr=False, default=None
|
|
112
106
|
)
|
|
113
|
-
bounding_y: Optional[
|
|
107
|
+
bounding_y: Optional[float] = dataclasses.field(
|
|
114
108
|
init=False, repr=False, default=None
|
|
115
109
|
)
|
|
116
110
|
docproto_width: Optional[float] = dataclasses.field(
|
|
@@ -180,6 +174,8 @@ class Block:
|
|
|
180
174
|
|
|
181
175
|
blocks: List[Block] = []
|
|
182
176
|
ens = _get_target_object(objects, entities)
|
|
177
|
+
if not isinstance(ens, (list, dict)):
|
|
178
|
+
raise TypeError("Expected list or dict for entities")
|
|
183
179
|
for i in ens:
|
|
184
180
|
entity = i
|
|
185
181
|
|
|
@@ -203,11 +199,13 @@ class Block:
|
|
|
203
199
|
b = Block(
|
|
204
200
|
type_=block_type,
|
|
205
201
|
text=block_text,
|
|
206
|
-
bounding_box=_get_target_object(entity, normalized_vertices)
|
|
202
|
+
bounding_box=_get_target_object(entity, normalized_vertices)
|
|
203
|
+
if normalized_vertices is not None
|
|
204
|
+
else None,
|
|
207
205
|
)
|
|
208
206
|
|
|
209
207
|
if id_:
|
|
210
|
-
b.
|
|
208
|
+
b.block_id = _get_target_object(entity, id_)
|
|
211
209
|
if confidence:
|
|
212
210
|
b.confidence = _get_target_object(entity, confidence)
|
|
213
211
|
if page_number and page_number in entity:
|
|
@@ -424,7 +424,7 @@ def convert_from_config(
|
|
|
424
424
|
|
|
425
425
|
print("-------- Converting Started --------")
|
|
426
426
|
files, labels, did_not_convert = _get_docproto_files(
|
|
427
|
-
futures_list, project_id, location, processor_id
|
|
427
|
+
list(futures_list), project_id, location, processor_id
|
|
428
428
|
)
|
|
429
429
|
|
|
430
430
|
print("-------- Finished Converting --------")
|
|
@@ -243,17 +243,17 @@ def _generate_entity_annotations(
|
|
|
243
243
|
"""
|
|
244
244
|
entity_annotations: List[EntityAnnotation] = []
|
|
245
245
|
for token in page_info.page.tokens:
|
|
246
|
-
v: vision.Vertex = []
|
|
246
|
+
v: list[vision.Vertex] = []
|
|
247
247
|
if token.layout.bounding_poly.vertices:
|
|
248
248
|
for vertex in token.layout.bounding_poly.vertices:
|
|
249
|
-
v.append(
|
|
249
|
+
v.append(vision.Vertex(x=int(vertex.x), y=int(vertex.y)))
|
|
250
250
|
else:
|
|
251
251
|
for normalized_vertex in token.layout.bounding_poly.normalized_vertices:
|
|
252
252
|
v.append(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
vision.Vertex(
|
|
254
|
+
x=int(normalized_vertex.x * page_info.page.dimension.width),
|
|
255
|
+
y=int(normalized_vertex.y * page_info.page.dimension.height),
|
|
256
|
+
)
|
|
257
257
|
)
|
|
258
258
|
|
|
259
259
|
text_start_index = token.layout.text_anchor.text_segments[0].start_index
|
|
@@ -20,7 +20,9 @@ from typing import Dict, List, Optional, Tuple
|
|
|
20
20
|
|
|
21
21
|
from google.api_core.gapic_v1 import client_info
|
|
22
22
|
|
|
23
|
-
from google.cloud import documentai
|
|
23
|
+
from google.cloud import documentai # type: ignore[attr-defined]
|
|
24
|
+
from google.cloud import documentai_toolbox
|
|
25
|
+
from google.cloud import storage # type: ignore[attr-defined]
|
|
24
26
|
from google.cloud.documentai_toolbox import constants
|
|
25
27
|
|
|
26
28
|
|
|
@@ -91,6 +93,8 @@ def get_blobs(
|
|
|
91
93
|
if gcs_uri:
|
|
92
94
|
gcs_bucket_name, gcs_prefix = split_gcs_uri(gcs_uri)
|
|
93
95
|
|
|
96
|
+
if gcs_prefix is None:
|
|
97
|
+
raise TypeError("gcs_prefix cannot be None")
|
|
94
98
|
if re.match(constants.FILE_CHECK_REGEX, gcs_prefix):
|
|
95
99
|
raise ValueError("gcs_prefix cannot contain file types")
|
|
96
100
|
|
|
@@ -22,7 +22,7 @@ from functools import cached_property
|
|
|
22
22
|
import glob
|
|
23
23
|
import os
|
|
24
24
|
import re
|
|
25
|
-
from typing import Dict, Iterator, List, Optional, Type, Union
|
|
25
|
+
from typing import Any, Dict, Iterable, Iterator, List, Optional, Type, Union
|
|
26
26
|
|
|
27
27
|
from google.api_core.client_options import ClientOptions
|
|
28
28
|
from google.api_core.operation import from_gapic as operation_from_gapic
|
|
@@ -51,7 +51,7 @@ def _document_layout_blocks_from_shards(
|
|
|
51
51
|
shards: List[documentai.Document],
|
|
52
52
|
) -> Iterator[documentai.Document.DocumentLayout.DocumentLayoutBlock]:
|
|
53
53
|
def extract_blocks(
|
|
54
|
-
blocks:
|
|
54
|
+
blocks: Iterable[documentai.Document.DocumentLayout.DocumentLayoutBlock],
|
|
55
55
|
) -> Iterator[documentai.Document.DocumentLayout.DocumentLayoutBlock]:
|
|
56
56
|
queue = collections.deque(blocks)
|
|
57
57
|
|
|
@@ -325,8 +325,9 @@ def _dict_to_bigquery(
|
|
|
325
325
|
bq_client = bigquery.Client(
|
|
326
326
|
project=project_id, client_info=gcs_utilities._get_client_info()
|
|
327
327
|
)
|
|
328
|
+
resolved_project_id = project_id or bq_client.project
|
|
328
329
|
table_ref = bigquery.DatasetReference(
|
|
329
|
-
project=
|
|
330
|
+
project=resolved_project_id, dataset_id=dataset_name
|
|
330
331
|
).table(table_name)
|
|
331
332
|
|
|
332
333
|
job_config = bigquery.LoadJobConfig(
|
|
@@ -345,7 +346,7 @@ def _dict_to_bigquery(
|
|
|
345
346
|
|
|
346
347
|
|
|
347
348
|
def _apply_text_offset(
|
|
348
|
-
documentai_object: Union[Dict[str,
|
|
349
|
+
documentai_object: Union[Dict[str, Any], List[Any]], text_offset: int
|
|
349
350
|
) -> None:
|
|
350
351
|
r"""Applies a text offset to all text_segments in `documentai_object`.
|
|
351
352
|
|
|
@@ -63,7 +63,10 @@ class Entity:
|
|
|
63
63
|
|
|
64
64
|
_image: Optional[Image.Image] = dataclasses.field(init=False, default=None)
|
|
65
65
|
|
|
66
|
-
def __post_init__(self, page_offset: int) -> None:
|
|
66
|
+
def __post_init__(self, page_offset: Optional[int]) -> None:
|
|
67
|
+
if page_offset is None:
|
|
68
|
+
page_offset = 0
|
|
69
|
+
|
|
67
70
|
self.type_ = self.documentai_object.type_
|
|
68
71
|
|
|
69
72
|
if self.documentai_object.mention_text:
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
from abc import ABC
|
|
19
19
|
import dataclasses
|
|
20
20
|
from functools import cached_property
|
|
21
|
-
from typing import Iterable, List, Optional, Type
|
|
21
|
+
from typing import Iterable, List, Optional, Type, TypeVar
|
|
22
22
|
|
|
23
23
|
import pandas as pd
|
|
24
24
|
|
|
@@ -26,6 +26,8 @@ from google.cloud import documentai
|
|
|
26
26
|
from google.cloud.documentai_toolbox.constants import ElementWithLayout
|
|
27
27
|
from google.cloud.documentai_toolbox.utilities import docai_utilities
|
|
28
28
|
|
|
29
|
+
T = TypeVar("T", bound="_BasePageElement")
|
|
30
|
+
|
|
29
31
|
|
|
30
32
|
@dataclasses.dataclass
|
|
31
33
|
class Table:
|
|
@@ -180,9 +182,7 @@ class _BasePageElement(ABC):
|
|
|
180
182
|
"""
|
|
181
183
|
return self.documentai_object.layout.text_anchor.text_segments[0]
|
|
182
184
|
|
|
183
|
-
def _get_children_of_element(
|
|
184
|
-
self, potential_children: List["_BasePageElement"]
|
|
185
|
-
) -> List["_BasePageElement"]:
|
|
185
|
+
def _get_children_of_element(self, potential_children: List[T]) -> List[T]:
|
|
186
186
|
"""
|
|
187
187
|
Filters potential child elements to identify only those fully contained within this element.
|
|
188
188
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-cloud-documentai-toolbox
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.0
|
|
4
4
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-documentai-toolbox
|
|
5
5
|
Author: Google LLC
|
|
6
6
|
Author-email: googleapis-packages@google.com
|
|
File without changes
|
{google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/MANIFEST.in
RENAMED
|
File without changes
|
{google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/README.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{google_cloud_documentai_toolbox-0.15.2 → google_cloud_documentai_toolbox-0.16.0}/tests/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|