kreuzberg 4.0.0.pre.rc.29 → 4.0.0.rc1

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 (321) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.rubocop.yaml +534 -1
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +28 -116
  6. data/README.md +269 -629
  7. data/Rakefile +0 -9
  8. data/Steepfile +4 -8
  9. data/examples/async_patterns.rb +58 -1
  10. data/ext/kreuzberg_rb/extconf.rb +5 -35
  11. data/ext/kreuzberg_rb/native/Cargo.toml +16 -55
  12. data/ext/kreuzberg_rb/native/build.rs +14 -12
  13. data/ext/kreuzberg_rb/native/include/ieeefp.h +1 -1
  14. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +1 -1
  15. data/ext/kreuzberg_rb/native/include/strings.h +2 -2
  16. data/ext/kreuzberg_rb/native/include/unistd.h +1 -1
  17. data/ext/kreuzberg_rb/native/src/lib.rs +34 -897
  18. data/extconf.rb +6 -38
  19. data/kreuzberg.gemspec +20 -114
  20. data/lib/kreuzberg/api_proxy.rb +18 -2
  21. data/lib/kreuzberg/cache_api.rb +0 -22
  22. data/lib/kreuzberg/cli.rb +10 -2
  23. data/lib/kreuzberg/cli_proxy.rb +10 -0
  24. data/lib/kreuzberg/config.rb +22 -274
  25. data/lib/kreuzberg/errors.rb +7 -73
  26. data/lib/kreuzberg/extraction_api.rb +8 -237
  27. data/lib/kreuzberg/mcp_proxy.rb +11 -2
  28. data/lib/kreuzberg/ocr_backend_protocol.rb +73 -0
  29. data/lib/kreuzberg/post_processor_protocol.rb +71 -0
  30. data/lib/kreuzberg/result.rb +33 -151
  31. data/lib/kreuzberg/setup_lib_path.rb +2 -22
  32. data/lib/kreuzberg/validator_protocol.rb +73 -0
  33. data/lib/kreuzberg/version.rb +1 -1
  34. data/lib/kreuzberg.rb +13 -27
  35. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  36. data/sig/kreuzberg.rbs +12 -105
  37. data/spec/binding/cache_spec.rb +22 -22
  38. data/spec/binding/cli_proxy_spec.rb +4 -2
  39. data/spec/binding/cli_spec.rb +11 -12
  40. data/spec/binding/config_spec.rb +0 -74
  41. data/spec/binding/config_validation_spec.rb +6 -100
  42. data/spec/binding/error_handling_spec.rb +97 -283
  43. data/spec/binding/plugins/ocr_backend_spec.rb +8 -8
  44. data/spec/binding/plugins/postprocessor_spec.rb +11 -11
  45. data/spec/binding/plugins/validator_spec.rb +13 -12
  46. data/spec/examples.txt +104 -0
  47. data/spec/fixtures/config.toml +1 -0
  48. data/spec/fixtures/config.yaml +1 -0
  49. data/spec/fixtures/invalid_config.toml +1 -0
  50. data/spec/smoke/package_spec.rb +3 -2
  51. data/spec/spec_helper.rb +3 -1
  52. data/vendor/kreuzberg/Cargo.toml +67 -192
  53. data/vendor/kreuzberg/README.md +9 -97
  54. data/vendor/kreuzberg/build.rs +194 -516
  55. data/vendor/kreuzberg/src/api/handlers.rs +9 -130
  56. data/vendor/kreuzberg/src/api/mod.rs +3 -18
  57. data/vendor/kreuzberg/src/api/server.rs +71 -236
  58. data/vendor/kreuzberg/src/api/types.rs +7 -43
  59. data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
  60. data/vendor/kreuzberg/src/cache/mod.rs +3 -27
  61. data/vendor/kreuzberg/src/chunking/mod.rs +79 -1705
  62. data/vendor/kreuzberg/src/core/batch_mode.rs +0 -60
  63. data/vendor/kreuzberg/src/core/config.rs +23 -905
  64. data/vendor/kreuzberg/src/core/extractor.rs +106 -403
  65. data/vendor/kreuzberg/src/core/io.rs +2 -4
  66. data/vendor/kreuzberg/src/core/mime.rs +12 -2
  67. data/vendor/kreuzberg/src/core/mod.rs +3 -22
  68. data/vendor/kreuzberg/src/core/pipeline.rs +78 -395
  69. data/vendor/kreuzberg/src/embeddings.rs +21 -169
  70. data/vendor/kreuzberg/src/error.rs +2 -2
  71. data/vendor/kreuzberg/src/extraction/archive.rs +31 -36
  72. data/vendor/kreuzberg/src/extraction/docx.rs +1 -365
  73. data/vendor/kreuzberg/src/extraction/email.rs +11 -12
  74. data/vendor/kreuzberg/src/extraction/excel.rs +129 -138
  75. data/vendor/kreuzberg/src/extraction/html.rs +170 -1447
  76. data/vendor/kreuzberg/src/extraction/image.rs +14 -138
  77. data/vendor/kreuzberg/src/extraction/libreoffice.rs +3 -13
  78. data/vendor/kreuzberg/src/extraction/mod.rs +5 -21
  79. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +0 -2
  80. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
  81. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
  82. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
  83. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
  84. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
  85. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
  86. data/vendor/kreuzberg/src/extraction/pptx.rs +94 -196
  87. data/vendor/kreuzberg/src/extraction/structured.rs +4 -5
  88. data/vendor/kreuzberg/src/extraction/table.rs +1 -2
  89. data/vendor/kreuzberg/src/extraction/text.rs +10 -18
  90. data/vendor/kreuzberg/src/extractors/archive.rs +0 -22
  91. data/vendor/kreuzberg/src/extractors/docx.rs +148 -69
  92. data/vendor/kreuzberg/src/extractors/email.rs +9 -37
  93. data/vendor/kreuzberg/src/extractors/excel.rs +40 -81
  94. data/vendor/kreuzberg/src/extractors/html.rs +173 -182
  95. data/vendor/kreuzberg/src/extractors/image.rs +8 -32
  96. data/vendor/kreuzberg/src/extractors/mod.rs +10 -171
  97. data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
  98. data/vendor/kreuzberg/src/extractors/pdf.rs +64 -329
  99. data/vendor/kreuzberg/src/extractors/pptx.rs +34 -79
  100. data/vendor/kreuzberg/src/extractors/structured.rs +0 -16
  101. data/vendor/kreuzberg/src/extractors/text.rs +7 -30
  102. data/vendor/kreuzberg/src/extractors/xml.rs +8 -27
  103. data/vendor/kreuzberg/src/keywords/processor.rs +1 -9
  104. data/vendor/kreuzberg/src/keywords/rake.rs +1 -0
  105. data/vendor/kreuzberg/src/language_detection/mod.rs +51 -94
  106. data/vendor/kreuzberg/src/lib.rs +5 -17
  107. data/vendor/kreuzberg/src/mcp/mod.rs +1 -4
  108. data/vendor/kreuzberg/src/mcp/server.rs +21 -145
  109. data/vendor/kreuzberg/src/ocr/mod.rs +0 -2
  110. data/vendor/kreuzberg/src/ocr/processor.rs +8 -19
  111. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +0 -2
  112. data/vendor/kreuzberg/src/pdf/error.rs +1 -93
  113. data/vendor/kreuzberg/src/pdf/metadata.rs +100 -263
  114. data/vendor/kreuzberg/src/pdf/mod.rs +2 -33
  115. data/vendor/kreuzberg/src/pdf/rendering.rs +12 -12
  116. data/vendor/kreuzberg/src/pdf/table.rs +64 -61
  117. data/vendor/kreuzberg/src/pdf/text.rs +24 -416
  118. data/vendor/kreuzberg/src/plugins/extractor.rs +8 -40
  119. data/vendor/kreuzberg/src/plugins/mod.rs +0 -3
  120. data/vendor/kreuzberg/src/plugins/ocr.rs +14 -22
  121. data/vendor/kreuzberg/src/plugins/processor.rs +1 -10
  122. data/vendor/kreuzberg/src/plugins/registry.rs +0 -15
  123. data/vendor/kreuzberg/src/plugins/validator.rs +8 -20
  124. data/vendor/kreuzberg/src/stopwords/mod.rs +2 -2
  125. data/vendor/kreuzberg/src/text/mod.rs +0 -8
  126. data/vendor/kreuzberg/src/text/quality.rs +15 -28
  127. data/vendor/kreuzberg/src/text/string_utils.rs +10 -22
  128. data/vendor/kreuzberg/src/text/token_reduction/core.rs +50 -86
  129. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +16 -37
  130. data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +1 -2
  131. data/vendor/kreuzberg/src/types.rs +67 -907
  132. data/vendor/kreuzberg/src/utils/mod.rs +0 -14
  133. data/vendor/kreuzberg/src/utils/quality.rs +3 -12
  134. data/vendor/kreuzberg/tests/api_tests.rs +0 -506
  135. data/vendor/kreuzberg/tests/archive_integration.rs +0 -2
  136. data/vendor/kreuzberg/tests/batch_orchestration.rs +12 -57
  137. data/vendor/kreuzberg/tests/batch_processing.rs +8 -32
  138. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
  139. data/vendor/kreuzberg/tests/concurrency_stress.rs +8 -40
  140. data/vendor/kreuzberg/tests/config_features.rs +1 -33
  141. data/vendor/kreuzberg/tests/config_loading_tests.rs +39 -16
  142. data/vendor/kreuzberg/tests/core_integration.rs +9 -35
  143. data/vendor/kreuzberg/tests/csv_integration.rs +81 -71
  144. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +25 -23
  145. data/vendor/kreuzberg/tests/email_integration.rs +1 -3
  146. data/vendor/kreuzberg/tests/error_handling.rs +34 -43
  147. data/vendor/kreuzberg/tests/format_integration.rs +1 -7
  148. data/vendor/kreuzberg/tests/helpers/mod.rs +0 -60
  149. data/vendor/kreuzberg/tests/image_integration.rs +0 -2
  150. data/vendor/kreuzberg/tests/mime_detection.rs +16 -17
  151. data/vendor/kreuzberg/tests/ocr_configuration.rs +0 -4
  152. data/vendor/kreuzberg/tests/ocr_errors.rs +0 -22
  153. data/vendor/kreuzberg/tests/ocr_quality.rs +0 -2
  154. data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
  155. data/vendor/kreuzberg/tests/pdf_integration.rs +0 -2
  156. data/vendor/kreuzberg/tests/pipeline_integration.rs +2 -36
  157. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +0 -5
  158. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +1 -17
  159. data/vendor/kreuzberg/tests/plugin_system.rs +0 -6
  160. data/vendor/kreuzberg/tests/registry_integration_tests.rs +22 -2
  161. data/vendor/kreuzberg/tests/security_validation.rs +1 -13
  162. data/vendor/kreuzberg/tests/test_fastembed.rs +23 -45
  163. metadata +25 -171
  164. data/.rubocop.yml +0 -543
  165. data/ext/kreuzberg_rb/native/.cargo/config.toml +0 -23
  166. data/ext/kreuzberg_rb/native/Cargo.lock +0 -7619
  167. data/lib/kreuzberg/error_context.rb +0 -136
  168. data/lib/kreuzberg/types.rb +0 -170
  169. data/lib/libpdfium.so +0 -0
  170. data/spec/binding/async_operations_spec.rb +0 -473
  171. data/spec/binding/batch_operations_spec.rb +0 -595
  172. data/spec/binding/batch_spec.rb +0 -359
  173. data/spec/binding/config_result_spec.rb +0 -377
  174. data/spec/binding/embeddings_spec.rb +0 -816
  175. data/spec/binding/error_recovery_spec.rb +0 -488
  176. data/spec/binding/font_config_spec.rb +0 -220
  177. data/spec/binding/images_spec.rb +0 -738
  178. data/spec/binding/keywords_extraction_spec.rb +0 -600
  179. data/spec/binding/metadata_types_spec.rb +0 -1228
  180. data/spec/binding/pages_extraction_spec.rb +0 -471
  181. data/spec/binding/tables_spec.rb +0 -641
  182. data/spec/unit/config/chunking_config_spec.rb +0 -213
  183. data/spec/unit/config/embedding_config_spec.rb +0 -343
  184. data/spec/unit/config/extraction_config_spec.rb +0 -438
  185. data/spec/unit/config/font_config_spec.rb +0 -285
  186. data/spec/unit/config/hierarchy_config_spec.rb +0 -314
  187. data/spec/unit/config/image_extraction_config_spec.rb +0 -209
  188. data/spec/unit/config/image_preprocessing_config_spec.rb +0 -249
  189. data/spec/unit/config/keyword_config_spec.rb +0 -229
  190. data/spec/unit/config/language_detection_config_spec.rb +0 -258
  191. data/spec/unit/config/ocr_config_spec.rb +0 -171
  192. data/spec/unit/config/page_config_spec.rb +0 -221
  193. data/spec/unit/config/pdf_config_spec.rb +0 -267
  194. data/spec/unit/config/postprocessor_config_spec.rb +0 -290
  195. data/spec/unit/config/tesseract_config_spec.rb +0 -181
  196. data/spec/unit/config/token_reduction_config_spec.rb +0 -251
  197. data/test/metadata_types_test.rb +0 -959
  198. data/vendor/Cargo.toml +0 -61
  199. data/vendor/kreuzberg/examples/bench_fixes.rs +0 -71
  200. data/vendor/kreuzberg/examples/test_pdfium_fork.rs +0 -62
  201. data/vendor/kreuzberg/src/chunking/processor.rs +0 -219
  202. data/vendor/kreuzberg/src/core/batch_optimizations.rs +0 -385
  203. data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
  204. data/vendor/kreuzberg/src/core/formats.rs +0 -235
  205. data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
  206. data/vendor/kreuzberg/src/extraction/capacity.rs +0 -263
  207. data/vendor/kreuzberg/src/extraction/markdown.rs +0 -216
  208. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +0 -284
  209. data/vendor/kreuzberg/src/extractors/bibtex.rs +0 -470
  210. data/vendor/kreuzberg/src/extractors/docbook.rs +0 -504
  211. data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
  212. data/vendor/kreuzberg/src/extractors/fictionbook.rs +0 -492
  213. data/vendor/kreuzberg/src/extractors/jats.rs +0 -1054
  214. data/vendor/kreuzberg/src/extractors/jupyter.rs +0 -368
  215. data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
  216. data/vendor/kreuzberg/src/extractors/markdown.rs +0 -701
  217. data/vendor/kreuzberg/src/extractors/odt.rs +0 -628
  218. data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
  219. data/vendor/kreuzberg/src/extractors/orgmode.rs +0 -529
  220. data/vendor/kreuzberg/src/extractors/rst.rs +0 -577
  221. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
  222. data/vendor/kreuzberg/src/extractors/security.rs +0 -484
  223. data/vendor/kreuzberg/src/extractors/security_tests.rs +0 -367
  224. data/vendor/kreuzberg/src/extractors/typst.rs +0 -651
  225. data/vendor/kreuzberg/src/language_detection/processor.rs +0 -218
  226. data/vendor/kreuzberg/src/ocr/language_registry.rs +0 -520
  227. data/vendor/kreuzberg/src/panic_context.rs +0 -154
  228. data/vendor/kreuzberg/src/pdf/bindings.rs +0 -306
  229. data/vendor/kreuzberg/src/pdf/bundled.rs +0 -408
  230. data/vendor/kreuzberg/src/pdf/fonts.rs +0 -358
  231. data/vendor/kreuzberg/src/pdf/hierarchy.rs +0 -903
  232. data/vendor/kreuzberg/src/text/quality_processor.rs +0 -231
  233. data/vendor/kreuzberg/src/text/utf8_validation.rs +0 -193
  234. data/vendor/kreuzberg/src/utils/pool.rs +0 -503
  235. data/vendor/kreuzberg/src/utils/pool_sizing.rs +0 -364
  236. data/vendor/kreuzberg/src/utils/string_pool.rs +0 -761
  237. data/vendor/kreuzberg/tests/api_embed.rs +0 -360
  238. data/vendor/kreuzberg/tests/api_extract_multipart.rs +0 -52
  239. data/vendor/kreuzberg/tests/api_large_pdf_extraction.rs +0 -471
  240. data/vendor/kreuzberg/tests/api_large_pdf_extraction_diagnostics.rs +0 -289
  241. data/vendor/kreuzberg/tests/batch_pooling_benchmark.rs +0 -154
  242. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +0 -421
  243. data/vendor/kreuzberg/tests/config_integration_test.rs +0 -753
  244. data/vendor/kreuzberg/tests/data/hierarchy_ground_truth.json +0 -294
  245. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +0 -500
  246. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +0 -370
  247. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +0 -275
  248. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +0 -228
  249. data/vendor/kreuzberg/tests/html_table_test.rs +0 -551
  250. data/vendor/kreuzberg/tests/instrumentation_test.rs +0 -139
  251. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +0 -639
  252. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +0 -704
  253. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +0 -496
  254. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +0 -490
  255. data/vendor/kreuzberg/tests/ocr_language_registry.rs +0 -191
  256. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +0 -674
  257. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +0 -616
  258. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +0 -822
  259. data/vendor/kreuzberg/tests/page_markers.rs +0 -297
  260. data/vendor/kreuzberg/tests/pdf_hierarchy_detection.rs +0 -301
  261. data/vendor/kreuzberg/tests/pdf_hierarchy_quality.rs +0 -589
  262. data/vendor/kreuzberg/tests/pdf_ocr_triggering.rs +0 -301
  263. data/vendor/kreuzberg/tests/pdf_text_merging.rs +0 -475
  264. data/vendor/kreuzberg/tests/pdfium_linking.rs +0 -340
  265. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +0 -694
  266. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +0 -775
  267. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +0 -1260
  268. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +0 -648
  269. data/vendor/kreuzberg-ffi/Cargo.toml +0 -67
  270. data/vendor/kreuzberg-ffi/README.md +0 -851
  271. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +0 -227
  272. data/vendor/kreuzberg-ffi/build.rs +0 -168
  273. data/vendor/kreuzberg-ffi/cbindgen.toml +0 -37
  274. data/vendor/kreuzberg-ffi/kreuzberg-ffi.pc.in +0 -12
  275. data/vendor/kreuzberg-ffi/kreuzberg.h +0 -3012
  276. data/vendor/kreuzberg-ffi/src/batch_streaming.rs +0 -588
  277. data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
  278. data/vendor/kreuzberg-ffi/src/error.rs +0 -901
  279. data/vendor/kreuzberg-ffi/src/extraction.rs +0 -555
  280. data/vendor/kreuzberg-ffi/src/helpers.rs +0 -879
  281. data/vendor/kreuzberg-ffi/src/lib.rs +0 -977
  282. data/vendor/kreuzberg-ffi/src/memory.rs +0 -493
  283. data/vendor/kreuzberg-ffi/src/mime.rs +0 -329
  284. data/vendor/kreuzberg-ffi/src/panic_shield.rs +0 -265
  285. data/vendor/kreuzberg-ffi/src/plugins/document_extractor.rs +0 -442
  286. data/vendor/kreuzberg-ffi/src/plugins/mod.rs +0 -14
  287. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +0 -628
  288. data/vendor/kreuzberg-ffi/src/plugins/post_processor.rs +0 -438
  289. data/vendor/kreuzberg-ffi/src/plugins/validator.rs +0 -329
  290. data/vendor/kreuzberg-ffi/src/result.rs +0 -510
  291. data/vendor/kreuzberg-ffi/src/result_pool.rs +0 -639
  292. data/vendor/kreuzberg-ffi/src/result_view.rs +0 -773
  293. data/vendor/kreuzberg-ffi/src/string_intern.rs +0 -568
  294. data/vendor/kreuzberg-ffi/src/types.rs +0 -363
  295. data/vendor/kreuzberg-ffi/src/util.rs +0 -210
  296. data/vendor/kreuzberg-ffi/src/validation.rs +0 -848
  297. data/vendor/kreuzberg-ffi/tests.disabled/README.md +0 -48
  298. data/vendor/kreuzberg-ffi/tests.disabled/config_loading_tests.rs +0 -299
  299. data/vendor/kreuzberg-ffi/tests.disabled/config_tests.rs +0 -346
  300. data/vendor/kreuzberg-ffi/tests.disabled/extractor_tests.rs +0 -232
  301. data/vendor/kreuzberg-ffi/tests.disabled/plugin_registration_tests.rs +0 -470
  302. data/vendor/kreuzberg-tesseract/.commitlintrc.json +0 -13
  303. data/vendor/kreuzberg-tesseract/.crate-ignore +0 -2
  304. data/vendor/kreuzberg-tesseract/Cargo.lock +0 -2933
  305. data/vendor/kreuzberg-tesseract/Cargo.toml +0 -57
  306. data/vendor/kreuzberg-tesseract/LICENSE +0 -22
  307. data/vendor/kreuzberg-tesseract/README.md +0 -399
  308. data/vendor/kreuzberg-tesseract/build.rs +0 -1127
  309. data/vendor/kreuzberg-tesseract/patches/README.md +0 -71
  310. data/vendor/kreuzberg-tesseract/patches/tesseract.diff +0 -199
  311. data/vendor/kreuzberg-tesseract/src/api.rs +0 -1371
  312. data/vendor/kreuzberg-tesseract/src/choice_iterator.rs +0 -77
  313. data/vendor/kreuzberg-tesseract/src/enums.rs +0 -297
  314. data/vendor/kreuzberg-tesseract/src/error.rs +0 -81
  315. data/vendor/kreuzberg-tesseract/src/lib.rs +0 -145
  316. data/vendor/kreuzberg-tesseract/src/monitor.rs +0 -57
  317. data/vendor/kreuzberg-tesseract/src/mutable_iterator.rs +0 -197
  318. data/vendor/kreuzberg-tesseract/src/page_iterator.rs +0 -253
  319. data/vendor/kreuzberg-tesseract/src/result_iterator.rs +0 -286
  320. data/vendor/kreuzberg-tesseract/src/result_renderer.rs +0 -183
  321. data/vendor/kreuzberg-tesseract/tests/integration_test.rs +0 -211
@@ -1,475 +0,0 @@
1
- //! Tests for PDF text extraction with font information and bounding box operations.
2
- //!
3
- //! This module tests character extraction functionality following TDD principles,
4
- //! verifying that characters are extracted with positions and font sizes,
5
- //! and that bounding box operations work correctly.
6
-
7
- #![cfg(feature = "pdf")]
8
-
9
- mod helpers;
10
-
11
- use helpers::get_test_file_path;
12
- use kreuzberg::pdf::hierarchy::{BoundingBox, extract_chars_with_fonts};
13
- use pdfium_render::prelude::*;
14
-
15
- // ============================================================================
16
- // Character Extraction Tests (Following TDD)
17
- // ============================================================================
18
-
19
- /// Test basic character extraction with positions and font sizes.
20
- ///
21
- /// Verifies that:
22
- /// - Characters are extracted with their positions
23
- /// - Font sizes are captured
24
- /// - Position order is preserved
25
- #[test]
26
- fn test_extract_chars_basic() {
27
- let pdf_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
28
-
29
- // Load PDF
30
- let pdfium = Pdfium;
31
- let document = pdfium
32
- .load_pdf_from_file(pdf_path.to_str().unwrap(), None)
33
- .expect("Failed to load test PDF");
34
-
35
- // Get first page
36
- let page = document.pages().get(0).expect("Failed to get first page");
37
-
38
- // Extract characters with fonts
39
- let chars = extract_chars_with_fonts(&page).expect("Failed to extract characters with fonts");
40
-
41
- // Verify we got some characters
42
- assert!(!chars.is_empty(), "Should extract at least one character from test PDF");
43
-
44
- // Verify each character has required fields
45
- for char_data in chars.iter() {
46
- assert!(!char_data.text.is_empty(), "Character text should not be empty");
47
- assert!(char_data.font_size > 0.0, "Font size should be positive");
48
- assert!(char_data.x >= 0.0, "X position should be non-negative");
49
- assert!(char_data.y >= 0.0, "Y position should be non-negative");
50
- }
51
- }
52
-
53
- /// Test that character extraction preserves reading order.
54
- ///
55
- /// Verifies that:
56
- /// - Characters appear in left-to-right order
57
- /// - Y-coordinates generally decrease as we move down the page
58
- #[test]
59
- fn test_extract_chars_preserves_order() {
60
- let pdf_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
61
-
62
- // Load PDF
63
- let pdfium = Pdfium;
64
- let document = pdfium
65
- .load_pdf_from_file(pdf_path.to_str().unwrap(), None)
66
- .expect("Failed to load test PDF");
67
-
68
- // Get first page
69
- let page = document.pages().get(0).expect("Failed to get first page");
70
-
71
- // Extract characters with fonts
72
- let chars = extract_chars_with_fonts(&page).expect("Failed to extract characters with fonts");
73
-
74
- assert!(!chars.is_empty(), "Should extract at least one character");
75
-
76
- // Within each line (similar y-coordinate), characters should be left-to-right
77
- let mut last_y = f32::NEG_INFINITY;
78
- let mut last_x = f32::NEG_INFINITY;
79
- let y_line_threshold = 5.0; // Consider within 5 units as same line
80
-
81
- for char_data in chars.iter() {
82
- // If we're on a new line
83
- if (char_data.y - last_y).abs() > y_line_threshold {
84
- last_x = f32::NEG_INFINITY;
85
- last_y = char_data.y;
86
- }
87
-
88
- // On same line, x should generally increase (allowing for small variations)
89
- // We use a threshold to allow for measurement precision issues
90
- if (char_data.y - last_y).abs() <= y_line_threshold && char_data.x < last_x - 1.0 {
91
- // This is acceptable if it's a new line or small variation
92
- if last_x != f32::NEG_INFINITY && (char_data.y - last_y).abs() <= y_line_threshold {
93
- panic!(
94
- "Characters should be left-to-right on same line: {} < {} at y={}",
95
- char_data.x, last_x, char_data.y
96
- );
97
- }
98
- }
99
-
100
- last_x = char_data.x;
101
- last_y = char_data.y;
102
- }
103
- }
104
-
105
- // ============================================================================
106
- // Bounding Box Tests
107
- // ============================================================================
108
-
109
- /// Helper function to create a BoundingBox from x, y, width, height
110
- fn create_bbox(x: f32, y: f32, width: f32, height: f32) -> BoundingBox {
111
- BoundingBox {
112
- left: x,
113
- top: y,
114
- right: x + width,
115
- bottom: y + height,
116
- }
117
- }
118
-
119
- #[test]
120
- fn test_iou_calculation() {
121
- // Two overlapping boxes
122
- let bbox1 = create_bbox(0.0, 0.0, 10.0, 10.0);
123
- let bbox2 = create_bbox(5.0, 5.0, 10.0, 10.0);
124
-
125
- // Expected intersection: 5x5 = 25
126
- // Expected union: 100 + 100 - 25 = 175
127
- // Expected IOU: 25/175 ≈ 0.1429
128
- let iou = bbox1.iou(&bbox2);
129
- assert!((iou - 0.1429).abs() < 0.001, "IOU calculation failed");
130
- }
131
-
132
- #[test]
133
- fn test_weighted_distance_calculation() {
134
- // Two boxes with different X and Y distances
135
- let bbox1 = create_bbox(0.0, 0.0, 10.0, 10.0);
136
- let bbox2 = create_bbox(20.0, 5.0, 10.0, 10.0);
137
-
138
- // Distance: X=20, Y=5
139
- // Weighted: X*5.0 + Y*1.0 = 20*5.0 + 5*1.0 = 100 + 5 = 105
140
- let weighted_dist = bbox1.weighted_distance(&bbox2);
141
- assert!(
142
- (weighted_dist - 105.0).abs() < 0.001,
143
- "Weighted distance calculation failed"
144
- );
145
-
146
- // Verify X weight (5.0) > Y weight (1.0) by checking ratio
147
- let bbox3 = create_bbox(0.0, 0.0, 10.0, 10.0);
148
- let bbox4 = create_bbox(10.0, 0.0, 10.0, 10.0);
149
- let only_x_dist = bbox3.weighted_distance(&bbox4);
150
-
151
- let bbox5 = create_bbox(0.0, 0.0, 10.0, 10.0);
152
- let bbox6 = create_bbox(0.0, 10.0, 10.0, 10.0);
153
- let only_y_dist = bbox5.weighted_distance(&bbox6);
154
-
155
- // X distance of 10 with weight 5.0 = 50
156
- // Y distance of 10 with weight 1.0 = 10
157
- // X weight should be 5x larger than Y weight
158
- assert!(only_x_dist > only_y_dist, "X weight should be greater than Y weight");
159
- assert!((only_x_dist - 50.0).abs() < 0.001, "X-only weighted distance failed");
160
- assert!((only_y_dist - 10.0).abs() < 0.001, "Y-only weighted distance failed");
161
- }
162
-
163
- #[test]
164
- fn test_intersection_ratio() {
165
- // Two overlapping boxes
166
- let bbox1 = create_bbox(0.0, 0.0, 10.0, 10.0);
167
- let bbox2 = create_bbox(5.0, 5.0, 10.0, 10.0);
168
-
169
- // Expected intersection: 5x5 = 25
170
- // bbox1 area: 100
171
- // Expected ratio: 25/100 = 0.25
172
- let ratio = bbox1.intersection_ratio(&bbox2);
173
- assert!((ratio - 0.25).abs() < 0.001, "Intersection ratio calculation failed");
174
- }
175
-
176
- #[test]
177
- fn test_edge_case_no_overlap() {
178
- // Two non-overlapping boxes
179
- let bbox1 = create_bbox(0.0, 0.0, 10.0, 10.0);
180
- let bbox2 = create_bbox(20.0, 20.0, 10.0, 10.0);
181
-
182
- // IOU should be 0
183
- let iou = bbox1.iou(&bbox2);
184
- assert!((iou - 0.0).abs() < 0.001, "Non-overlapping boxes should have IOU of 0");
185
-
186
- // Intersection ratio should be 0
187
- let ratio = bbox1.intersection_ratio(&bbox2);
188
- assert!(
189
- (ratio - 0.0).abs() < 0.001,
190
- "Non-overlapping boxes should have intersection ratio of 0"
191
- );
192
- }
193
-
194
- #[test]
195
- fn test_edge_case_fully_contained() {
196
- // Smaller box fully contained in larger box
197
- let bbox_large = create_bbox(0.0, 0.0, 20.0, 20.0);
198
- let bbox_small = create_bbox(5.0, 5.0, 10.0, 10.0);
199
-
200
- // Intersection: 10x10 = 100
201
- // Union: 400 + 100 - 100 = 400
202
- // IOU: 100/400 = 0.25
203
- let iou = bbox_large.iou(&bbox_small);
204
- assert!((iou - 0.25).abs() < 0.001, "Fully contained box IOU calculation failed");
205
-
206
- // Intersection ratio: 100/400 = 0.25
207
- let ratio = bbox_large.intersection_ratio(&bbox_small);
208
- assert!(
209
- (ratio - 0.25).abs() < 0.001,
210
- "Fully contained box intersection ratio failed"
211
- );
212
- }
213
-
214
- // ============================================================================
215
- // Character Merging Tests (Following TDD)
216
- // ============================================================================
217
-
218
- use kreuzberg::pdf::hierarchy::{CharData, merge_chars_into_blocks};
219
-
220
- /// Factory helper to create a CharData with minimal parameters.
221
- fn create_char(text: &str, x: f32, y: f32, font_size: f32) -> CharData {
222
- CharData {
223
- text: text.to_string(),
224
- font_size,
225
- x,
226
- y,
227
- width: font_size * 0.6,
228
- height: font_size,
229
- }
230
- }
231
-
232
- /// Test horizontal text merging: characters at (0,10), (10,10), (20,10) should merge into 1 block.
233
- ///
234
- /// This test validates that characters on the same horizontal line and within the merge
235
- /// distance threshold are grouped into a single text block.
236
- #[test]
237
- fn test_merge_horizontal_text_merging() {
238
- let chars = vec![
239
- create_char("H", 0.0, 10.0, 12.0),
240
- create_char("e", 10.0, 10.0, 12.0),
241
- create_char("y", 20.0, 10.0, 12.0),
242
- ];
243
-
244
- let blocks = merge_chars_into_blocks(chars);
245
-
246
- assert_eq!(blocks.len(), 1, "Expected 1 block for horizontal text");
247
- assert_eq!(blocks[0].text, "Hey", "Expected merged text 'Hey'");
248
- }
249
-
250
- /// Test vertical text separation: characters at (0,10) and (0,50) should be 2 blocks.
251
- ///
252
- /// This test validates that characters with large vertical separation are kept in separate blocks.
253
- #[test]
254
- fn test_merge_vertical_text_separation() {
255
- let chars = vec![create_char("A", 0.0, 10.0, 12.0), create_char("B", 0.0, 50.0, 12.0)];
256
-
257
- let blocks = merge_chars_into_blocks(chars);
258
-
259
- assert_eq!(blocks.len(), 2, "Expected 2 blocks for vertically separated text");
260
- assert_eq!(blocks[0].text, "A", "Expected first block to contain 'A'");
261
- assert_eq!(blocks[1].text, "B", "Expected second block to contain 'B'");
262
- }
263
-
264
- /// Test edge case with negative coordinates.
265
- ///
266
- /// This test ensures the merging algorithm handles negative coordinates correctly.
267
- #[test]
268
- fn test_merge_edge_case_negative_coordinates() {
269
- let chars = vec![
270
- create_char("X", -10.0, -5.0, 12.0),
271
- create_char("Y", 0.0, -5.0, 12.0),
272
- create_char("Z", 10.0, -5.0, 12.0),
273
- ];
274
-
275
- let blocks = merge_chars_into_blocks(chars);
276
-
277
- assert_eq!(blocks.len(), 1, "Expected 1 block for negative coordinates");
278
- assert_eq!(blocks[0].text, "XYZ", "Expected merged text 'XYZ'");
279
- }
280
-
281
- /// Test edge case with overlapping blocks.
282
- ///
283
- /// This test validates behavior when characters have overlapping or very close bounding boxes.
284
- #[test]
285
- fn test_merge_edge_case_overlapping_blocks() {
286
- let chars = vec![
287
- create_char("O", 0.0, 0.0, 12.0),
288
- create_char("V", 1.0, 0.0, 12.0),
289
- create_char("E", 2.0, 0.0, 12.0),
290
- ];
291
-
292
- let blocks = merge_chars_into_blocks(chars);
293
-
294
- assert_eq!(blocks.len(), 1, "Expected 1 block for overlapping characters");
295
- assert_eq!(blocks[0].text, "OVE", "Expected merged text 'OVE'");
296
- }
297
-
298
- /// Test max merge distance threshold.
299
- ///
300
- /// This test validates that characters beyond the maximum merge distance are kept separate.
301
- #[test]
302
- fn test_merge_max_merge_distance_threshold() {
303
- let chars = vec![
304
- create_char("T", 0.0, 10.0, 12.0),
305
- create_char("e", 50.0, 10.0, 12.0), // Large gap, should be separate
306
- create_char("s", 100.0, 10.0, 12.0), // Even larger gap
307
- ];
308
-
309
- let blocks = merge_chars_into_blocks(chars);
310
-
311
- // With reasonable merge distance (should be ~2.5x font size for distance),
312
- // characters at 50 and 100 units apart should create separate blocks
313
- assert!(blocks.len() > 1, "Expected multiple blocks due to large gaps");
314
- assert_eq!(
315
- blocks.iter().map(|b| b.text.len()).sum::<usize>(),
316
- 3,
317
- "Expected all 3 characters to be preserved"
318
- );
319
- }
320
-
321
- /// Test edge case with zero font size.
322
- ///
323
- /// This test ensures the algorithm handles zero or near-zero font sizes gracefully
324
- /// without panicking or causing division by zero.
325
- #[test]
326
- fn test_merge_zero_font_size() {
327
- // Create characters with zero font size (edge case)
328
- let chars = vec![
329
- CharData {
330
- text: "A".to_string(),
331
- x: 0.0,
332
- y: 10.0,
333
- font_size: 0.0,
334
- width: 0.0,
335
- height: 0.0,
336
- },
337
- CharData {
338
- text: "B".to_string(),
339
- x: 1.0,
340
- y: 10.0,
341
- font_size: 0.0,
342
- width: 0.0,
343
- height: 0.0,
344
- },
345
- ];
346
-
347
- // Should not panic
348
- let blocks = merge_chars_into_blocks(chars);
349
-
350
- // Should still produce some output
351
- assert!(!blocks.is_empty(), "Should produce blocks even with zero font size");
352
- }
353
-
354
- /// Test IOU calculation with zero area boxes.
355
- ///
356
- /// This test validates that IOU calculations handle degenerate bounding boxes
357
- /// with zero area without panicking.
358
- #[test]
359
- fn test_iou_zero_area_boxes() {
360
- // Two boxes with zero area (point-like)
361
- let bbox1 = create_bbox(0.0, 0.0, 0.0, 0.0);
362
- let bbox2 = create_bbox(5.0, 5.0, 0.0, 0.0);
363
-
364
- // Should not panic and should return 0 or similar
365
- let iou = bbox1.iou(&bbox2);
366
- assert!(
367
- (0.0..=1.0).contains(&iou),
368
- "IOU should be in valid range for zero-area boxes"
369
- );
370
-
371
- // Intersection ratio should also be safe
372
- let ratio = bbox1.intersection_ratio(&bbox2);
373
- assert!(
374
- (0.0..=1.0).contains(&ratio),
375
- "Intersection ratio should be in valid range"
376
- );
377
- }
378
-
379
- /// Test IOU calculation with identical boxes.
380
- ///
381
- /// This test validates that identical boxes have IOU of 1.0 (perfect overlap).
382
- #[test]
383
- fn test_iou_identical_boxes() {
384
- // Two identical boxes
385
- let bbox1 = create_bbox(10.0, 20.0, 30.0, 40.0);
386
- let bbox2 = create_bbox(10.0, 20.0, 30.0, 40.0);
387
-
388
- // IOU should be 1.0 for identical boxes
389
- let iou = bbox1.iou(&bbox2);
390
- assert!(
391
- (iou - 1.0).abs() < 0.001,
392
- "Identical boxes should have IOU of 1.0, got {}",
393
- iou
394
- );
395
-
396
- // Intersection ratio should also be 1.0
397
- let ratio = bbox1.intersection_ratio(&bbox2);
398
- assert!(
399
- (ratio - 1.0).abs() < 0.001,
400
- "Identical boxes should have intersection ratio of 1.0, got {}",
401
- ratio
402
- );
403
- }
404
-
405
- /// Test contains() method with various box configurations.
406
- #[test]
407
- fn test_contains_method() {
408
- let large_box = create_bbox(0.0, 0.0, 100.0, 100.0);
409
- let small_box = create_bbox(10.0, 10.0, 50.0, 50.0);
410
- let outside_box = create_bbox(110.0, 110.0, 150.0, 150.0);
411
-
412
- // Small box should be contained in large box
413
- assert!(large_box.contains(&small_box), "Large box should contain small box");
414
-
415
- // Large box should not be contained in small box
416
- assert!(
417
- !small_box.contains(&large_box),
418
- "Small box should not contain large box"
419
- );
420
-
421
- // Outside box should not be contained
422
- assert!(
423
- !large_box.contains(&outside_box),
424
- "Large box should not contain outside box"
425
- );
426
- }
427
-
428
- /// Test center() method for bounding box centerpoint calculation.
429
- #[test]
430
- fn test_center_method() {
431
- let bbox = create_bbox(0.0, 0.0, 100.0, 100.0);
432
- let center = bbox.center();
433
-
434
- assert_eq!(center.0, 50.0, "Center X should be 50.0");
435
- assert_eq!(center.1, 50.0, "Center Y should be 50.0");
436
-
437
- // Test with offset box
438
- let offset_bbox = create_bbox(20.0, 30.0, 80.0, 70.0);
439
- let offset_center = offset_bbox.center();
440
-
441
- assert_eq!(offset_center.0, 60.0, "Offset center X should be 60.0");
442
- assert_eq!(offset_center.1, 65.0, "Offset center Y should be 65.0");
443
- }
444
-
445
- /// Test merge() method for combining bounding boxes.
446
- #[test]
447
- fn test_merge_method() {
448
- let bbox1 = create_bbox(0.0, 0.0, 50.0, 50.0);
449
- let bbox2 = create_bbox(30.0, 30.0, 100.0, 100.0);
450
-
451
- let merged = bbox1.merge(&bbox2);
452
-
453
- assert_eq!(merged.left, 0.0, "Merged left should be 0.0");
454
- assert_eq!(merged.top, 0.0, "Merged top should be 0.0");
455
- assert_eq!(merged.right, 130.0, "Merged right should be 130.0");
456
- assert_eq!(merged.bottom, 130.0, "Merged bottom should be 130.0");
457
- }
458
-
459
- /// Test relaxed_iou() method with expansion factor.
460
- #[test]
461
- fn test_relaxed_iou_method() {
462
- let bbox1 = create_bbox(0.0, 0.0, 10.0, 10.0);
463
- let bbox2 = create_bbox(15.0, 15.0, 25.0, 25.0);
464
-
465
- // Without relaxation, IOU should be 0
466
- let normal_iou = bbox1.iou(&bbox2);
467
- assert!(normal_iou < 0.01, "Non-overlapping boxes should have near-zero IOU");
468
-
469
- // With relaxation, IOU should increase
470
- let relaxed_iou = bbox1.relaxed_iou(&bbox2, 0.5);
471
- assert!(
472
- relaxed_iou > normal_iou,
473
- "Relaxed IOU should be greater than normal IOU"
474
- );
475
- }