kreuzberg 4.0.7 → 4.1.0

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 (308) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +24 -16
  3. data/README.md +4 -1
  4. data/ext/kreuzberg_rb/native/Cargo.lock +94 -98
  5. data/ext/kreuzberg_rb/native/Cargo.toml +4 -2
  6. data/ext/kreuzberg_rb/native/src/batch.rs +139 -0
  7. data/ext/kreuzberg_rb/native/src/config/mod.rs +10 -0
  8. data/ext/kreuzberg_rb/native/src/config/types.rs +1058 -0
  9. data/ext/kreuzberg_rb/native/src/error_handling.rs +125 -0
  10. data/ext/kreuzberg_rb/native/src/extraction.rs +79 -0
  11. data/ext/kreuzberg_rb/native/src/gc_guarded_value.rs +35 -0
  12. data/ext/kreuzberg_rb/native/src/helpers.rs +176 -0
  13. data/ext/kreuzberg_rb/native/src/lib.rs +342 -3622
  14. data/ext/kreuzberg_rb/native/src/metadata.rs +34 -0
  15. data/ext/kreuzberg_rb/native/src/plugins/mod.rs +92 -0
  16. data/ext/kreuzberg_rb/native/src/plugins/ocr_backend.rs +159 -0
  17. data/ext/kreuzberg_rb/native/src/plugins/post_processor.rs +126 -0
  18. data/ext/kreuzberg_rb/native/src/plugins/validator.rs +99 -0
  19. data/ext/kreuzberg_rb/native/src/result.rs +326 -0
  20. data/ext/kreuzberg_rb/native/src/validation.rs +4 -0
  21. data/lib/kreuzberg/config.rb +66 -0
  22. data/lib/kreuzberg/result.rb +107 -2
  23. data/lib/kreuzberg/types.rb +104 -0
  24. data/lib/kreuzberg/version.rb +1 -1
  25. data/lib/kreuzberg.rb +0 -4
  26. data/sig/kreuzberg.rbs +105 -1
  27. data/vendor/Cargo.toml +3 -3
  28. data/vendor/kreuzberg/Cargo.toml +4 -3
  29. data/vendor/kreuzberg/README.md +1 -1
  30. data/vendor/kreuzberg/src/api/config.rs +69 -0
  31. data/vendor/kreuzberg/src/api/handlers.rs +99 -2
  32. data/vendor/kreuzberg/src/api/mod.rs +14 -7
  33. data/vendor/kreuzberg/src/api/router.rs +214 -0
  34. data/vendor/kreuzberg/src/api/startup.rs +243 -0
  35. data/vendor/kreuzberg/src/api/types.rs +78 -0
  36. data/vendor/kreuzberg/src/cache/cleanup.rs +277 -0
  37. data/vendor/kreuzberg/src/cache/core.rs +428 -0
  38. data/vendor/kreuzberg/src/cache/mod.rs +21 -843
  39. data/vendor/kreuzberg/src/cache/utilities.rs +156 -0
  40. data/vendor/kreuzberg/src/chunking/boundaries.rs +301 -0
  41. data/vendor/kreuzberg/src/chunking/builder.rs +294 -0
  42. data/vendor/kreuzberg/src/chunking/config.rs +52 -0
  43. data/vendor/kreuzberg/src/chunking/core.rs +1017 -0
  44. data/vendor/kreuzberg/src/chunking/mod.rs +14 -2211
  45. data/vendor/kreuzberg/src/chunking/processor.rs +10 -0
  46. data/vendor/kreuzberg/src/chunking/validation.rs +686 -0
  47. data/vendor/kreuzberg/src/core/config/extraction/core.rs +169 -0
  48. data/vendor/kreuzberg/src/core/config/extraction/env.rs +179 -0
  49. data/vendor/kreuzberg/src/core/config/extraction/loaders.rs +204 -0
  50. data/vendor/kreuzberg/src/core/config/extraction/mod.rs +42 -0
  51. data/vendor/kreuzberg/src/core/config/extraction/types.rs +93 -0
  52. data/vendor/kreuzberg/src/core/config/formats.rs +135 -0
  53. data/vendor/kreuzberg/src/core/config/mod.rs +20 -0
  54. data/vendor/kreuzberg/src/core/config/ocr.rs +73 -0
  55. data/vendor/kreuzberg/src/core/config/page.rs +57 -0
  56. data/vendor/kreuzberg/src/core/config/pdf.rs +111 -0
  57. data/vendor/kreuzberg/src/core/config/processing.rs +312 -0
  58. data/vendor/kreuzberg/src/core/config_validation/dependencies.rs +187 -0
  59. data/vendor/kreuzberg/src/core/config_validation/mod.rs +386 -0
  60. data/vendor/kreuzberg/src/core/config_validation/sections.rs +401 -0
  61. data/vendor/kreuzberg/src/core/extractor/batch.rs +246 -0
  62. data/vendor/kreuzberg/src/core/extractor/bytes.rs +116 -0
  63. data/vendor/kreuzberg/src/core/extractor/file.rs +240 -0
  64. data/vendor/kreuzberg/src/core/extractor/helpers.rs +71 -0
  65. data/vendor/kreuzberg/src/core/extractor/legacy.rs +62 -0
  66. data/vendor/kreuzberg/src/core/extractor/mod.rs +490 -0
  67. data/vendor/kreuzberg/src/core/extractor/sync.rs +208 -0
  68. data/vendor/kreuzberg/src/core/mod.rs +4 -1
  69. data/vendor/kreuzberg/src/core/pipeline/cache.rs +60 -0
  70. data/vendor/kreuzberg/src/core/pipeline/execution.rs +89 -0
  71. data/vendor/kreuzberg/src/core/pipeline/features.rs +108 -0
  72. data/vendor/kreuzberg/src/core/pipeline/format.rs +392 -0
  73. data/vendor/kreuzberg/src/core/pipeline/initialization.rs +67 -0
  74. data/vendor/kreuzberg/src/core/pipeline/mod.rs +135 -0
  75. data/vendor/kreuzberg/src/core/pipeline/tests.rs +975 -0
  76. data/vendor/kreuzberg/src/core/server_config/env.rs +90 -0
  77. data/vendor/kreuzberg/src/core/server_config/loader.rs +202 -0
  78. data/vendor/kreuzberg/src/core/server_config/mod.rs +380 -0
  79. data/vendor/kreuzberg/src/core/server_config/tests/basic_tests.rs +124 -0
  80. data/vendor/kreuzberg/src/core/server_config/tests/env_tests.rs +216 -0
  81. data/vendor/kreuzberg/src/core/server_config/tests/file_loading_tests.rs +341 -0
  82. data/vendor/kreuzberg/src/core/server_config/tests/mod.rs +5 -0
  83. data/vendor/kreuzberg/src/core/server_config/validation.rs +17 -0
  84. data/vendor/kreuzberg/src/embeddings.rs +136 -13
  85. data/vendor/kreuzberg/src/extraction/{archive.rs → archive/mod.rs} +45 -239
  86. data/vendor/kreuzberg/src/extraction/archive/sevenz.rs +98 -0
  87. data/vendor/kreuzberg/src/extraction/archive/tar.rs +118 -0
  88. data/vendor/kreuzberg/src/extraction/archive/zip.rs +101 -0
  89. data/vendor/kreuzberg/src/extraction/html/converter.rs +592 -0
  90. data/vendor/kreuzberg/src/extraction/html/image_handling.rs +95 -0
  91. data/vendor/kreuzberg/src/extraction/html/mod.rs +53 -0
  92. data/vendor/kreuzberg/src/extraction/html/processor.rs +659 -0
  93. data/vendor/kreuzberg/src/extraction/html/stack_management.rs +103 -0
  94. data/vendor/kreuzberg/src/extraction/html/types.rs +28 -0
  95. data/vendor/kreuzberg/src/extraction/mod.rs +6 -2
  96. data/vendor/kreuzberg/src/extraction/pptx/container.rs +159 -0
  97. data/vendor/kreuzberg/src/extraction/pptx/content_builder.rs +168 -0
  98. data/vendor/kreuzberg/src/extraction/pptx/elements.rs +132 -0
  99. data/vendor/kreuzberg/src/extraction/pptx/image_handling.rs +57 -0
  100. data/vendor/kreuzberg/src/extraction/pptx/metadata.rs +160 -0
  101. data/vendor/kreuzberg/src/extraction/pptx/mod.rs +558 -0
  102. data/vendor/kreuzberg/src/extraction/pptx/parser.rs +379 -0
  103. data/vendor/kreuzberg/src/extraction/transform/content.rs +205 -0
  104. data/vendor/kreuzberg/src/extraction/transform/elements.rs +211 -0
  105. data/vendor/kreuzberg/src/extraction/transform/mod.rs +480 -0
  106. data/vendor/kreuzberg/src/extraction/transform/types.rs +27 -0
  107. data/vendor/kreuzberg/src/extractors/archive.rs +2 -0
  108. data/vendor/kreuzberg/src/extractors/bibtex.rs +2 -0
  109. data/vendor/kreuzberg/src/extractors/djot_format/attributes.rs +134 -0
  110. data/vendor/kreuzberg/src/extractors/djot_format/conversion.rs +223 -0
  111. data/vendor/kreuzberg/src/extractors/djot_format/extractor.rs +172 -0
  112. data/vendor/kreuzberg/src/extractors/djot_format/mod.rs +24 -0
  113. data/vendor/kreuzberg/src/extractors/djot_format/parsing/block_handlers.rs +271 -0
  114. data/vendor/kreuzberg/src/extractors/djot_format/parsing/content_extraction.rs +257 -0
  115. data/vendor/kreuzberg/src/extractors/djot_format/parsing/event_handlers.rs +101 -0
  116. data/vendor/kreuzberg/src/extractors/djot_format/parsing/inline_handlers.rs +201 -0
  117. data/vendor/kreuzberg/src/extractors/djot_format/parsing/mod.rs +16 -0
  118. data/vendor/kreuzberg/src/extractors/djot_format/parsing/state.rs +78 -0
  119. data/vendor/kreuzberg/src/extractors/djot_format/parsing/table_extraction.rs +68 -0
  120. data/vendor/kreuzberg/src/extractors/djot_format/parsing/text_extraction.rs +61 -0
  121. data/vendor/kreuzberg/src/extractors/djot_format/rendering.rs +452 -0
  122. data/vendor/kreuzberg/src/extractors/docbook.rs +2 -0
  123. data/vendor/kreuzberg/src/extractors/docx.rs +12 -1
  124. data/vendor/kreuzberg/src/extractors/email.rs +2 -0
  125. data/vendor/kreuzberg/src/extractors/epub/content.rs +333 -0
  126. data/vendor/kreuzberg/src/extractors/epub/metadata.rs +137 -0
  127. data/vendor/kreuzberg/src/extractors/epub/mod.rs +186 -0
  128. data/vendor/kreuzberg/src/extractors/epub/parsing.rs +86 -0
  129. data/vendor/kreuzberg/src/extractors/excel.rs +4 -0
  130. data/vendor/kreuzberg/src/extractors/fictionbook.rs +2 -0
  131. data/vendor/kreuzberg/src/extractors/frontmatter_utils.rs +466 -0
  132. data/vendor/kreuzberg/src/extractors/html.rs +80 -8
  133. data/vendor/kreuzberg/src/extractors/image.rs +8 -1
  134. data/vendor/kreuzberg/src/extractors/jats/elements.rs +350 -0
  135. data/vendor/kreuzberg/src/extractors/jats/metadata.rs +21 -0
  136. data/vendor/kreuzberg/src/extractors/{jats.rs → jats/mod.rs} +10 -412
  137. data/vendor/kreuzberg/src/extractors/jats/parser.rs +52 -0
  138. data/vendor/kreuzberg/src/extractors/jupyter.rs +2 -0
  139. data/vendor/kreuzberg/src/extractors/latex/commands.rs +93 -0
  140. data/vendor/kreuzberg/src/extractors/latex/environments.rs +157 -0
  141. data/vendor/kreuzberg/src/extractors/latex/metadata.rs +27 -0
  142. data/vendor/kreuzberg/src/extractors/latex/mod.rs +146 -0
  143. data/vendor/kreuzberg/src/extractors/latex/parser.rs +231 -0
  144. data/vendor/kreuzberg/src/extractors/latex/utilities.rs +126 -0
  145. data/vendor/kreuzberg/src/extractors/markdown.rs +39 -162
  146. data/vendor/kreuzberg/src/extractors/mod.rs +9 -1
  147. data/vendor/kreuzberg/src/extractors/odt.rs +2 -0
  148. data/vendor/kreuzberg/src/extractors/opml/core.rs +165 -0
  149. data/vendor/kreuzberg/src/extractors/opml/mod.rs +31 -0
  150. data/vendor/kreuzberg/src/extractors/opml/parser.rs +479 -0
  151. data/vendor/kreuzberg/src/extractors/orgmode.rs +2 -0
  152. data/vendor/kreuzberg/src/extractors/pdf/extraction.rs +106 -0
  153. data/vendor/kreuzberg/src/extractors/{pdf.rs → pdf/mod.rs} +25 -324
  154. data/vendor/kreuzberg/src/extractors/pdf/ocr.rs +214 -0
  155. data/vendor/kreuzberg/src/extractors/pdf/pages.rs +51 -0
  156. data/vendor/kreuzberg/src/extractors/pptx.rs +9 -2
  157. data/vendor/kreuzberg/src/extractors/rst.rs +2 -0
  158. data/vendor/kreuzberg/src/extractors/rtf/encoding.rs +116 -0
  159. data/vendor/kreuzberg/src/extractors/rtf/formatting.rs +24 -0
  160. data/vendor/kreuzberg/src/extractors/rtf/images.rs +72 -0
  161. data/vendor/kreuzberg/src/extractors/rtf/metadata.rs +216 -0
  162. data/vendor/kreuzberg/src/extractors/rtf/mod.rs +142 -0
  163. data/vendor/kreuzberg/src/extractors/rtf/parser.rs +259 -0
  164. data/vendor/kreuzberg/src/extractors/rtf/tables.rs +83 -0
  165. data/vendor/kreuzberg/src/extractors/structured.rs +2 -0
  166. data/vendor/kreuzberg/src/extractors/text.rs +4 -0
  167. data/vendor/kreuzberg/src/extractors/typst.rs +2 -0
  168. data/vendor/kreuzberg/src/extractors/xml.rs +2 -0
  169. data/vendor/kreuzberg/src/keywords/processor.rs +14 -0
  170. data/vendor/kreuzberg/src/language_detection/processor.rs +10 -0
  171. data/vendor/kreuzberg/src/lib.rs +2 -2
  172. data/vendor/kreuzberg/src/mcp/errors.rs +312 -0
  173. data/vendor/kreuzberg/src/mcp/format.rs +211 -0
  174. data/vendor/kreuzberg/src/mcp/mod.rs +9 -3
  175. data/vendor/kreuzberg/src/mcp/params.rs +196 -0
  176. data/vendor/kreuzberg/src/mcp/server.rs +39 -1438
  177. data/vendor/kreuzberg/src/mcp/tools/cache.rs +179 -0
  178. data/vendor/kreuzberg/src/mcp/tools/extraction.rs +403 -0
  179. data/vendor/kreuzberg/src/mcp/tools/mime.rs +150 -0
  180. data/vendor/kreuzberg/src/mcp/tools/mod.rs +11 -0
  181. data/vendor/kreuzberg/src/ocr/backends/easyocr.rs +96 -0
  182. data/vendor/kreuzberg/src/ocr/backends/mod.rs +7 -0
  183. data/vendor/kreuzberg/src/ocr/backends/paddleocr.rs +27 -0
  184. data/vendor/kreuzberg/src/ocr/backends/tesseract.rs +134 -0
  185. data/vendor/kreuzberg/src/ocr/hocr.rs +60 -16
  186. data/vendor/kreuzberg/src/ocr/language_registry.rs +11 -235
  187. data/vendor/kreuzberg/src/ocr/mod.rs +1 -0
  188. data/vendor/kreuzberg/src/ocr/processor/config.rs +203 -0
  189. data/vendor/kreuzberg/src/ocr/processor/execution.rs +494 -0
  190. data/vendor/kreuzberg/src/ocr/processor/mod.rs +265 -0
  191. data/vendor/kreuzberg/src/ocr/processor/validation.rs +145 -0
  192. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +41 -24
  193. data/vendor/kreuzberg/src/pdf/bindings.rs +21 -8
  194. data/vendor/kreuzberg/src/pdf/hierarchy/bounding_box.rs +289 -0
  195. data/vendor/kreuzberg/src/pdf/hierarchy/clustering.rs +199 -0
  196. data/vendor/kreuzberg/src/pdf/{hierarchy.rs → hierarchy/extraction.rs} +6 -346
  197. data/vendor/kreuzberg/src/pdf/hierarchy/mod.rs +18 -0
  198. data/vendor/kreuzberg/src/plugins/extractor/mod.rs +319 -0
  199. data/vendor/kreuzberg/src/plugins/extractor/registry.rs +434 -0
  200. data/vendor/kreuzberg/src/plugins/extractor/trait.rs +391 -0
  201. data/vendor/kreuzberg/src/plugins/mod.rs +13 -0
  202. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -0
  203. data/vendor/kreuzberg/src/plugins/processor/mod.rs +365 -0
  204. data/vendor/kreuzberg/src/plugins/processor/registry.rs +37 -0
  205. data/vendor/kreuzberg/src/plugins/processor/trait.rs +284 -0
  206. data/vendor/kreuzberg/src/plugins/registry/extractor.rs +416 -0
  207. data/vendor/kreuzberg/src/plugins/registry/mod.rs +116 -0
  208. data/vendor/kreuzberg/src/plugins/registry/ocr.rs +293 -0
  209. data/vendor/kreuzberg/src/plugins/registry/processor.rs +304 -0
  210. data/vendor/kreuzberg/src/plugins/registry/validator.rs +238 -0
  211. data/vendor/kreuzberg/src/plugins/validator/mod.rs +424 -0
  212. data/vendor/kreuzberg/src/plugins/validator/registry.rs +355 -0
  213. data/vendor/kreuzberg/src/plugins/validator/trait.rs +276 -0
  214. data/vendor/kreuzberg/src/stopwords/languages/asian.rs +40 -0
  215. data/vendor/kreuzberg/src/stopwords/languages/germanic.rs +36 -0
  216. data/vendor/kreuzberg/src/stopwords/languages/mod.rs +10 -0
  217. data/vendor/kreuzberg/src/stopwords/languages/other.rs +44 -0
  218. data/vendor/kreuzberg/src/stopwords/languages/romance.rs +36 -0
  219. data/vendor/kreuzberg/src/stopwords/languages/slavic.rs +36 -0
  220. data/vendor/kreuzberg/src/stopwords/mod.rs +7 -33
  221. data/vendor/kreuzberg/src/text/quality.rs +1 -1
  222. data/vendor/kreuzberg/src/text/quality_processor.rs +10 -0
  223. data/vendor/kreuzberg/src/text/token_reduction/core/analysis.rs +238 -0
  224. data/vendor/kreuzberg/src/text/token_reduction/core/mod.rs +8 -0
  225. data/vendor/kreuzberg/src/text/token_reduction/core/punctuation.rs +54 -0
  226. data/vendor/kreuzberg/src/text/token_reduction/core/reducer.rs +384 -0
  227. data/vendor/kreuzberg/src/text/token_reduction/core/sentence_selection.rs +68 -0
  228. data/vendor/kreuzberg/src/text/token_reduction/core/word_filtering.rs +156 -0
  229. data/vendor/kreuzberg/src/text/token_reduction/filters/general.rs +377 -0
  230. data/vendor/kreuzberg/src/text/token_reduction/filters/html.rs +51 -0
  231. data/vendor/kreuzberg/src/text/token_reduction/filters/markdown.rs +285 -0
  232. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +131 -246
  233. data/vendor/kreuzberg/src/types/djot.rs +209 -0
  234. data/vendor/kreuzberg/src/types/extraction.rs +301 -0
  235. data/vendor/kreuzberg/src/types/formats.rs +443 -0
  236. data/vendor/kreuzberg/src/types/metadata.rs +560 -0
  237. data/vendor/kreuzberg/src/types/mod.rs +281 -0
  238. data/vendor/kreuzberg/src/types/page.rs +182 -0
  239. data/vendor/kreuzberg/src/types/serde_helpers.rs +132 -0
  240. data/vendor/kreuzberg/src/types/tables.rs +39 -0
  241. data/vendor/kreuzberg/src/utils/quality/heuristics.rs +58 -0
  242. data/vendor/kreuzberg/src/utils/{quality.rs → quality/mod.rs} +168 -489
  243. data/vendor/kreuzberg/src/utils/quality/patterns.rs +117 -0
  244. data/vendor/kreuzberg/src/utils/quality/scoring.rs +178 -0
  245. data/vendor/kreuzberg/src/utils/string_pool/buffer_pool.rs +325 -0
  246. data/vendor/kreuzberg/src/utils/string_pool/interned.rs +102 -0
  247. data/vendor/kreuzberg/src/utils/string_pool/language_pool.rs +119 -0
  248. data/vendor/kreuzberg/src/utils/string_pool/mime_pool.rs +235 -0
  249. data/vendor/kreuzberg/src/utils/string_pool/mod.rs +41 -0
  250. data/vendor/kreuzberg/tests/api_chunk.rs +313 -0
  251. data/vendor/kreuzberg/tests/api_embed.rs +6 -9
  252. data/vendor/kreuzberg/tests/batch_orchestration.rs +1 -0
  253. data/vendor/kreuzberg/tests/concurrency_stress.rs +7 -0
  254. data/vendor/kreuzberg/tests/core_integration.rs +1 -0
  255. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +130 -0
  256. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +5 -14
  257. data/vendor/kreuzberg/tests/format_integration.rs +2 -0
  258. data/vendor/kreuzberg/tests/helpers/mod.rs +1 -0
  259. data/vendor/kreuzberg/tests/html_table_test.rs +11 -11
  260. data/vendor/kreuzberg/tests/ocr_configuration.rs +16 -0
  261. data/vendor/kreuzberg/tests/ocr_errors.rs +18 -0
  262. data/vendor/kreuzberg/tests/ocr_quality.rs +9 -0
  263. data/vendor/kreuzberg/tests/ocr_stress.rs +1 -0
  264. data/vendor/kreuzberg/tests/pipeline_integration.rs +50 -0
  265. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +13 -0
  266. data/vendor/kreuzberg/tests/plugin_system.rs +12 -0
  267. data/vendor/kreuzberg/tests/registry_integration_tests.rs +2 -0
  268. data/vendor/kreuzberg-ffi/Cargo.toml +2 -1
  269. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +2 -0
  270. data/vendor/kreuzberg-ffi/kreuzberg.h +347 -178
  271. data/vendor/kreuzberg-ffi/src/config/html.rs +318 -0
  272. data/vendor/kreuzberg-ffi/src/config/loader.rs +154 -0
  273. data/vendor/kreuzberg-ffi/src/config/merge.rs +104 -0
  274. data/vendor/kreuzberg-ffi/src/config/mod.rs +385 -0
  275. data/vendor/kreuzberg-ffi/src/config/parse.rs +91 -0
  276. data/vendor/kreuzberg-ffi/src/config/serialize.rs +118 -0
  277. data/vendor/kreuzberg-ffi/src/config_builder.rs +598 -0
  278. data/vendor/kreuzberg-ffi/src/error.rs +46 -14
  279. data/vendor/kreuzberg-ffi/src/helpers.rs +26 -353
  280. data/vendor/kreuzberg-ffi/src/html_options.rs +421 -0
  281. data/vendor/kreuzberg-ffi/src/lib.rs +16 -0
  282. data/vendor/kreuzberg-ffi/src/panic_shield.rs +11 -0
  283. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +2 -0
  284. data/vendor/kreuzberg-ffi/src/result.rs +148 -122
  285. data/vendor/kreuzberg-ffi/src/result_view.rs +4 -0
  286. data/vendor/kreuzberg-tesseract/Cargo.toml +3 -3
  287. metadata +200 -28
  288. data/vendor/kreuzberg/src/api/server.rs +0 -518
  289. data/vendor/kreuzberg/src/core/config.rs +0 -1914
  290. data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
  291. data/vendor/kreuzberg/src/core/extractor.rs +0 -1200
  292. data/vendor/kreuzberg/src/core/pipeline.rs +0 -1223
  293. data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
  294. data/vendor/kreuzberg/src/extraction/html.rs +0 -1830
  295. data/vendor/kreuzberg/src/extraction/pptx.rs +0 -3102
  296. data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
  297. data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
  298. data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
  299. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
  300. data/vendor/kreuzberg/src/ocr/processor.rs +0 -858
  301. data/vendor/kreuzberg/src/plugins/extractor.rs +0 -1042
  302. data/vendor/kreuzberg/src/plugins/processor.rs +0 -650
  303. data/vendor/kreuzberg/src/plugins/registry.rs +0 -1339
  304. data/vendor/kreuzberg/src/plugins/validator.rs +0 -967
  305. data/vendor/kreuzberg/src/text/token_reduction/core.rs +0 -832
  306. data/vendor/kreuzberg/src/types.rs +0 -1713
  307. data/vendor/kreuzberg/src/utils/string_pool.rs +0 -762
  308. data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
@@ -1,696 +0,0 @@
1
- //! Native EPUB extractor using permissive-licensed dependencies.
2
- //!
3
- //! This extractor provides native Rust-based EPUB extraction without GPL-licensed
4
- //! dependencies, extracting:
5
- //! - Metadata from OPF (Open Packaging Format) using Dublin Core standards
6
- //! - Content from XHTML files in spine order
7
- //! - Proper handling of EPUB2 and EPUB3 formats
8
- //!
9
- //! Uses only permissive-licensed crates:
10
- //! - `zip` (MIT/Apache) - for reading EPUB container
11
- //! - `roxmltree` (MIT) - for parsing XML
12
- //! - `html-to-markdown-rs` (MIT) - for converting XHTML to plain text
13
-
14
- use crate::Result;
15
- use crate::core::config::ExtractionConfig;
16
- use crate::plugins::{DocumentExtractor, Plugin};
17
- use crate::types::{ExtractionResult, Metadata};
18
- use async_trait::async_trait;
19
- use roxmltree;
20
- use std::collections::BTreeMap;
21
- use std::io::Cursor;
22
- use zip::ZipArchive;
23
-
24
- /// EPUB format extractor using permissive-licensed dependencies.
25
- ///
26
- /// Extracts content and metadata from EPUB files (both EPUB2 and EPUB3)
27
- /// using native Rust parsing without GPL-licensed dependencies.
28
- pub struct EpubExtractor;
29
-
30
- impl EpubExtractor {
31
- /// Create a new EPUB extractor.
32
- pub fn new() -> Self {
33
- Self
34
- }
35
-
36
- /// Extract text content from an EPUB document by reading in spine order
37
- fn extract_content(
38
- archive: &mut ZipArchive<Cursor<Vec<u8>>>,
39
- opf_path: &str,
40
- manifest_dir: &str,
41
- ) -> Result<String> {
42
- let opf_xml = Self::read_file_from_zip(archive, opf_path)?;
43
- let (_, spine_hrefs) = Self::parse_opf(&opf_xml)?;
44
-
45
- let mut content = String::new();
46
-
47
- for (index, href) in spine_hrefs.iter().enumerate() {
48
- let file_path = Self::resolve_path(manifest_dir, href);
49
-
50
- match Self::read_file_from_zip(archive, &file_path) {
51
- Ok(xhtml_content) => {
52
- let text = Self::extract_text_from_xhtml(&xhtml_content);
53
- if !text.is_empty() {
54
- if index > 0 && !content.ends_with('\n') {
55
- content.push('\n');
56
- }
57
- content.push_str(&text);
58
- content.push('\n');
59
- }
60
- }
61
- Err(_) => {
62
- continue;
63
- }
64
- }
65
- }
66
-
67
- Ok(content.trim().to_string())
68
- }
69
-
70
- /// Extract text from XHTML content using html-to-markdown-rs
71
- fn extract_text_from_xhtml(xhtml: &str) -> String {
72
- match crate::extraction::html::convert_html_to_markdown(xhtml, None) {
73
- Ok(markdown) => {
74
- let text = Self::markdown_to_plain_text(&markdown);
75
- Self::remove_html_comments(&text)
76
- }
77
- Err(_) => Self::strip_html_tags(xhtml),
78
- }
79
- }
80
-
81
- /// Remove HTML comments from text
82
- fn remove_html_comments(text: &str) -> String {
83
- let mut result = String::new();
84
- let mut in_comment = false;
85
- let mut chars = text.chars().peekable();
86
-
87
- while let Some(ch) = chars.next() {
88
- if !in_comment && ch == '<' {
89
- if chars.peek() == Some(&'!') {
90
- chars.next();
91
- if chars.peek() == Some(&'-') {
92
- chars.next();
93
- if chars.peek() == Some(&'-') {
94
- chars.next();
95
- in_comment = true;
96
- continue;
97
- } else {
98
- result.push('<');
99
- result.push('!');
100
- result.push('-');
101
- continue;
102
- }
103
- } else {
104
- result.push('<');
105
- result.push('!');
106
- continue;
107
- }
108
- } else {
109
- result.push(ch);
110
- }
111
- } else if in_comment {
112
- if ch == '-' && chars.peek() == Some(&'-') {
113
- chars.next();
114
- if chars.peek() == Some(&'>') {
115
- chars.next();
116
- in_comment = false;
117
- result.push('\n');
118
- }
119
- }
120
- } else {
121
- result.push(ch);
122
- }
123
- }
124
-
125
- result
126
- }
127
-
128
- /// Convert markdown output to plain text by removing markdown syntax
129
- fn markdown_to_plain_text(markdown: &str) -> String {
130
- let mut text = String::new();
131
- let mut in_code_block = false;
132
-
133
- for line in markdown.lines() {
134
- let trimmed = line.trim();
135
-
136
- if trimmed.is_empty() {
137
- if !text.is_empty() && !text.ends_with('\n') {
138
- text.push('\n');
139
- }
140
- continue;
141
- }
142
-
143
- if trimmed.starts_with("```") {
144
- in_code_block = !in_code_block;
145
- continue;
146
- }
147
-
148
- if in_code_block {
149
- text.push_str(trimmed);
150
- text.push('\n');
151
- continue;
152
- }
153
-
154
- let cleaned = if let Some(stripped) = trimmed.strip_prefix("- ").or_else(|| trimmed.strip_prefix("* ")) {
155
- stripped
156
- } else if let Some(stripped) = trimmed.strip_prefix(|c: char| c.is_ascii_digit()) {
157
- if let Some(rest) = stripped.strip_prefix(". ") {
158
- rest
159
- } else {
160
- trimmed
161
- }
162
- } else {
163
- trimmed
164
- };
165
-
166
- let cleaned = cleaned.trim_start_matches('#').trim();
167
-
168
- let cleaned = cleaned
169
- .replace("**", "")
170
- .replace("__", "")
171
- .replace("*", "")
172
- .replace("_", "");
173
-
174
- let cleaned = Self::remove_markdown_links(&cleaned);
175
-
176
- if !cleaned.is_empty() {
177
- text.push_str(&cleaned);
178
- text.push('\n');
179
- }
180
- }
181
-
182
- text.trim().to_string()
183
- }
184
-
185
- /// Remove markdown links [text](url) -> text
186
- fn remove_markdown_links(text: &str) -> String {
187
- let mut result = String::new();
188
- let mut chars = text.chars().peekable();
189
-
190
- while let Some(ch) = chars.next() {
191
- if ch == '[' {
192
- let mut link_text = String::new();
193
- let mut depth = 1;
194
-
195
- while let Some(&next_ch) = chars.peek() {
196
- chars.next();
197
- if next_ch == '[' {
198
- depth += 1;
199
- link_text.push(next_ch);
200
- } else if next_ch == ']' {
201
- depth -= 1;
202
- if depth == 0 {
203
- break;
204
- }
205
- link_text.push(next_ch);
206
- } else {
207
- link_text.push(next_ch);
208
- }
209
- }
210
-
211
- if let Some(&'(') = chars.peek() {
212
- chars.next();
213
- let mut paren_depth = 1;
214
- while let Some(&next_ch) = chars.peek() {
215
- chars.next();
216
- if next_ch == '(' {
217
- paren_depth += 1;
218
- } else if next_ch == ')' {
219
- paren_depth -= 1;
220
- if paren_depth == 0 {
221
- break;
222
- }
223
- }
224
- }
225
- }
226
-
227
- result.push_str(&link_text);
228
- } else {
229
- result.push(ch);
230
- }
231
- }
232
-
233
- result
234
- }
235
-
236
- /// Fallback: strip HTML tags without using specialized libraries
237
- fn strip_html_tags(html: &str) -> String {
238
- let mut text = String::new();
239
- let mut in_tag = false;
240
- let mut in_script_style = false;
241
- let mut tag_name = String::new();
242
-
243
- for ch in html.chars() {
244
- if ch == '<' {
245
- in_tag = true;
246
- tag_name.clear();
247
- continue;
248
- }
249
-
250
- if ch == '>' {
251
- in_tag = false;
252
-
253
- let tag_lower = tag_name.to_lowercase();
254
- if tag_lower.contains("script") || tag_lower.contains("style") {
255
- in_script_style = !tag_name.starts_with('/');
256
- }
257
- continue;
258
- }
259
-
260
- if in_tag {
261
- tag_name.push(ch);
262
- continue;
263
- }
264
-
265
- if in_script_style {
266
- continue;
267
- }
268
-
269
- if ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ' {
270
- if !text.is_empty() && !text.ends_with(' ') {
271
- text.push(' ');
272
- }
273
- } else {
274
- text.push(ch);
275
- }
276
- }
277
-
278
- let mut result = String::new();
279
- let mut prev_space = false;
280
- for ch in text.chars() {
281
- if ch == ' ' {
282
- if !prev_space {
283
- result.push(ch);
284
- }
285
- prev_space = true;
286
- } else {
287
- result.push(ch);
288
- prev_space = false;
289
- }
290
- }
291
-
292
- result.trim().to_string()
293
- }
294
-
295
- /// Extract metadata from EPUB OPF file
296
- fn extract_metadata(opf_xml: &str) -> Result<(OepbMetadata, BTreeMap<String, serde_json::Value>)> {
297
- let mut additional_metadata = BTreeMap::new();
298
-
299
- let (epub_metadata, _) = Self::parse_opf(opf_xml)?;
300
-
301
- if let Some(identifier) = epub_metadata.identifier.clone() {
302
- additional_metadata.insert("identifier".to_string(), serde_json::json!(identifier));
303
- }
304
-
305
- if let Some(publisher) = epub_metadata.publisher.clone() {
306
- additional_metadata.insert("publisher".to_string(), serde_json::json!(publisher));
307
- }
308
-
309
- if let Some(subject) = epub_metadata.subject.clone() {
310
- additional_metadata.insert("subject".to_string(), serde_json::json!(subject));
311
- }
312
-
313
- if let Some(description) = epub_metadata.description.clone() {
314
- additional_metadata.insert("description".to_string(), serde_json::json!(description));
315
- }
316
-
317
- if let Some(rights) = epub_metadata.rights.clone() {
318
- additional_metadata.insert("rights".to_string(), serde_json::json!(rights));
319
- }
320
-
321
- Ok((epub_metadata, additional_metadata))
322
- }
323
-
324
- /// Parse container.xml to find the OPF file path
325
- fn parse_container_xml(xml: &str) -> Result<String> {
326
- match roxmltree::Document::parse(xml) {
327
- Ok(doc) => {
328
- for node in doc.descendants() {
329
- if node.tag_name().name() == "rootfile"
330
- && let Some(full_path) = node.attribute("full-path")
331
- {
332
- return Ok(full_path.to_string());
333
- }
334
- }
335
- Err(crate::KreuzbergError::Parsing {
336
- message: "No rootfile found in container.xml".to_string(),
337
- source: None,
338
- })
339
- }
340
- Err(e) => Err(crate::KreuzbergError::Parsing {
341
- message: format!("Failed to parse container.xml: {}", e),
342
- source: None,
343
- }),
344
- }
345
- }
346
-
347
- /// Parse OPF file and extract metadata and spine order
348
- fn parse_opf(xml: &str) -> Result<(OepbMetadata, Vec<String>)> {
349
- match roxmltree::Document::parse(xml) {
350
- Ok(doc) => {
351
- let root = doc.root();
352
-
353
- let mut metadata = OepbMetadata::default();
354
- let mut manifest: BTreeMap<String, String> = BTreeMap::new();
355
- let mut spine_order: Vec<String> = Vec::new();
356
-
357
- for node in root.descendants() {
358
- match node.tag_name().name() {
359
- "title" => {
360
- if let Some(text) = node.text() {
361
- metadata.title = Some(text.trim().to_string());
362
- }
363
- }
364
- "creator" => {
365
- if let Some(text) = node.text() {
366
- metadata.creator = Some(text.trim().to_string());
367
- }
368
- }
369
- "date" => {
370
- if let Some(text) = node.text() {
371
- metadata.date = Some(text.trim().to_string());
372
- }
373
- }
374
- "language" => {
375
- if let Some(text) = node.text() {
376
- metadata.language = Some(text.trim().to_string());
377
- }
378
- }
379
- "identifier" => {
380
- if let Some(text) = node.text() {
381
- metadata.identifier = Some(text.trim().to_string());
382
- }
383
- }
384
- "publisher" => {
385
- if let Some(text) = node.text() {
386
- metadata.publisher = Some(text.trim().to_string());
387
- }
388
- }
389
- "subject" => {
390
- if let Some(text) = node.text() {
391
- metadata.subject = Some(text.trim().to_string());
392
- }
393
- }
394
- "description" => {
395
- if let Some(text) = node.text() {
396
- metadata.description = Some(text.trim().to_string());
397
- }
398
- }
399
- "rights" => {
400
- if let Some(text) = node.text() {
401
- metadata.rights = Some(text.trim().to_string());
402
- }
403
- }
404
- "item" => {
405
- if let Some(id) = node.attribute("id")
406
- && let Some(href) = node.attribute("href")
407
- {
408
- manifest.insert(id.to_string(), href.to_string());
409
- }
410
- }
411
- _ => {}
412
- }
413
- }
414
-
415
- for node in root.descendants() {
416
- if node.tag_name().name() == "itemref"
417
- && let Some(idref) = node.attribute("idref")
418
- && let Some(href) = manifest.get(idref)
419
- {
420
- spine_order.push(href.clone());
421
- }
422
- }
423
-
424
- Ok((metadata, spine_order))
425
- }
426
- Err(e) => Err(crate::KreuzbergError::Parsing {
427
- message: format!("Failed to parse OPF file: {}", e),
428
- source: None,
429
- }),
430
- }
431
- }
432
-
433
- /// Read a file from the ZIP archive
434
- fn read_file_from_zip(archive: &mut ZipArchive<Cursor<Vec<u8>>>, path: &str) -> Result<String> {
435
- match archive.by_name(path) {
436
- Ok(mut file) => {
437
- let mut content = String::new();
438
- match std::io::Read::read_to_string(&mut file, &mut content) {
439
- Ok(_) => Ok(content),
440
- Err(e) => Err(crate::KreuzbergError::Parsing {
441
- message: format!("Failed to read file from EPUB: {}", e),
442
- source: None,
443
- }),
444
- }
445
- }
446
- Err(e) => Err(crate::KreuzbergError::Parsing {
447
- message: format!("File not found in EPUB: {} ({})", path, e),
448
- source: None,
449
- }),
450
- }
451
- }
452
-
453
- /// Resolve a relative path within the manifest directory
454
- fn resolve_path(base_dir: &str, relative_path: &str) -> String {
455
- if relative_path.starts_with('/') {
456
- relative_path.trim_start_matches('/').to_string()
457
- } else if base_dir.is_empty() || base_dir == "." {
458
- relative_path.to_string()
459
- } else {
460
- format!("{}/{}", base_dir.trim_end_matches('/'), relative_path)
461
- }
462
- }
463
- }
464
-
465
- /// Metadata extracted from OPF (Open Packaging Format) file
466
- #[derive(Debug, Default, Clone)]
467
- struct OepbMetadata {
468
- title: Option<String>,
469
- creator: Option<String>,
470
- date: Option<String>,
471
- language: Option<String>,
472
- identifier: Option<String>,
473
- publisher: Option<String>,
474
- subject: Option<String>,
475
- description: Option<String>,
476
- rights: Option<String>,
477
- }
478
-
479
- impl Default for EpubExtractor {
480
- fn default() -> Self {
481
- Self::new()
482
- }
483
- }
484
-
485
- impl Plugin for EpubExtractor {
486
- fn name(&self) -> &str {
487
- "epub-extractor"
488
- }
489
-
490
- fn version(&self) -> String {
491
- env!("CARGO_PKG_VERSION").to_string()
492
- }
493
-
494
- fn initialize(&self) -> Result<()> {
495
- Ok(())
496
- }
497
-
498
- fn shutdown(&self) -> Result<()> {
499
- Ok(())
500
- }
501
-
502
- fn description(&self) -> &str {
503
- "Extracts content and metadata from EPUB documents (native Rust implementation with permissive licenses)"
504
- }
505
-
506
- fn author(&self) -> &str {
507
- "Kreuzberg Team"
508
- }
509
- }
510
-
511
- #[cfg(feature = "office")]
512
- #[async_trait]
513
- impl DocumentExtractor for EpubExtractor {
514
- #[cfg_attr(
515
- feature = "otel",
516
- tracing::instrument(
517
- skip(self, content, _config),
518
- fields(
519
- extractor.name = self.name(),
520
- content.size_bytes = content.len(),
521
- )
522
- )
523
- )]
524
- async fn extract_bytes(
525
- &self,
526
- content: &[u8],
527
- mime_type: &str,
528
- _config: &ExtractionConfig,
529
- ) -> Result<ExtractionResult> {
530
- let cursor = Cursor::new(content.to_vec());
531
-
532
- let mut archive = ZipArchive::new(cursor).map_err(|e| crate::KreuzbergError::Parsing {
533
- message: format!("Failed to open EPUB as ZIP: {}", e),
534
- source: None,
535
- })?;
536
-
537
- let container_xml = Self::read_file_from_zip(&mut archive, "META-INF/container.xml")?;
538
- let opf_path = Self::parse_container_xml(&container_xml)?;
539
-
540
- let manifest_dir = if let Some(last_slash) = opf_path.rfind('/') {
541
- opf_path[..last_slash].to_string()
542
- } else {
543
- String::new()
544
- };
545
-
546
- let opf_xml = Self::read_file_from_zip(&mut archive, &opf_path)?;
547
-
548
- let extracted_content = Self::extract_content(&mut archive, &opf_path, &manifest_dir)?;
549
-
550
- let (epub_metadata, additional_metadata) = Self::extract_metadata(&opf_xml)?;
551
- let metadata_map: std::collections::HashMap<String, serde_json::Value> =
552
- additional_metadata.into_iter().collect();
553
-
554
- Ok(ExtractionResult {
555
- content: extracted_content,
556
- mime_type: mime_type.to_string(),
557
- metadata: Metadata {
558
- title: epub_metadata.title,
559
- authors: epub_metadata.creator.map(|c| vec![c]),
560
- language: epub_metadata.language,
561
- created_at: epub_metadata.date,
562
- additional: metadata_map,
563
- ..Default::default()
564
- },
565
- pages: None,
566
- tables: vec![],
567
- detected_languages: None,
568
- chunks: None,
569
- images: None,
570
- })
571
- }
572
-
573
- fn supported_mime_types(&self) -> &[&str] {
574
- &[
575
- "application/epub+zip",
576
- "application/x-epub+zip",
577
- "application/vnd.epub+zip",
578
- ]
579
- }
580
-
581
- fn priority(&self) -> i32 {
582
- 60
583
- }
584
- }
585
-
586
- #[cfg(all(test, feature = "office"))]
587
- mod tests {
588
- use super::*;
589
-
590
- #[test]
591
- fn test_epub_extractor_plugin_interface() {
592
- let extractor = EpubExtractor::new();
593
- assert_eq!(extractor.name(), "epub-extractor");
594
- assert_eq!(extractor.version(), env!("CARGO_PKG_VERSION"));
595
- assert_eq!(extractor.priority(), 60);
596
- assert!(!extractor.supported_mime_types().is_empty());
597
- }
598
-
599
- #[test]
600
- fn test_epub_extractor_default() {
601
- let extractor = EpubExtractor;
602
- assert_eq!(extractor.name(), "epub-extractor");
603
- }
604
-
605
- #[tokio::test]
606
- async fn test_epub_extractor_initialize_shutdown() {
607
- let extractor = EpubExtractor::new();
608
- assert!(extractor.initialize().is_ok());
609
- assert!(extractor.shutdown().is_ok());
610
- }
611
-
612
- #[test]
613
- fn test_strip_html_tags_simple() {
614
- let html = "<html><body><p>Hello World</p></body></html>";
615
- let text = EpubExtractor::strip_html_tags(html);
616
- assert!(text.contains("Hello World"));
617
- }
618
-
619
- #[test]
620
- fn test_strip_html_tags_with_scripts() {
621
- let html = "<body><p>Text</p><script>alert('bad');</script><p>More</p></body>";
622
- let text = EpubExtractor::strip_html_tags(html);
623
- assert!(!text.contains("bad"));
624
- assert!(text.contains("Text"));
625
- assert!(text.contains("More"));
626
- }
627
-
628
- #[test]
629
- fn test_strip_html_tags_with_styles() {
630
- let html = "<body><p>Text</p><style>.class { color: red; }</style><p>More</p></body>";
631
- let text = EpubExtractor::strip_html_tags(html);
632
- assert!(!text.to_lowercase().contains("color"));
633
- assert!(text.contains("Text"));
634
- assert!(text.contains("More"));
635
- }
636
-
637
- #[test]
638
- fn test_strip_html_tags_normalizes_whitespace() {
639
- let html = "<p>Hello \n\t World</p>";
640
- let text = EpubExtractor::strip_html_tags(html);
641
- assert!(text.contains("Hello") && text.contains("World"));
642
- }
643
-
644
- #[test]
645
- fn test_remove_markdown_links() {
646
- let text = "This is a [link](http://example.com) in text";
647
- let result = EpubExtractor::remove_markdown_links(text);
648
- assert!(result.contains("link"));
649
- assert!(!result.contains("http://"));
650
- }
651
-
652
- #[test]
653
- fn test_resolve_path_with_base_dir() {
654
- let result = EpubExtractor::resolve_path("OEBPS", "chapter.xhtml");
655
- assert_eq!(result, "OEBPS/chapter.xhtml");
656
- }
657
-
658
- #[test]
659
- fn test_resolve_path_absolute() {
660
- let result = EpubExtractor::resolve_path("OEBPS", "/chapter.xhtml");
661
- assert_eq!(result, "chapter.xhtml");
662
- }
663
-
664
- #[test]
665
- fn test_resolve_path_empty_base() {
666
- let result = EpubExtractor::resolve_path("", "chapter.xhtml");
667
- assert_eq!(result, "chapter.xhtml");
668
- }
669
-
670
- #[test]
671
- fn test_epub_extractor_supported_mime_types() {
672
- let extractor = EpubExtractor::new();
673
- let supported = extractor.supported_mime_types();
674
- assert!(supported.contains(&"application/epub+zip"));
675
- assert!(supported.contains(&"application/x-epub+zip"));
676
- assert!(supported.contains(&"application/vnd.epub+zip"));
677
- }
678
-
679
- #[test]
680
- fn test_markdown_to_plain_text_removes_formatting() {
681
- let markdown = "# Heading\n\nThis is **bold** text with _italic_ emphasis.";
682
- let result = EpubExtractor::markdown_to_plain_text(markdown);
683
- assert!(result.contains("Heading"));
684
- assert!(result.contains("bold"));
685
- assert!(!result.contains("**"));
686
- }
687
-
688
- #[test]
689
- fn test_markdown_to_plain_text_removes_list_markers() {
690
- let markdown = "- Item 1\n- Item 2\n* Item 3";
691
- let result = EpubExtractor::markdown_to_plain_text(markdown);
692
- assert!(result.contains("Item 1"));
693
- assert!(result.contains("Item 2"));
694
- assert!(result.contains("Item 3"));
695
- }
696
- }