deepdoctection 1.4.0__tar.gz → 1.5.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.
Files changed (59) hide show
  1. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/PKG-INFO +13 -12
  2. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/pyproject.toml +15 -14
  3. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/__init__.py +1 -1
  4. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/config.py +8 -0
  5. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/factory.py +4 -0
  6. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/conf_dd_one.yaml +1 -0
  7. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/accmetric.py +1 -1
  8. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/pdftext.py +1 -1
  9. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/order.py +61 -23
  10. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/segment.py +2 -2
  11. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/PKG-INFO +13 -12
  12. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/requires.txt +9 -9
  13. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/README.md +0 -0
  14. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/setup.cfg +0 -0
  15. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/__init__.py +0 -0
  16. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/analyzer/dd.py +0 -0
  17. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/__init__.py +0 -0
  18. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/conf_tesseract.yaml +0 -0
  19. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/configs/profiles.jsonl +0 -0
  20. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/__init__.py +0 -0
  21. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/base.py +0 -0
  22. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/cocometric.py +0 -0
  23. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/eval.py +0 -0
  24. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/record_align.py +0 -0
  25. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/registry.py +0 -0
  26. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/eval/tedsmetric.py +0 -0
  27. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/__init__.py +0 -0
  28. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/base.py +0 -0
  29. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/d2detect.py +0 -0
  30. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/deskew.py +0 -0
  31. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/doctrocr.py +0 -0
  32. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/hfdetr.py +0 -0
  33. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/hflayoutlm.py +0 -0
  34. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/hflm.py +0 -0
  35. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/model.py +0 -0
  36. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/tessocr.py +0 -0
  37. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/extern/texocr.py +0 -0
  38. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/__init__.py +0 -0
  39. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/anngen.py +0 -0
  40. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/base.py +0 -0
  41. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/common.py +0 -0
  42. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/concurrency.py +0 -0
  43. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/doctectionpipe.py +0 -0
  44. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/language.py +0 -0
  45. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/layout.py +0 -0
  46. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/lm.py +0 -0
  47. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/refine.py +0 -0
  48. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/registry.py +0 -0
  49. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/sub_layout.py +0 -0
  50. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/text.py +0 -0
  51. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/pipe/transform.py +0 -0
  52. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/py.typed +0 -0
  53. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/train/__init__.py +0 -0
  54. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/train/d2_frcnn_train.py +0 -0
  55. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/train/hf_detr_train.py +0 -0
  56. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection/train/hf_layoutlm_train.py +0 -0
  57. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/SOURCES.txt +0 -0
  58. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/dependency_links.txt +0 -0
  59. {deepdoctection-1.4.0 → deepdoctection-1.5.0}/src/deepdoctection.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deepdoctection
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: Repository for Document AI - server/inference core package
5
5
  Author: Dr. Janis Meyer
6
6
  License: Apache License 2.0
@@ -11,27 +11,28 @@ Classifier: Development Status :: 4 - Beta
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Natural Language :: English
13
13
  Classifier: Operating System :: POSIX :: Linux
14
- Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
17
18
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
- Requires-Python: >=3.10
19
+ Requires-Python: >=3.11
19
20
  Description-Content-Type: text/markdown
20
- Requires-Dist: dd-core[full]>=1.0.1
21
+ Requires-Dist: dd-core[full]>=1.5.0
21
22
  Requires-Dist: huggingface_hub>=1.0
22
23
  Provides-Extra: full
23
- Requires-Dist: dd-datasets[full]>=1.0.1; extra == "full"
24
- Requires-Dist: boto3==1.34.102; extra == "full"
24
+ Requires-Dist: dd-datasets[full]>=1.5.0; extra == "full"
25
+ Requires-Dist: boto3>=1.34.102; extra == "full"
25
26
  Requires-Dist: pdfplumber>=0.11.0; extra == "full"
26
27
  Requires-Dist: jdeskew>=0.2.2; extra == "full"
27
28
  Requires-Dist: networkx>=2.7.1; extra == "full"
28
29
  Requires-Dist: apted==1.0.3; extra == "full"
29
30
  Requires-Dist: distance==0.1.3; extra == "full"
30
- Requires-Dist: lxml>=4.9.1; extra == "full"
31
+ Requires-Dist: lxml>=6.1.0; extra == "full"
31
32
  Requires-Dist: pycocotools>=2.0.2; extra == "full"
32
33
  Requires-Dist: timm>=0.9.16; extra == "full"
33
- Requires-Dist: transformers>=5.2.0; extra == "full"
34
- Requires-Dist: accelerate>=0.29.1; extra == "full"
34
+ Requires-Dist: transformers>=5.10.0; extra == "full"
35
+ Requires-Dist: accelerate>=1.15.0; extra == "full"
35
36
  Requires-Dist: python-doctr>=1.0.0; extra == "full"
36
37
  Provides-Extra: types
37
38
  Requires-Dist: dd_core[types]; extra == "types"
@@ -39,7 +40,7 @@ Requires-Dist: lxml-stubs>=0.5.1; extra == "types"
39
40
  Provides-Extra: dev
40
41
  Requires-Dist: black==25.11.0; extra == "dev"
41
42
  Requires-Dist: isort==7.0.0; extra == "dev"
42
- Requires-Dist: pylint==4.0.2; extra == "dev"
43
+ Requires-Dist: pylint==4.0.9; extra == "dev"
43
44
  Requires-Dist: mypy==1.4.1; extra == "dev"
44
45
  Requires-Dist: types-PyYAML>=6.0.12.12; extra == "dev"
45
46
  Requires-Dist: types-termcolor>=1.1.3; extra == "dev"
@@ -49,10 +50,10 @@ Requires-Dist: types-Pillow>=10.2.0.20240406; extra == "dev"
49
50
  Requires-Dist: types-urllib3>=1.26.25.14; extra == "dev"
50
51
  Requires-Dist: lxml-stubs>=0.5.1; extra == "dev"
51
52
  Provides-Extra: test
52
- Requires-Dist: pytest==9.0.1; extra == "test"
53
+ Requires-Dist: pytest==9.0.3; extra == "test"
53
54
  Requires-Dist: pytest-cov; extra == "test"
54
55
  Provides-Extra: docs
55
- Requires-Dist: mkdocs-material==9.7.0; extra == "docs"
56
+ Requires-Dist: mkdocs-material==9.7.7; extra == "docs"
56
57
  Requires-Dist: mkdocstrings-python==1.19.0; extra == "docs"
57
58
  Requires-Dist: griffe==1.13; extra == "docs"
58
59
 
@@ -4,47 +4,48 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "deepdoctection"
7
- version = "1.4.0"
7
+ version = "1.5.0"
8
8
  authors = [
9
9
  {name = "Dr. Janis Meyer"}
10
10
  ]
11
11
  description = "Repository for Document AI - server/inference core package"
12
12
  readme = "README.md"
13
13
  license = {text = "Apache License 2.0"}
14
- requires-python = ">=3.10"
14
+ requires-python = ">=3.11"
15
15
  classifiers = [
16
16
  "Development Status :: 4 - Beta",
17
17
  "License :: OSI Approved :: Apache Software License",
18
18
  "Natural Language :: English",
19
19
  "Operating System :: POSIX :: Linux",
20
- "Programming Language :: Python :: 3.10",
21
20
  "Programming Language :: Python :: 3.11",
22
21
  "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
23
24
  "Topic :: Scientific/Engineering :: Artificial Intelligence",
24
25
  ]
25
26
 
26
27
  dependencies = [
27
- "dd-core[full]>=1.0.1",
28
+ "dd-core[full]>=1.5.0",
28
29
  "huggingface_hub>=1.0",
29
30
  ]
30
31
 
31
32
  [project.optional-dependencies]
32
33
  full = [
33
- "dd-datasets[full]>=1.0.1",
34
+ "dd-datasets[full]>=1.5.0",
34
35
  # Additional dependencies/ Non DL predictors
35
- "boto3==1.34.102",
36
+ "boto3>=1.34.102",
36
37
  "pdfplumber>=0.11.0",
37
38
  "jdeskew>=0.2.2",
38
39
  "networkx>=2.7.1",
39
40
  # Some libs for evals
40
41
  "apted==1.0.3",
41
42
  "distance==0.1.3",
42
- "lxml>=4.9.1",
43
+ "lxml>=6.1.0",
43
44
  "pycocotools>=2.0.2",
44
45
  # DL dependencies
45
46
  "timm>=0.9.16",
46
- "transformers>=5.2.0",
47
- "accelerate>=0.29.1",
47
+ "transformers>=5.10.0",
48
+ "accelerate>=1.15.0",
48
49
  "python-doctr>=1.0.0",
49
50
  ]
50
51
 
@@ -56,7 +57,7 @@ types = [
56
57
  dev = [
57
58
  "black==25.11.0",
58
59
  "isort==7.0.0",
59
- "pylint==4.0.2",
60
+ "pylint==4.0.9",
60
61
  "mypy==1.4.1",
61
62
  "types-PyYAML>=6.0.12.12",
62
63
  "types-termcolor>=1.1.3",
@@ -68,12 +69,12 @@ dev = [
68
69
  ]
69
70
 
70
71
  test = [
71
- "pytest==9.0.1",
72
+ "pytest==9.0.3",
72
73
  "pytest-cov",
73
74
  ]
74
75
 
75
76
  docs = [
76
- "mkdocs-material==9.7.0",
77
+ "mkdocs-material==9.7.7",
77
78
  "mkdocstrings-python==1.19.0",
78
79
  "griffe==1.13"
79
80
  ]
@@ -94,14 +95,14 @@ deepdoctection = ["py.typed", "configs/*.yaml", "configs/*.jsonl"]
94
95
 
95
96
  [tool.black]
96
97
  line-length = 120
97
- target-version = ['py310']
98
+ target-version = ['py311']
98
99
 
99
100
  [tool.isort]
100
101
  profile = "black"
101
102
  line_length = 120
102
103
 
103
104
  [tool.mypy]
104
- python_version = "3.10"
105
+ python_version = "3.11"
105
106
  warn_return_any = true
106
107
  warn_unused_configs = true
107
108
  ignore_missing_imports = true
@@ -12,7 +12,7 @@ from dd_core.utils.env_info import collect_env_info
12
12
  from dd_core.utils.file_utils import _LazyModule
13
13
  from dd_core.utils.logger import LoggingRecord, logger
14
14
 
15
- __version__ = "1.4.0"
15
+ __version__ = "1.5.0"
16
16
  _IMPORT_STRUCTURE = {
17
17
  "analyzer": ["config_sanity_checks", "get_dd_analyzer", "ServiceFactory", "update_cfg_from_defaults"],
18
18
  "eval": [
@@ -404,6 +404,10 @@ The following weights configure each stage for TensorFlow and PyTorch.
404
404
  Defines the spacing threshold that indicates a paragraph break in vertically
405
405
  arranged text blocks. Helps determine reading order in multi-column, broken layouts.
406
406
 
407
+ TEXT_ORDERING.RIGHT_TO_LEFT:
408
+ If set to True, words within a line and columns lying next to each other are read from right to left
409
+ (e.g. for Hebrew or Arabic documents). Lines and text blocks are still read from top to bottom.
410
+
407
411
  ---
408
412
  ## Layout Linking Configuration
409
413
 
@@ -834,6 +838,10 @@ cfg.TEXT_ORDERING.HEIGHT_TOLERANCE = 2.0
834
838
  # Helps determine reading order in multi-column, broken layouts.
835
839
  cfg.TEXT_ORDERING.PARAGRAPH_BREAK = 0.035
836
840
 
841
+ # If set to True, words within a line and columns lying next to each other are read from right to left
842
+ # (e.g. for Hebrew or Arabic documents). Lines and text blocks are still read from top to bottom.
843
+ cfg.TEXT_ORDERING.RIGHT_TO_LEFT = False
844
+
837
845
  # Configuration for linking spatially related layout sections
838
846
  # (e.g., associating figures with their captions) based on proximity.
839
847
  # The distance is calculated using the center points of the layout elements.
@@ -1194,6 +1194,7 @@ class ServiceFactory:
1194
1194
  "broken_line_tolerance": config.TEXT_ORDERING.BROKEN_LINE_TOLERANCE,
1195
1195
  "height_tolerance": config.TEXT_ORDERING.HEIGHT_TOLERANCE,
1196
1196
  "paragraph_break": config.TEXT_ORDERING.PARAGRAPH_BREAK,
1197
+ "right_to_left": config.TEXT_ORDERING.RIGHT_TO_LEFT,
1197
1198
  }
1198
1199
 
1199
1200
  @staticmethod
@@ -1206,6 +1207,7 @@ class ServiceFactory:
1206
1207
  broken_line_tolerance: float,
1207
1208
  height_tolerance: float,
1208
1209
  paragraph_break: float,
1210
+ right_to_left: bool = False,
1209
1211
  ) -> TextOrderService:
1210
1212
  """
1211
1213
  Building a text order service.
@@ -1219,6 +1221,7 @@ class ServiceFactory:
1219
1221
  broken_line_tolerance: Broken line tolerance for text ordering.
1220
1222
  height_tolerance: Height tolerance for text ordering.
1221
1223
  paragraph_break: Paragraph break threshold.
1224
+ right_to_left: Whether words within a line and neighbouring columns are read from right to left.
1222
1225
 
1223
1226
  Returns:
1224
1227
  TextOrderService: Text order service instance.
@@ -1232,6 +1235,7 @@ class ServiceFactory:
1232
1235
  broken_line_tolerance=broken_line_tolerance,
1233
1236
  height_tolerance=height_tolerance,
1234
1237
  paragraph_break=paragraph_break,
1238
+ right_to_left=right_to_left,
1235
1239
  )
1236
1240
 
1237
1241
  @staticmethod
@@ -153,6 +153,7 @@ TEXT_ORDERING:
153
153
  HEIGHT_TOLERANCE: 2.0
154
154
  INCLUDE_RESIDUAL_TEXT_CONTAINER: true
155
155
  PARAGRAPH_BREAK: 0.035
156
+ RIGHT_TO_LEFT: false
156
157
  STARTING_POINT_TOLERANCE: 0.005
157
158
  TEXT_BLOCK_CATEGORIES:
158
159
  - text
@@ -220,7 +220,7 @@ def f1_score(
220
220
  f_1 = 2 * np_precision * np_recall / (np_precision + np_recall)
221
221
  if per_label:
222
222
  return f_1
223
- return np.average(f_1) # type: ignore
223
+ return np.average(f_1)
224
224
 
225
225
 
226
226
  class ClassificationMetric(MetricBase):
@@ -189,7 +189,7 @@ class Pdfmium2TextDetector(PdfMiner):
189
189
  words = []
190
190
  height = page.get_height()
191
191
  for obj in page.get_objects((pypdfium_c.FPDF_PAGEOBJ_TEXT,)):
192
- box = obj.get_pos()
192
+ box = obj.get_bounds()
193
193
  if all(x > 0 for x in box):
194
194
  words.append(
195
195
  {
@@ -51,7 +51,13 @@ class OrderGenerator:
51
51
  (by detecting gaps between words), as well as ordering text blocks (e.g., titles, tables, etc.).
52
52
  """
53
53
 
54
- def __init__(self, starting_point_tolerance: float, broken_line_tolerance: float, height_tolerance: float):
54
+ def __init__(
55
+ self,
56
+ starting_point_tolerance: float,
57
+ broken_line_tolerance: float,
58
+ height_tolerance: float,
59
+ right_to_left: bool = False,
60
+ ):
55
61
  """
56
62
  Args:
57
63
  starting_point_tolerance: Threshold to identify if two text blocks belong to one column. To check if two
@@ -61,16 +67,19 @@ class OrderGenerator:
61
67
  different sub-lines (because they belong to two different text columns).
62
68
  height_tolerance: Threshold to identify if two columns lying over each other belong together or need to be
63
69
  separated. Scaling factor of relative text block height.
70
+ right_to_left: If `True`, words within a line and columns lying next to each other are read from right to
71
+ left (e.g. for Hebrew or Arabic). Lines and blocks are still read from top to bottom.
64
72
  """
65
73
  self.starting_point_tolerance = starting_point_tolerance
66
74
  self.broken_line_tolerance = broken_line_tolerance
67
75
  self.height_tolerance = height_tolerance
76
+ self.right_to_left = right_to_left
68
77
  self.ioa_column_threshold = 0.9
69
78
  self.columns_detect_result: Optional[Sequence[DetectionResult]] = None
70
79
 
71
80
  @staticmethod
72
81
  def group_words_into_lines(
73
- word_anns: Sequence[ImageAnnotation], image_id: Optional[str] = None
82
+ word_anns: Sequence[ImageAnnotation], image_id: Optional[str] = None, right_to_left: bool = False
74
83
  ) -> list[tuple[int, int, str]]:
75
84
  """
76
85
  Arranges words into horizontal text lines and sorts text lines vertically to provide an enumeration of words
@@ -87,6 +96,7 @@ class OrderGenerator:
87
96
  Args:
88
97
  word_anns: Sequence of `ImageAnnotation` representing words.
89
98
  image_id: Optional image ID.
99
+ right_to_left: If `True`, words within a line are read from right to left.
90
100
 
91
101
  Returns:
92
102
  List of triplets for every word annotation: (word reading order position, text line position, word
@@ -120,7 +130,7 @@ class OrderGenerator:
120
130
  idx: key[0] # type:ignore
121
131
  for idx, key in enumerate(sorted(rows_dict.items(), key=lambda it: it[1]["upper"]))
122
132
  }
123
- reading_lines.sort(key=lambda x: (rows_dict[x[0]], x[2]))
133
+ reading_lines.sort(key=lambda x: (rows_dict[x[0]], -x[2] if right_to_left else x[2]))
124
134
  number_rows = len(rows_dict)
125
135
  if logger.isEnabledFor(DEBUG):
126
136
  logger.debug(
@@ -162,7 +172,7 @@ class OrderGenerator:
162
172
  return [(idx + 1, idx + 1, line[1]) for idx, line in enumerate(reading_lines)]
163
173
 
164
174
  @staticmethod
165
- def _connected_components(columns: list[BoundingBox]) -> list[dict[str, Any]]:
175
+ def _connected_components(columns: list[BoundingBox], right_to_left: bool = False) -> list[dict[str, Any]]:
166
176
  # building connected components of columns
167
177
  connected_components: list[dict[str, Any]] = []
168
178
  for idx, col in enumerate(columns):
@@ -184,16 +194,26 @@ class OrderGenerator:
184
194
  if not component_found:
185
195
  connected_components.append({"top": col.uly, "bottom": col.lry, "left": col.ulx, "column": [col_dict]})
186
196
 
187
- # next, sorting columns in connected components by increasing x-value. In order to be tolerant to
188
- # nearby values we are rounding values we want to sort
197
+ # next, sorting columns in connected components by increasing x-value (or by decreasing right x-value for
198
+ # right-to-left reading order). In order to be tolerant to nearby values we are rounding values we want to
199
+ # sort
189
200
  for comp in connected_components:
190
201
  for column in comp["column"]:
191
202
  column["box"].ulx = round(column["box"].ulx, 2)
192
203
  column["box"].uly = round(column["box"].uly, 2)
193
- comp["column"].sort(key=lambda x: (x["box"].ulx, x["box"].uly))
194
-
195
- # finally, sorting connected components by increasing y-value
196
- connected_components.sort(key=lambda x: x["top"])
204
+ if right_to_left:
205
+ comp["column"].sort(key=lambda x: (-round(x["box"].lrx, 2), x["box"].uly))
206
+ else:
207
+ comp["column"].sort(key=lambda x: (x["box"].ulx, x["box"].uly))
208
+
209
+ # finally, sorting connected components by increasing y-value. For right-to-left reading order,
210
+ # components starting at the same height are sorted by decreasing right x-value.
211
+ if right_to_left:
212
+ connected_components.sort(
213
+ key=lambda x: (x["top"], -max(round(column["box"].lrx, 2) for column in x["column"]))
214
+ )
215
+ else:
216
+ connected_components.sort(key=lambda x: x["top"])
197
217
  if logger.isEnabledFor(DEBUG):
198
218
  logger.debug(LoggingRecord("_connected_components", {"connected_components": str(connected_components)}))
199
219
  return connected_components
@@ -299,7 +319,7 @@ class OrderGenerator:
299
319
 
300
320
  reading_blocks = [(consoldiated_cols.get(x[0], x[0]), x[1]) for x in reading_blocks]
301
321
 
302
- connected_components = self._connected_components(consolidated_columns)
322
+ connected_components = self._connected_components(consolidated_columns, self.right_to_left)
303
323
  columns_box = list(chain(*[comp["column"] for comp in connected_components]))
304
324
 
305
325
  # old to new mapping
@@ -312,7 +332,9 @@ class OrderGenerator:
312
332
  for idx in range(max_block_number + 1):
313
333
  filtered_blocks = list(filter(lambda x: x[0] == idx, blocks)) # type: ignore # pylint: disable=W0640
314
334
  sorted_blocks.extend(
315
- self._sort_anns_grouped_by_blocks(filtered_blocks, anns, image_width, image_height, image_id)
335
+ self._sort_anns_grouped_by_blocks(
336
+ filtered_blocks, anns, image_width, image_height, image_id, self.right_to_left
337
+ )
316
338
  )
317
339
  reading_blocks = [(idx + 1, block[1]) for idx, block in enumerate(sorted_blocks)]
318
340
 
@@ -337,15 +359,14 @@ class OrderGenerator:
337
359
  np.fill_diagonal(ioa_matrix, 0)
338
360
  output = ioa_matrix > self.ioa_column_threshold
339
361
  child_index, parent_index = output.nonzero()
340
- column_dict = dict(zip(child_index, parent_index))
341
- column_dict = {int(key): int(val) for key, val in column_dict.items()}
362
+ column_dict = {int(key): int(val) for key, val in zip(child_index, parent_index)}
342
363
  counter = 0
343
364
  for idx, _ in enumerate(columns):
344
365
  if idx not in column_dict:
345
366
  column_dict[idx] = counter
346
367
  counter += 1
347
368
  if logger.isEnabledFor(DEBUG):
348
- logger.debug(LoggingRecord("consolidated columns", copy(column_dict)))
369
+ logger.debug(LoggingRecord("consolidated columns", {"columns": copy(column_dict)}))
349
370
  return column_dict
350
371
 
351
372
  @staticmethod
@@ -355,6 +376,7 @@ class OrderGenerator:
355
376
  image_width: float,
356
377
  image_height: float,
357
378
  image_id: Optional[str] = None,
379
+ right_to_left: bool = False,
358
380
  ) -> list[tuple[int, str]]:
359
381
  if not block:
360
382
  return []
@@ -362,12 +384,20 @@ class OrderGenerator:
362
384
  ann_ids = anns_and_blocks_numbers[1]
363
385
  block_number = anns_and_blocks_numbers[0][0]
364
386
  block_anns = [ann for ann in anns if ann.annotation_id in ann_ids]
365
- block_anns.sort(
366
- key=lambda x: (
367
- round(x.get_bounding_box(image_id).transform(image_width, image_height).uly, 2),
368
- round(x.get_bounding_box(image_id).transform(image_width, image_height).ulx, 2),
387
+ if right_to_left:
388
+ block_anns.sort(
389
+ key=lambda x: (
390
+ round(x.get_bounding_box(image_id).transform(image_width, image_height).uly, 2),
391
+ -round(x.get_bounding_box(image_id).transform(image_width, image_height).lrx, 2),
392
+ )
393
+ )
394
+ else:
395
+ block_anns.sort(
396
+ key=lambda x: (
397
+ round(x.get_bounding_box(image_id).transform(image_width, image_height).uly, 2),
398
+ round(x.get_bounding_box(image_id).transform(image_width, image_height).ulx, 2),
399
+ )
369
400
  )
370
- )
371
401
  return [(block_number, ann.annotation_id) for ann in block_anns]
372
402
 
373
403
  @staticmethod
@@ -637,7 +667,9 @@ class TextOrderService(TextLineServiceMixin):
637
667
  belong to floating text that encircle a table. They are rather an element that is supposed to be read independently.
638
668
 
639
669
  A heuristic argument for its ordering is used where the underlying assumption is the reading order from left
640
- to right.
670
+ to right. For scripts that are read from right to left (e.g. Hebrew or Arabic), set `right_to_left=True`: words
671
+ within a line and columns lying next to each other are then ordered from right to left, while lines and blocks
672
+ are still read from top to bottom.
641
673
 
642
674
  - For the reading order within a text block, text containers (i.e., image annotations that contain character
643
675
  sub-annotations) are sorted based on their bounding box center and then lines are formed: Each word induces a new
@@ -681,6 +713,7 @@ class TextOrderService(TextLineServiceMixin):
681
713
  broken_line_tolerance: float = 0.003,
682
714
  height_tolerance: float = 2.0,
683
715
  paragraph_break: Optional[float] = 0.035,
716
+ right_to_left: bool = False,
684
717
  ):
685
718
  """
686
719
  Args:
@@ -708,6 +741,8 @@ class TextOrderService(TextLineServiceMixin):
708
741
  separated. Scaling factor of relative text block height.
709
742
  paragraph_break: Threshold of two consecutive words. If distance is larger than threshold, two sublines
710
743
  will be built.
744
+ right_to_left: If `True`, words within a line and columns lying next to each other are read from right
745
+ to left (e.g. for Hebrew or Arabic). Defaults to `False` (left to right).
711
746
  """
712
747
  self.text_container = get_type(text_container)
713
748
  if isinstance(text_block_categories, (str, ObjectTypes)):
@@ -723,7 +758,9 @@ class TextOrderService(TextLineServiceMixin):
723
758
  if include_residual_text_container:
724
759
  self.floating_text_block_categories = self.floating_text_block_categories + (LayoutLabel.LINE,)
725
760
  self.include_residual_text_container = include_residual_text_container
726
- self.order_generator = OrderGenerator(starting_point_tolerance, broken_line_tolerance, height_tolerance)
761
+ self.order_generator = OrderGenerator(
762
+ starting_point_tolerance, broken_line_tolerance, height_tolerance, right_to_left
763
+ )
727
764
  self.text_line_generator = TextLineGenerator(self.include_residual_text_container, paragraph_break)
728
765
  super().__init__(
729
766
  name="text_order",
@@ -777,7 +814,7 @@ class TextOrderService(TextLineServiceMixin):
777
814
  )
778
815
  if self.text_container == LayoutLabel.WORD:
779
816
  word_order_list = self.order_generator.group_words_into_lines(
780
- text_container_ann, self.dp_manager.datapoint.image_id
817
+ text_container_ann, self.dp_manager.datapoint.image_id, self.order_generator.right_to_left
781
818
  )
782
819
  else:
783
820
  word_order_list = self.order_generator.group_lines_into_lines(
@@ -847,6 +884,7 @@ class TextOrderService(TextLineServiceMixin):
847
884
  self.order_generator.broken_line_tolerance,
848
885
  self.order_generator.height_tolerance,
849
886
  self.text_line_generator.paragraph_break,
887
+ self.order_generator.right_to_left,
850
888
  )
851
889
 
852
890
  def clear_predictor(self) -> None:
@@ -555,7 +555,7 @@ def segment_table(
555
555
  for idx, cell in enumerate(cells):
556
556
  cell_positions_rows = cell_index_rows == idx
557
557
  rows_of_cell = [rows[k] for k in row_index[cell_positions_rows]]
558
- rs = np.count_nonzero(cell_index_rows == idx)
558
+ rs = int(np.count_nonzero(cell_index_rows == idx))
559
559
  if len(rows_of_cell):
560
560
  row_number = min(row.get_sub_category(CellKey.ROW_NUMBER).category_id for row in rows_of_cell)
561
561
  else:
@@ -563,7 +563,7 @@ def segment_table(
563
563
 
564
564
  cell_positions_cols = cell_index_cols == idx
565
565
  cols_of_cell = [columns[k] for k in col_index[cell_positions_cols]]
566
- cs = np.count_nonzero(cell_index_cols == idx)
566
+ cs = int(np.count_nonzero(cell_index_cols == idx))
567
567
  if len(cols_of_cell):
568
568
  col_number = min(col.get_sub_category(CellKey.COLUMN_NUMBER).category_id for col in cols_of_cell)
569
569
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deepdoctection
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: Repository for Document AI - server/inference core package
5
5
  Author: Dr. Janis Meyer
6
6
  License: Apache License 2.0
@@ -11,27 +11,28 @@ Classifier: Development Status :: 4 - Beta
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Natural Language :: English
13
13
  Classifier: Operating System :: POSIX :: Linux
14
- Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
17
18
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
- Requires-Python: >=3.10
19
+ Requires-Python: >=3.11
19
20
  Description-Content-Type: text/markdown
20
- Requires-Dist: dd-core[full]>=1.0.1
21
+ Requires-Dist: dd-core[full]>=1.5.0
21
22
  Requires-Dist: huggingface_hub>=1.0
22
23
  Provides-Extra: full
23
- Requires-Dist: dd-datasets[full]>=1.0.1; extra == "full"
24
- Requires-Dist: boto3==1.34.102; extra == "full"
24
+ Requires-Dist: dd-datasets[full]>=1.5.0; extra == "full"
25
+ Requires-Dist: boto3>=1.34.102; extra == "full"
25
26
  Requires-Dist: pdfplumber>=0.11.0; extra == "full"
26
27
  Requires-Dist: jdeskew>=0.2.2; extra == "full"
27
28
  Requires-Dist: networkx>=2.7.1; extra == "full"
28
29
  Requires-Dist: apted==1.0.3; extra == "full"
29
30
  Requires-Dist: distance==0.1.3; extra == "full"
30
- Requires-Dist: lxml>=4.9.1; extra == "full"
31
+ Requires-Dist: lxml>=6.1.0; extra == "full"
31
32
  Requires-Dist: pycocotools>=2.0.2; extra == "full"
32
33
  Requires-Dist: timm>=0.9.16; extra == "full"
33
- Requires-Dist: transformers>=5.2.0; extra == "full"
34
- Requires-Dist: accelerate>=0.29.1; extra == "full"
34
+ Requires-Dist: transformers>=5.10.0; extra == "full"
35
+ Requires-Dist: accelerate>=1.15.0; extra == "full"
35
36
  Requires-Dist: python-doctr>=1.0.0; extra == "full"
36
37
  Provides-Extra: types
37
38
  Requires-Dist: dd_core[types]; extra == "types"
@@ -39,7 +40,7 @@ Requires-Dist: lxml-stubs>=0.5.1; extra == "types"
39
40
  Provides-Extra: dev
40
41
  Requires-Dist: black==25.11.0; extra == "dev"
41
42
  Requires-Dist: isort==7.0.0; extra == "dev"
42
- Requires-Dist: pylint==4.0.2; extra == "dev"
43
+ Requires-Dist: pylint==4.0.9; extra == "dev"
43
44
  Requires-Dist: mypy==1.4.1; extra == "dev"
44
45
  Requires-Dist: types-PyYAML>=6.0.12.12; extra == "dev"
45
46
  Requires-Dist: types-termcolor>=1.1.3; extra == "dev"
@@ -49,10 +50,10 @@ Requires-Dist: types-Pillow>=10.2.0.20240406; extra == "dev"
49
50
  Requires-Dist: types-urllib3>=1.26.25.14; extra == "dev"
50
51
  Requires-Dist: lxml-stubs>=0.5.1; extra == "dev"
51
52
  Provides-Extra: test
52
- Requires-Dist: pytest==9.0.1; extra == "test"
53
+ Requires-Dist: pytest==9.0.3; extra == "test"
53
54
  Requires-Dist: pytest-cov; extra == "test"
54
55
  Provides-Extra: docs
55
- Requires-Dist: mkdocs-material==9.7.0; extra == "docs"
56
+ Requires-Dist: mkdocs-material==9.7.7; extra == "docs"
56
57
  Requires-Dist: mkdocstrings-python==1.19.0; extra == "docs"
57
58
  Requires-Dist: griffe==1.13; extra == "docs"
58
59
 
@@ -1,10 +1,10 @@
1
- dd-core[full]>=1.0.1
1
+ dd-core[full]>=1.5.0
2
2
  huggingface_hub>=1.0
3
3
 
4
4
  [dev]
5
5
  black==25.11.0
6
6
  isort==7.0.0
7
- pylint==4.0.2
7
+ pylint==4.0.9
8
8
  mypy==1.4.1
9
9
  types-PyYAML>=6.0.12.12
10
10
  types-termcolor>=1.1.3
@@ -15,27 +15,27 @@ types-urllib3>=1.26.25.14
15
15
  lxml-stubs>=0.5.1
16
16
 
17
17
  [docs]
18
- mkdocs-material==9.7.0
18
+ mkdocs-material==9.7.7
19
19
  mkdocstrings-python==1.19.0
20
20
  griffe==1.13
21
21
 
22
22
  [full]
23
- dd-datasets[full]>=1.0.1
24
- boto3==1.34.102
23
+ dd-datasets[full]>=1.5.0
24
+ boto3>=1.34.102
25
25
  pdfplumber>=0.11.0
26
26
  jdeskew>=0.2.2
27
27
  networkx>=2.7.1
28
28
  apted==1.0.3
29
29
  distance==0.1.3
30
- lxml>=4.9.1
30
+ lxml>=6.1.0
31
31
  pycocotools>=2.0.2
32
32
  timm>=0.9.16
33
- transformers>=5.2.0
34
- accelerate>=0.29.1
33
+ transformers>=5.10.0
34
+ accelerate>=1.15.0
35
35
  python-doctr>=1.0.0
36
36
 
37
37
  [test]
38
- pytest==9.0.1
38
+ pytest==9.0.3
39
39
  pytest-cov
40
40
 
41
41
  [types]
File without changes
File without changes