docling-core 2.40.0__py3-none-any.whl → 2.42.0__py3-none-any.whl
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.
Potentially problematic release.
This version of docling-core might be problematic. Click here for more details.
- docling_core/types/doc/base.py +29 -2
- docling_core/types/doc/document.py +1329 -161
- docling_core/types/doc/page.py +22 -2
- {docling_core-2.40.0.dist-info → docling_core-2.42.0.dist-info}/METADATA +1 -1
- {docling_core-2.40.0.dist-info → docling_core-2.42.0.dist-info}/RECORD +9 -9
- {docling_core-2.40.0.dist-info → docling_core-2.42.0.dist-info}/WHEEL +0 -0
- {docling_core-2.40.0.dist-info → docling_core-2.42.0.dist-info}/entry_points.txt +0 -0
- {docling_core-2.40.0.dist-info → docling_core-2.42.0.dist-info}/licenses/LICENSE +0 -0
- {docling_core-2.40.0.dist-info → docling_core-2.42.0.dist-info}/top_level.txt +0 -0
docling_core/types/doc/base.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""Models for the base data types."""
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import List, Tuple
|
|
4
|
+
from typing import Any, List, Tuple
|
|
5
5
|
|
|
6
|
-
from pydantic import BaseModel
|
|
6
|
+
from pydantic import BaseModel, FieldSerializationInfo, field_serializer
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class ImageRefMode(str, Enum):
|
|
@@ -21,12 +21,35 @@ class CoordOrigin(str, Enum):
|
|
|
21
21
|
BOTTOMLEFT = "BOTTOMLEFT"
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
class PydanticSerCtxKey(str, Enum):
|
|
25
|
+
"""Pydantic serialization context keys."""
|
|
26
|
+
|
|
27
|
+
COORD_PREC = "coord_prec" # key for coordinates precision
|
|
28
|
+
CONFID_PREC = "confid_prec" # key for confidence values precision
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def round_pydantic_float(
|
|
32
|
+
val: float, ctx: Any, precision_ctx_key: PydanticSerCtxKey
|
|
33
|
+
) -> float:
|
|
34
|
+
"""Round float, provided the precision is available in the context."""
|
|
35
|
+
precision = (
|
|
36
|
+
ctx.get(precision_ctx_key.value)
|
|
37
|
+
if isinstance(ctx, dict)
|
|
38
|
+
else getattr(ctx, precision_ctx_key.value, None)
|
|
39
|
+
)
|
|
40
|
+
return round(val, precision) if isinstance(precision, int) else val
|
|
41
|
+
|
|
42
|
+
|
|
24
43
|
class Size(BaseModel):
|
|
25
44
|
"""Size."""
|
|
26
45
|
|
|
27
46
|
width: float = 0.0
|
|
28
47
|
height: float = 0.0
|
|
29
48
|
|
|
49
|
+
@field_serializer("width", "height")
|
|
50
|
+
def _serialize(self, value: float, info: FieldSerializationInfo) -> float:
|
|
51
|
+
return round_pydantic_float(value, info.context, PydanticSerCtxKey.COORD_PREC)
|
|
52
|
+
|
|
30
53
|
def as_tuple(self):
|
|
31
54
|
"""as_tuple."""
|
|
32
55
|
return (self.width, self.height)
|
|
@@ -52,6 +75,10 @@ class BoundingBox(BaseModel):
|
|
|
52
75
|
"""height."""
|
|
53
76
|
return abs(self.t - self.b)
|
|
54
77
|
|
|
78
|
+
@field_serializer("l", "t", "r", "b")
|
|
79
|
+
def _serialize(self, value: float, info: FieldSerializationInfo) -> float:
|
|
80
|
+
return round_pydantic_float(value, info.context, PydanticSerCtxKey.COORD_PREC)
|
|
81
|
+
|
|
55
82
|
def resize_by_scale(self, x_scale: float, y_scale: float):
|
|
56
83
|
"""resize_by_scale."""
|
|
57
84
|
return BoundingBox(
|