docvortex 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. docvortex/__init__.py +21 -0
  2. docvortex/analyzers/__init__.py +3 -0
  3. docvortex/analyzers/native/__init__.py +37 -0
  4. docvortex/analyzers/native/_shared/__init__.py +3 -0
  5. docvortex/analyzers/native/_shared/hyperlink.py +16 -0
  6. docvortex/analyzers/native/_shared/image.py +8 -0
  7. docvortex/analyzers/native/_shared/markup/__init__.py +47 -0
  8. docvortex/analyzers/native/_shared/markup/anchors.py +30 -0
  9. docvortex/analyzers/native/_shared/markup/formula.py +37 -0
  10. docvortex/analyzers/native/_shared/markup/projector.py +57 -0
  11. docvortex/analyzers/native/_shared/markup/styles.py +19 -0
  12. docvortex/analyzers/native/_shared/mathml.py +17 -0
  13. docvortex/analyzers/native/_shared/names.py +7 -0
  14. docvortex/analyzers/native/_shared/xycut.py +414 -0
  15. docvortex/analyzers/native/contracts.py +44 -0
  16. docvortex/analyzers/native/csv.py +351 -0
  17. docvortex/analyzers/native/epub/__init__.py +18 -0
  18. docvortex/analyzers/native/epub/constants.py +45 -0
  19. docvortex/analyzers/native/epub/converter.py +80 -0
  20. docvortex/analyzers/native/epub/errors.py +20 -0
  21. docvortex/analyzers/native/epub/metadata.py +31 -0
  22. docvortex/analyzers/native/epub/package.py +649 -0
  23. docvortex/analyzers/native/epub/xhtml.py +306 -0
  24. docvortex/analyzers/native/html/__init__.py +6 -0
  25. docvortex/analyzers/native/html/anchors.py +271 -0
  26. docvortex/analyzers/native/html/constants.py +25 -0
  27. docvortex/analyzers/native/html/contracts.py +7 -0
  28. docvortex/analyzers/native/html/converter.py +117 -0
  29. docvortex/analyzers/native/html/document.py +389 -0
  30. docvortex/analyzers/native/html/errors.py +12 -0
  31. docvortex/analyzers/native/html/resources.py +365 -0
  32. docvortex/analyzers/native/html/selector.py +421 -0
  33. docvortex/analyzers/native/models.py +209 -0
  34. docvortex/analyzers/native/ofd/__init__.py +14 -0
  35. docvortex/analyzers/native/ofd/constants.py +59 -0
  36. docvortex/analyzers/native/ofd/converter.py +31 -0
  37. docvortex/analyzers/native/ofd/errors.py +16 -0
  38. docvortex/analyzers/native/ofd/geometry.py +215 -0
  39. docvortex/analyzers/native/ofd/images.py +124 -0
  40. docvortex/analyzers/native/ofd/metadata.py +53 -0
  41. docvortex/analyzers/native/ofd/models.py +170 -0
  42. docvortex/analyzers/native/ofd/package.py +346 -0
  43. docvortex/analyzers/native/ofd/path.py +201 -0
  44. docvortex/analyzers/native/ofd/reading_order.py +293 -0
  45. docvortex/analyzers/native/ofd/resources.py +122 -0
  46. docvortex/analyzers/native/ofd/scene.py +347 -0
  47. docvortex/analyzers/native/ofd/table.py +240 -0
  48. docvortex/analyzers/native/ofd/text.py +521 -0
  49. docvortex/analyzers/native/office/__init__.py +3 -0
  50. docvortex/analyzers/native/office/doc/__init__.py +3 -0
  51. docvortex/analyzers/native/office/doc/bookmarks.py +81 -0
  52. docvortex/analyzers/native/office/doc/doc_converter.py +573 -0
  53. docvortex/analyzers/native/office/doc/fib.py +261 -0
  54. docvortex/analyzers/native/office/doc/fields.py +101 -0
  55. docvortex/analyzers/native/office/doc/formatting.py +171 -0
  56. docvortex/analyzers/native/office/doc/images.py +162 -0
  57. docvortex/analyzers/native/office/doc/lists.py +356 -0
  58. docvortex/analyzers/native/office/doc/models.py +164 -0
  59. docvortex/analyzers/native/office/doc/parser.py +851 -0
  60. docvortex/analyzers/native/office/doc/pieces.py +256 -0
  61. docvortex/analyzers/native/office/doc/records.py +40 -0
  62. docvortex/analyzers/native/office/doc/sprm.py +269 -0
  63. docvortex/analyzers/native/office/doc/styles.py +215 -0
  64. docvortex/analyzers/native/office/docx/__init__.py +3 -0
  65. docvortex/analyzers/native/office/docx/context.py +71 -0
  66. docvortex/analyzers/native/office/docx/docx_converter.py +614 -0
  67. docvortex/analyzers/native/office/docx/equationxml.py +119 -0
  68. docvortex/analyzers/native/office/docx/fields.py +816 -0
  69. docvortex/analyzers/native/office/docx/formatting_types.py +23 -0
  70. docvortex/analyzers/native/office/docx/main.py +50 -0
  71. docvortex/analyzers/native/office/docx/numbering.py +491 -0
  72. docvortex/analyzers/native/office/docx/office_xml.py +57 -0
  73. docvortex/analyzers/native/office/docx/package_normalizer.py +248 -0
  74. docvortex/analyzers/native/office/docx/resources.py +526 -0
  75. docvortex/analyzers/native/office/docx/styles.py +693 -0
  76. docvortex/analyzers/native/office/docx/tables.py +515 -0
  77. docvortex/analyzers/native/office/equation/__init__.py +3 -0
  78. docvortex/analyzers/native/office/equation/image.py +470 -0
  79. docvortex/analyzers/native/office/equation/latex_dict.py +324 -0
  80. docvortex/analyzers/native/office/equation/mtef.py +885 -0
  81. docvortex/analyzers/native/office/equation/mtef_v5.py +941 -0
  82. docvortex/analyzers/native/office/equation/omml.py +561 -0
  83. docvortex/analyzers/native/office/equation/ooxml.py +62 -0
  84. docvortex/analyzers/native/office/errors.py +33 -0
  85. docvortex/analyzers/native/office/image.py +307 -0
  86. docvortex/analyzers/native/office/legacy/__init__.py +3 -0
  87. docvortex/analyzers/native/office/legacy/binary.py +43 -0
  88. docvortex/analyzers/native/office/legacy/officeart.py +362 -0
  89. docvortex/analyzers/native/office/legacy/ole.py +110 -0
  90. docvortex/analyzers/native/office/limits.py +12 -0
  91. docvortex/analyzers/native/office/odf/__init__.py +3 -0
  92. docvortex/analyzers/native/office/odf/chart.py +76 -0
  93. docvortex/analyzers/native/office/odf/constants.py +70 -0
  94. docvortex/analyzers/native/office/odf/converters.py +403 -0
  95. docvortex/analyzers/native/office/odf/errors.py +18 -0
  96. docvortex/analyzers/native/office/odf/metadata.py +91 -0
  97. docvortex/analyzers/native/office/odf/models.py +176 -0
  98. docvortex/analyzers/native/office/odf/package.py +270 -0
  99. docvortex/analyzers/native/office/odf/styles.py +329 -0
  100. docvortex/analyzers/native/office/odf/table.py +469 -0
  101. docvortex/analyzers/native/office/odf/text.py +1002 -0
  102. docvortex/analyzers/native/office/ooxml_chart.py +1016 -0
  103. docvortex/analyzers/native/office/opc.py +38 -0
  104. docvortex/analyzers/native/office/ppt/__init__.py +3 -0
  105. docvortex/analyzers/native/office/ppt/models.py +118 -0
  106. docvortex/analyzers/native/office/ppt/parser.py +1895 -0
  107. docvortex/analyzers/native/office/ppt/ppt_converter.py +292 -0
  108. docvortex/analyzers/native/office/ppt/records.py +131 -0
  109. docvortex/analyzers/native/office/ppt/style_text.py +247 -0
  110. docvortex/analyzers/native/office/pptx/__init__.py +3 -0
  111. docvortex/analyzers/native/office/pptx/context.py +113 -0
  112. docvortex/analyzers/native/office/pptx/lists.py +558 -0
  113. docvortex/analyzers/native/office/pptx/main.py +20 -0
  114. docvortex/analyzers/native/office/pptx/package_normalizer.py +321 -0
  115. docvortex/analyzers/native/office/pptx/pptx_converter.py +323 -0
  116. docvortex/analyzers/native/office/pptx/resources.py +329 -0
  117. docvortex/analyzers/native/office/pptx/shapes.py +393 -0
  118. docvortex/analyzers/native/office/pptx/text_styles.py +625 -0
  119. docvortex/analyzers/native/office/pptx/titles.py +178 -0
  120. docvortex/analyzers/native/office/rich_text.py +420 -0
  121. docvortex/analyzers/native/office/rtf/__init__.py +3 -0
  122. docvortex/analyzers/native/office/rtf/converter.py +708 -0
  123. docvortex/analyzers/native/office/rtf/lexer.py +213 -0
  124. docvortex/analyzers/native/office/rtf/math.py +339 -0
  125. docvortex/analyzers/native/office/rtf/models.py +185 -0
  126. docvortex/analyzers/native/office/rtf/parser.py +1553 -0
  127. docvortex/analyzers/native/office/spreadsheet/__init__.py +3 -0
  128. docvortex/analyzers/native/office/spreadsheet/html.py +81 -0
  129. docvortex/analyzers/native/office/spreadsheet/models.py +79 -0
  130. docvortex/analyzers/native/office/spreadsheet/projector.py +928 -0
  131. docvortex/analyzers/native/office/streams.py +18 -0
  132. docvortex/analyzers/native/office/xls/__init__.py +3 -0
  133. docvortex/analyzers/native/office/xls/chart.py +132 -0
  134. docvortex/analyzers/native/office/xls/embedded_chart.py +299 -0
  135. docvortex/analyzers/native/office/xls/models.py +109 -0
  136. docvortex/analyzers/native/office/xls/number_format.py +521 -0
  137. docvortex/analyzers/native/office/xls/parser.py +1145 -0
  138. docvortex/analyzers/native/office/xls/records.py +201 -0
  139. docvortex/analyzers/native/office/xls/strings.py +205 -0
  140. docvortex/analyzers/native/office/xls/xls_converter.py +354 -0
  141. docvortex/analyzers/native/office/xlsx/__init__.py +3 -0
  142. docvortex/analyzers/native/office/xlsx/main.py +20 -0
  143. docvortex/analyzers/native/office/xlsx/ooxml_ole.py +522 -0
  144. docvortex/analyzers/native/office/xlsx/package_normalizer.py +310 -0
  145. docvortex/analyzers/native/office/xlsx/xlsx_converter.py +716 -0
  146. docvortex/analyzers/native/pdf/__init__.py +3 -0
  147. docvortex/analyzers/native/pdf/auxiliary_text.py +1671 -0
  148. docvortex/analyzers/native/pdf/char_geometry.py +1662 -0
  149. docvortex/analyzers/native/pdf/code_blocks.py +535 -0
  150. docvortex/analyzers/native/pdf/formulas.py +1985 -0
  151. docvortex/analyzers/native/pdf/geometry.py +281 -0
  152. docvortex/analyzers/native/pdf/graphics.py +1501 -0
  153. docvortex/analyzers/native/pdf/index_blocks.py +268 -0
  154. docvortex/analyzers/native/pdf/inline/__init__.py +3 -0
  155. docvortex/analyzers/native/pdf/inline/common.py +112 -0
  156. docvortex/analyzers/native/pdf/inline/detection.py +590 -0
  157. docvortex/analyzers/native/pdf/inline/matching.py +1185 -0
  158. docvortex/analyzers/native/pdf/inline/materialize.py +457 -0
  159. docvortex/analyzers/native/pdf/inline/scripts.py +975 -0
  160. docvortex/analyzers/native/pdf/inline/types.py +385 -0
  161. docvortex/analyzers/native/pdf/line_layout.py +1106 -0
  162. docvortex/analyzers/native/pdf/line_merging.py +1223 -0
  163. docvortex/analyzers/native/pdf/models.py +246 -0
  164. docvortex/analyzers/native/pdf/native_text.py +1004 -0
  165. docvortex/analyzers/native/pdf/pipeline.py +1390 -0
  166. docvortex/analyzers/native/pdf/script_geometry.py +636 -0
  167. docvortex/analyzers/native/pdf/shared.py +30 -0
  168. docvortex/analyzers/native/pdf/spatial_text.py +383 -0
  169. docvortex/analyzers/native/pdf/table_annotations.py +446 -0
  170. docvortex/analyzers/native/pdf/table_constants.py +48 -0
  171. docvortex/analyzers/native/pdf/table_detection.py +227 -0
  172. docvortex/analyzers/native/pdf/table_filled_grid.py +218 -0
  173. docvortex/analyzers/native/pdf/table_geometry.py +40 -0
  174. docvortex/analyzers/native/pdf/table_materialization.py +444 -0
  175. docvortex/analyzers/native/pdf/table_recovery/__init__.py +15 -0
  176. docvortex/analyzers/native/pdf/table_recovery/candidate.py +356 -0
  177. docvortex/analyzers/native/pdf/table_recovery/contracts.py +154 -0
  178. docvortex/analyzers/native/pdf/table_recovery/engine.py +609 -0
  179. docvortex/analyzers/native/pdf/table_recovery/geometry.py +164 -0
  180. docvortex/analyzers/native/pdf/table_recovery/sparse_common.py +85 -0
  181. docvortex/analyzers/native/pdf/table_recovery/sparse_hybrid.py +804 -0
  182. docvortex/analyzers/native/pdf/table_recovery/sparse_multiline.py +1122 -0
  183. docvortex/analyzers/native/pdf/table_recovery/text.py +414 -0
  184. docvortex/analyzers/native/pdf/table_recovery/text_grid.py +618 -0
  185. docvortex/analyzers/native/pdf/table_recovery/vector.py +1931 -0
  186. docvortex/analyzers/native/pdf/table_rows.py +34 -0
  187. docvortex/analyzers/native/pdf/table_rules.py +1129 -0
  188. docvortex/analyzers/native/pdf/table_text_styles.py +283 -0
  189. docvortex/analyzers/native/pdf/tables.py +147 -0
  190. docvortex/analyzers/native/pdf/text_assembly/__init__.py +3 -0
  191. docvortex/analyzers/native/pdf/text_assembly/annotations.py +581 -0
  192. docvortex/analyzers/native/pdf/text_assembly/assembly.py +292 -0
  193. docvortex/analyzers/native/pdf/text_assembly/common.py +477 -0
  194. docvortex/analyzers/native/pdf/text_assembly/footnotes.py +394 -0
  195. docvortex/analyzers/native/pdf/text_assembly/merging.py +1274 -0
  196. docvortex/analyzers/native/pdf/text_assembly/rows.py +692 -0
  197. docvortex/analyzers/native/pdf/text_blocks.py +82 -0
  198. docvortex/analyzers/native/pdf/text_styles.py +55 -0
  199. docvortex/analyzers/native/pdf/title_analysis/__init__.py +3 -0
  200. docvortex/analyzers/native/pdf/title_analysis/body_profile.py +215 -0
  201. docvortex/analyzers/native/pdf/title_analysis/common.py +117 -0
  202. docvortex/analyzers/native/pdf/title_analysis/document_profile.py +164 -0
  203. docvortex/analyzers/native/pdf/title_analysis/lane_titles.py +758 -0
  204. docvortex/analyzers/native/pdf/title_analysis/page_titles.py +1024 -0
  205. docvortex/analyzers/native/pdf/title_analysis/prototype.py +194 -0
  206. docvortex/analyzers/native/pdf/title_analysis/structural.py +1081 -0
  207. docvortex/analyzers/native/pdf/titles.py +75 -0
  208. docvortex/analyzers/native/pdf/typography.py +19 -0
  209. docvortex/analyzers/native/pdf/visual_annotations.py +1262 -0
  210. docvortex/api.py +180 -0
  211. docvortex/assets/__init__.py +5 -0
  212. docvortex/assets/store.py +51 -0
  213. docvortex/cli.py +54 -0
  214. docvortex/codecs/__init__.py +3 -0
  215. docvortex/codecs/html/__init__.py +22 -0
  216. docvortex/codecs/html/contracts.py +236 -0
  217. docvortex/codecs/html/materializer.py +331 -0
  218. docvortex/codecs/html/parser.py +763 -0
  219. docvortex/codecs/html/resources.py +34 -0
  220. docvortex/codecs/json.py +17 -0
  221. docvortex/content/__init__.py +5 -0
  222. docvortex/content/inline.py +248 -0
  223. docvortex/content/markup/__init__.py +44 -0
  224. docvortex/content/markup/anchors.py +188 -0
  225. docvortex/content/markup/formula.py +280 -0
  226. docvortex/content/markup/projector.py +1237 -0
  227. docvortex/content/markup/styles.py +327 -0
  228. docvortex/content/mathml.py +167 -0
  229. docvortex/content/normalization.py +188 -0
  230. docvortex/content/spans.py +183 -0
  231. docvortex/content/table/__init__.py +18 -0
  232. docvortex/content/table/blocks.py +152 -0
  233. docvortex/content/table/content.py +425 -0
  234. docvortex/content/table/document.py +104 -0
  235. docvortex/content/table/html.py +399 -0
  236. docvortex/content/table/models.py +76 -0
  237. docvortex/content/table/rules.py +42 -0
  238. docvortex/content/table/structure.py +221 -0
  239. docvortex/content/tree.py +5 -0
  240. docvortex/document/__init__.py +3 -0
  241. docvortex/document/contracts.py +22 -0
  242. docvortex/document/detection.py +389 -0
  243. docvortex/document/filetypes.py +175 -0
  244. docvortex/document/page_range.py +167 -0
  245. docvortex/document/pdf/__init__.py +19 -0
  246. docvortex/document/pdf/classify.py +1138 -0
  247. docvortex/document/pdf/constants.py +132 -0
  248. docvortex/document/pdf/diagnostics.py +350 -0
  249. docvortex/document/pdf/document.py +582 -0
  250. docvortex/document/pdf/font_runtime.py +335 -0
  251. docvortex/document/pdf/geometry.py +31 -0
  252. docvortex/document/pdf/images.py +654 -0
  253. docvortex/document/pdf/native_annotations.py +367 -0
  254. docvortex/document/pdf/native_contracts.py +169 -0
  255. docvortex/document/pdf/native_coordinates.py +216 -0
  256. docvortex/document/pdf/native_lifecycle.py +16 -0
  257. docvortex/document/pdf/native_objects.py +902 -0
  258. docvortex/document/pdf/native_text_geometry.py +315 -0
  259. docvortex/document/pdf/pdfium.py +325 -0
  260. docvortex/document/pdf/raster.py +46 -0
  261. docvortex/document/pdf/text/__init__.py +62 -0
  262. docvortex/document/pdf/text/contracts.py +211 -0
  263. docvortex/document/pdf/text/extract.py +165 -0
  264. docvortex/document/pdf/text/geometry.py +16 -0
  265. docvortex/document/pdf/text/groups.py +162 -0
  266. docvortex/document/pdf/visual_geometry.py +201 -0
  267. docvortex/document/pdf/visuals.py +343 -0
  268. docvortex/document/source.py +92 -0
  269. docvortex/errors.py +21 -0
  270. docvortex/export/__init__.py +3 -0
  271. docvortex/export/bundle.py +98 -0
  272. docvortex/export/files.py +66 -0
  273. docvortex/export/middle.py +208 -0
  274. docvortex/foundation/__init__.py +3 -0
  275. docvortex/foundation/geometry.py +125 -0
  276. docvortex/foundation/hyperlink.py +65 -0
  277. docvortex/foundation/image.py +48 -0
  278. docvortex/foundation/image_encoding.py +30 -0
  279. docvortex/foundation/image_payload.py +280 -0
  280. docvortex/foundation/language.py +92 -0
  281. docvortex/foundation/platform.py +38 -0
  282. docvortex/foundation/text.py +153 -0
  283. docvortex/foundation/type_identity.py +20 -0
  284. docvortex/foundation/xml_names.py +20 -0
  285. docvortex/options.py +30 -0
  286. docvortex/postprocess/__init__.py +3 -0
  287. docvortex/postprocess/content.py +53 -0
  288. docvortex/postprocess/document.py +19 -0
  289. docvortex/postprocess/lists.py +236 -0
  290. docvortex/postprocess/page_blocks.py +214 -0
  291. docvortex/postprocess/pages.py +95 -0
  292. docvortex/postprocess/paragraphs.py +580 -0
  293. docvortex/postprocess/visual.py +715 -0
  294. docvortex/render/__init__.py +48 -0
  295. docvortex/render/_internal/__init__.py +3 -0
  296. docvortex/render/_internal/common/__init__.py +3 -0
  297. docvortex/render/_internal/common/context.py +43 -0
  298. docvortex/render/_internal/common/html_table.py +178 -0
  299. docvortex/render/_internal/common/index.py +33 -0
  300. docvortex/render/_internal/common/list_items.py +158 -0
  301. docvortex/render/_internal/common/planner.py +140 -0
  302. docvortex/render/_internal/docx/__init__.py +3 -0
  303. docvortex/render/_internal/docx/assets.py +202 -0
  304. docvortex/render/_internal/docx/inline.py +434 -0
  305. docvortex/render/_internal/docx/math.py +220 -0
  306. docvortex/render/_internal/docx/renderer.py +905 -0
  307. docvortex/render/_internal/docx/styles.py +195 -0
  308. docvortex/render/_internal/docx/table.py +442 -0
  309. docvortex/render/_internal/epub/__init__.py +5 -0
  310. docvortex/render/_internal/epub/assets.py +173 -0
  311. docvortex/render/_internal/epub/package.py +249 -0
  312. docvortex/render/_internal/epub/renderer.py +1156 -0
  313. docvortex/render/_internal/html/__init__.py +3 -0
  314. docvortex/render/_internal/html/inline.py +346 -0
  315. docvortex/render/_internal/html/renderer.py +1041 -0
  316. docvortex/render/_internal/html/sanitizer.py +478 -0
  317. docvortex/render/_internal/html/table.py +121 -0
  318. docvortex/render/_internal/latex/__init__.py +1 -0
  319. docvortex/render/_internal/latex/assets.py +85 -0
  320. docvortex/render/_internal/latex/inline.py +145 -0
  321. docvortex/render/_internal/latex/renderer.py +506 -0
  322. docvortex/render/_internal/latex/table.py +347 -0
  323. docvortex/render/_internal/markdown/__init__.py +3 -0
  324. docvortex/render/_internal/markdown/assets.py +78 -0
  325. docvortex/render/_internal/markdown/blocks.py +635 -0
  326. docvortex/render/_internal/markdown/escaping.py +51 -0
  327. docvortex/render/_internal/markdown/inline.py +260 -0
  328. docvortex/render/_internal/markdown/renderer.py +93 -0
  329. docvortex/render/_internal/markdown/table.py +281 -0
  330. docvortex/render/_internal/pdf/__init__.py +3 -0
  331. docvortex/render/_internal/pdf/assets.py +197 -0
  332. docvortex/render/_internal/pdf/formula.py +417 -0
  333. docvortex/render/_internal/pdf/inline.py +343 -0
  334. docvortex/render/_internal/pdf/renderer.py +734 -0
  335. docvortex/render/_internal/pdf/styles.py +206 -0
  336. docvortex/render/_internal/pdf/table.py +272 -0
  337. docvortex/render/_internal/structured_content/__init__.py +3 -0
  338. docvortex/render/_internal/structured_content/renderer.py +193 -0
  339. docvortex/render/api.py +199 -0
  340. docvortex/render/contracts.py +205 -0
  341. docvortex/render/docx.py +38 -0
  342. docvortex/render/epub.py +35 -0
  343. docvortex/render/fragments.py +70 -0
  344. docvortex/render/html.py +29 -0
  345. docvortex/render/latex.py +24 -0
  346. docvortex/render/markdown.py +50 -0
  347. docvortex/render/pdf.py +25 -0
  348. docvortex/render/structured_content.py +23 -0
  349. docvortex/resources/epub/docvortex.css +91 -0
  350. docvortex/resources/fasttext-langdetect/lid.176.ftz +0 -0
  351. docvortex/resources/fonts/DroidSansFallbackFull.ttf +0 -0
  352. docvortex/resources/fonts/NOTICE +190 -0
  353. docvortex/resources/fonts/manifest.json +9 -0
  354. docvortex/resources/html/docvortex.css +601 -0
  355. docvortex/resources/html/docvortex.min.css +1 -0
  356. docvortex/result.py +91 -0
  357. docvortex/schema.py +1141 -0
  358. docvortex/version.py +3 -0
  359. docvortex-0.2.1.dist-info/METADATA +193 -0
  360. docvortex-0.2.1.dist-info/RECORD +364 -0
  361. docvortex-0.2.1.dist-info/WHEEL +5 -0
  362. docvortex-0.2.1.dist-info/entry_points.txt +2 -0
  363. docvortex-0.2.1.dist-info/licenses/LICENSE.md +21 -0
  364. docvortex-0.2.1.dist-info/top_level.txt +1 -0
docvortex/api.py ADDED
@@ -0,0 +1,180 @@
1
+ """独立文档引擎的分阶段 API 与完整转换入口。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import replace
6
+ from io import BytesIO
7
+ import json
8
+ from pathlib import Path
9
+ import time
10
+ from typing import TYPE_CHECKING
11
+
12
+ from .assets import AssetStore
13
+ from .document.source import HtmlSourceContext, prepare_source
14
+ from .result import AnalysisResult, Diagnostic, DocumentResult, ExportResult, RenderArtifact
15
+ from .schema import DocumentMetadata, FileSuffix, MiddleJson, ModelJson, PageInfo, Producer
16
+ from .version import __version__
17
+ from .render.contracts import DocxRenderOptions, EpubRenderOptions, PdfRenderOptions, RenderFormat, RenderOptions
18
+
19
+ if TYPE_CHECKING:
20
+ from .analyzers.native.contracts import NativeBinaryAnalyzer
21
+ from .document.pdf.document import PDFDocument
22
+
23
+
24
+ def analyze(
25
+ source: str | Path | bytes | PDFDocument,
26
+ *,
27
+ file_suffix: FileSuffix | None = None,
28
+ page_range: str = "",
29
+ source_context: HtmlSourceContext | None = None,
30
+ ) -> AnalysisResult:
31
+ """执行原生分析,显式调用者选择不会被隐式分类或 OCR 改写。"""
32
+ from .analyzers.native import models
33
+
34
+ started = time.perf_counter()
35
+ prepared = prepare_source(source, file_suffix=file_suffix, page_range=page_range, source_context=source_context)
36
+ try:
37
+ if prepared.file_suffix == "pdf":
38
+ from .document.pdf.visuals import attach_visual_block_images_from_pdf
39
+
40
+ assert prepared.document is not None
41
+ pages = models.PdfModel().predict(prepared.document)
42
+ attach_visual_block_images_from_pdf(prepared.document, pages)
43
+ elif prepared.file_suffix == "html":
44
+ pages = models.HtmlModel().predict(BytesIO(prepared.data), source_context=prepared.source_context)
45
+ else:
46
+ model_types: dict[FileSuffix, type[NativeBinaryAnalyzer]] = {
47
+ "csv": models.CsvModel,
48
+ "epub": models.EpubModel,
49
+ "ofd": models.OfdModel,
50
+ "doc": models.DocModel,
51
+ "docx": models.DocxModel,
52
+ "ppt": models.PptModel,
53
+ "pptx": models.PptxModel,
54
+ "xls": models.XlsModel,
55
+ "xlsx": models.XlsxModel,
56
+ "rtf": models.RtfModel,
57
+ "odt": models.OdtModel,
58
+ "ods": models.OdsModel,
59
+ "odp": models.OdpModel,
60
+ }
61
+ pages = model_types[prepared.file_suffix]().predict(BytesIO(prepared.data))
62
+ model = ModelJson(
63
+ pages=pages,
64
+ page_index_map=prepared.page_index_map or [],
65
+ metadata=DocumentMetadata(
66
+ file_suffix=prepared.file_suffix, producer=Producer(name="docvortex", version=__version__)
67
+ ),
68
+ )
69
+ diagnostics = tuple(
70
+ Diagnostic("broken_page", "The selected PDF page could not be loaded", index)
71
+ for index in prepared.broken_page_indices
72
+ )
73
+ return AnalysisResult(model, diagnostics=diagnostics, elapsed_seconds=time.perf_counter() - started)
74
+ finally:
75
+ if prepared.owns_document and prepared.document is not None:
76
+ prepared.document.close()
77
+
78
+
79
+ def postprocess(
80
+ analysis: AnalysisResult | ModelJson, *, assets: AssetStore | None = None, keep_model_json: bool = False
81
+ ) -> DocumentResult:
82
+ """执行确定性后处理并物化结果素材,智能增强由上层显式调用。"""
83
+ from .postprocess.document import model_json_to_middle_json
84
+ from .export.files import materialize_middle
85
+
86
+ if isinstance(analysis, AnalysisResult):
87
+ model, diagnostics = analysis.model_json, analysis.diagnostics
88
+ if assets is None:
89
+ assets = analysis.assets
90
+ else:
91
+ model, diagnostics = analysis, ()
92
+ middle = model_json_to_middle_json(model)
93
+ if model.page_index_map:
94
+ pages = {page.page_idx: page for page in middle.pages}
95
+ for diagnostic in diagnostics:
96
+ if diagnostic.code == "broken_page" and diagnostic.page_index is not None:
97
+ pages.setdefault(diagnostic.page_index, PageInfo(page_idx=diagnostic.page_index))
98
+ middle.pages = [pages[index] for index in sorted(pages)]
99
+ middle, result_assets = materialize_middle(middle, assets)
100
+ return DocumentResult(middle, result_assets, model if keep_model_json else None, diagnostics)
101
+
102
+
103
+ def parse(
104
+ source: str | Path | bytes | PDFDocument,
105
+ *,
106
+ file_suffix: FileSuffix | None = None,
107
+ page_range: str = "",
108
+ source_context: HtmlSourceContext | None = None,
109
+ keep_model_json: bool = False,
110
+ ) -> DocumentResult:
111
+ """完成输入、分析及后处理,返回可脱离原文件使用的结果。"""
112
+ return postprocess(
113
+ analyze(source, file_suffix=file_suffix, page_range=page_range, source_context=source_context),
114
+ keep_model_json=keep_model_json,
115
+ )
116
+
117
+
118
+ def render(
119
+ middle_json: MiddleJson,
120
+ output_format: RenderFormat | str,
121
+ *,
122
+ assets: AssetStore | None = None,
123
+ options: RenderOptions | None = None,
124
+ ) -> RenderArtifact:
125
+ """把同一语义文档编码为目标文件,返回值不产生文件系统副作用。"""
126
+ from .render.api import render as render_value
127
+ from .render._internal.common.context import owned_render_document
128
+ from .export.files import materialize_middle
129
+
130
+ target = RenderFormat(output_format)
131
+ middle, resolved_assets = materialize_middle(middle_json, assets)
132
+ resolver_options = {
133
+ RenderFormat.DOCX: DocxRenderOptions,
134
+ RenderFormat.EPUB: EpubRenderOptions,
135
+ RenderFormat.PDF: PdfRenderOptions,
136
+ }
137
+ if target in resolver_options:
138
+ if options is None:
139
+ options = resolver_options[target](asset_resolver=resolved_assets.__getitem__)
140
+ elif isinstance(options, resolver_options[target]) and options.asset_resolver is None:
141
+ options = replace(options, asset_resolver=resolved_assets.__getitem__)
142
+ with owned_render_document(middle):
143
+ value = render_value(middle, target, options=options)
144
+ if isinstance(value, bytes):
145
+ content = value
146
+ elif isinstance(value, str):
147
+ content = value.encode("utf-8")
148
+ else:
149
+ content = json.dumps(value, ensure_ascii=False, indent=2).encode("utf-8")
150
+ mime_types = {
151
+ RenderFormat.MARKDOWN: "text/markdown",
152
+ RenderFormat.HTML: "text/html",
153
+ RenderFormat.LATEX: "application/x-tex",
154
+ RenderFormat.DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
155
+ RenderFormat.EPUB: "application/epub+zip",
156
+ RenderFormat.PDF: "application/pdf",
157
+ }
158
+ packaged = target in resolver_options
159
+ return RenderArtifact(
160
+ content, target, mime_types.get(target, "application/json"), AssetStore() if packaged else resolved_assets
161
+ )
162
+
163
+
164
+ def convert(
165
+ source: str | Path | bytes | PDFDocument,
166
+ output_path: str | Path,
167
+ *,
168
+ output_format: RenderFormat | str = RenderFormat.MARKDOWN,
169
+ file_suffix: FileSuffix | None = None,
170
+ page_range: str = "",
171
+ source_context: HtmlSourceContext | None = None,
172
+ options: RenderOptions | None = None,
173
+ overwrite: bool = False,
174
+ ) -> ExportResult:
175
+ """使用完整原生流程进行一次转换,并返回实际写出的文件路径。"""
176
+ result = parse(source, file_suffix=file_suffix, page_range=page_range, source_context=source_context)
177
+ return result.export(output_path, output_format=output_format, options=options, overwrite=overwrite)
178
+
179
+
180
+ __all__ = ["analyze", "postprocess", "parse", "render", "convert"]
@@ -0,0 +1,5 @@
1
+ """文档素材的显式字节所有权与读取接口。"""
2
+
3
+ from .store import AssetStore
4
+
5
+ __all__ = ["AssetStore"]
@@ -0,0 +1,51 @@
1
+ """结果拥有的素材字节集合,所有路径均相对于输出目录。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Iterator, Mapping
6
+ from hashlib import sha256
7
+
8
+ from ..foundation.image_payload import validate_image_sidecar_path
9
+
10
+
11
+ class AssetStore(Mapping[str, bytes]):
12
+ """以稳定相对路径读取素材,并共享相同内容的字节对象。"""
13
+
14
+ def __init__(self, files: Mapping[str, bytes] | None = None) -> None:
15
+ """复制素材索引,调用者后续修改字典不会污染结果。"""
16
+ self._files: dict[str, bytes] = {}
17
+ self._content: dict[str, bytes] = {}
18
+ for path, payload in (files or {}).items():
19
+ self.add(path, payload)
20
+
21
+ def add(self, path: str, payload: bytes) -> None:
22
+ """校验相对路径并拒绝同名不同内容,避免覆盖现有素材。"""
23
+ path = validate_image_sidecar_path(path)
24
+ if not isinstance(payload, bytes):
25
+ raise TypeError("Asset payload must be bytes")
26
+ if path in self._files and self._files[path] != payload:
27
+ raise ValueError(f"Conflicting asset payload: {path}")
28
+ payload = self._content.setdefault(sha256(payload).hexdigest(), payload)
29
+ self._files[path] = payload
30
+
31
+ def __getitem__(self, path: str) -> bytes:
32
+ """按经过验证的相对路径解析素材,不读取宿主文件或网络。"""
33
+ return self._files[validate_image_sidecar_path(path)]
34
+
35
+ def __iter__(self) -> Iterator[str]:
36
+ """以登记顺序遍历素材路径。"""
37
+ return iter(self._files)
38
+
39
+ def __len__(self) -> int:
40
+ """返回素材引用数量。"""
41
+ return len(self._files)
42
+
43
+ def copy(self) -> AssetStore:
44
+ """建立独立索引并复用不可变字节。"""
45
+ copied = AssetStore()
46
+ copied._files = self._files.copy()
47
+ copied._content = self._content.copy()
48
+ return copied
49
+
50
+
51
+ __all__ = ["AssetStore"]
docvortex/cli.py ADDED
@@ -0,0 +1,54 @@
1
+ """独立转换命令行,业务行为全部委托公开 API。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import click
8
+
9
+ from .version import __version__
10
+
11
+
12
+ @click.group(help="DocVortex: native multi-format document parsing and conversion.")
13
+ @click.version_option(__version__)
14
+ def main() -> None:
15
+ """提供独立文档引擎的命令行入口。"""
16
+
17
+
18
+ @main.command("convert")
19
+ @click.argument("source", type=click.Path(exists=True, dir_okay=False, path_type=Path))
20
+ @click.option("--output", "-o", required=True, type=click.Path(path_type=Path))
21
+ @click.option(
22
+ "--format",
23
+ "output_format",
24
+ default="markdown",
25
+ show_default=True,
26
+ type=click.Choice(["markdown", "html", "latex", "docx", "epub", "pdf", "structured_content"]),
27
+ )
28
+ @click.option("--pages", "page_range", default="", help="PDF page selection: 1-5, r1, all.")
29
+ @click.option("--overwrite", is_flag=True)
30
+ def convert_command(source: Path, output: Path, output_format: str, page_range: str, overwrite: bool) -> None:
31
+ """转换原生文档并写出目标文件及所需素材。"""
32
+ from .api import convert
33
+
34
+ try:
35
+ result = convert(source, output, output_format=output_format, page_range=page_range, overwrite=overwrite)
36
+ except (ValueError, OSError) as error:
37
+ raise click.ClickException(str(error)) from error
38
+ click.echo(str(result.path))
39
+
40
+
41
+ @main.command("classify")
42
+ @click.argument("source", type=click.Path(exists=True, dir_okay=False, path_type=Path))
43
+ def classify_command(source: Path) -> None:
44
+ """显式判断 PDF 应使用文本解析还是 OCR,不启动任何推理。"""
45
+ from .document.pdf import PDFDocument
46
+
47
+ with PDFDocument(source.read_bytes()) as document:
48
+ click.echo(document.classify())
49
+
50
+
51
+ __all__ = ["main"]
52
+
53
+ if __name__ == "__main__":
54
+ main()
@@ -0,0 +1,3 @@
1
+ """DocVortex 模块边界。"""
2
+
3
+ __all__ = []
@@ -0,0 +1,22 @@
1
+ """DocVortex HTML v1 canonical wire 的轻量内部入口。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from lxml import etree # type: ignore[reportMissingImports]
6
+
7
+ from .resources import WireResourceContext
8
+ from .contracts import DOCVORTEX_HTML_VERSION, WireDecodeResult
9
+
10
+
11
+ def decode_docvortex_html_wire(body: etree._Element, resources: WireResourceContext) -> WireDecodeResult:
12
+ """只对 canonical v1 wire 精确解码,其余输入返回通用投影信号。"""
13
+ from .materializer import materialize_docvortex_html_wire
14
+ from .parser import parse_docvortex_html_wire
15
+
16
+ plan, fallback_reason = parse_docvortex_html_wire(body)
17
+ if plan is None:
18
+ return WireDecodeResult(None, fallback_reason)
19
+ return WireDecodeResult(materialize_docvortex_html_wire(plan, resources))
20
+
21
+
22
+ __all__ = ["DOCVORTEX_HTML_VERSION", "WireDecodeResult", "decode_docvortex_html_wire"]
@@ -0,0 +1,236 @@
1
+ """DocVortex HTML v1 canonical wire 的内部类型契约。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from typing import Literal, TypeAlias, Union
7
+
8
+ from lxml import etree # type: ignore[reportMissingImports]
9
+
10
+ from ...schema import BlockType
11
+
12
+
13
+ DOCVORTEX_HTML_VERSION = "1"
14
+ WIRE_BLOCK_CLASS = "docvortex-block"
15
+ WIRE_DOCUMENT_CLASS = "docvortex-document"
16
+ WIRE_INDEX_CLASS = "docvortex-index"
17
+ WIRE_LIST_CONTENT_CLASS = "docvortex-list-content"
18
+ WIRE_LIST_MARKER_CLASS = "docvortex-list-marker"
19
+ WIRE_PAGE_BREAK_CLASS = "docvortex-page-break"
20
+ WIRE_PAGE_CLASS = "docvortex-page"
21
+ WIRE_VISUAL_BODY_CLASS = "docvortex-visual-body"
22
+ WireRenderMode: TypeAlias = Literal["default", "full"]
23
+ WireFallbackReason: TypeAlias = Literal["unsupported_version", "non_canonical_wire"]
24
+
25
+
26
+ @dataclass(frozen=True, slots=True)
27
+ class TextWireSpec:
28
+ """保存一个文本类顶层 block 的 canonical 节点与元数据。"""
29
+
30
+ wrapper: etree._Element
31
+ content_root: etree._Element
32
+ block_type: BlockType
33
+ page_idx: int
34
+ block_index: int | None
35
+
36
+
37
+ @dataclass(frozen=True, slots=True)
38
+ class EquationWireSpec:
39
+ """保存一个行间公式或公式图片 carrier。"""
40
+
41
+ wrapper: etree._Element
42
+ content_root: etree._Element
43
+ page_idx: int
44
+ block_index: int | None
45
+
46
+
47
+ @dataclass(frozen=True, slots=True)
48
+ class AnnotationWireSpec:
49
+ """保存 visual caption/footnote 的 canonical 行内容器。"""
50
+
51
+ element: etree._Element
52
+ block_type: BlockType
53
+
54
+
55
+ @dataclass(frozen=True, slots=True)
56
+ class RichVisualBodyWireSpec:
57
+ """保存普通 image/chart body 的主图片与规范化富内容片段。"""
58
+
59
+ element: etree._Element
60
+ parent_type: BlockType
61
+ sub_type: str
62
+ primary_image: etree._Element | None
63
+ content_fragment: etree._Element | None
64
+
65
+
66
+ @dataclass(frozen=True, slots=True)
67
+ class FlowchartBodyWireSpec:
68
+ """保存 flowchart 源码与可选 raster fallback。"""
69
+
70
+ element: etree._Element
71
+ source_element: etree._Element
72
+ fallback_image: etree._Element | None
73
+
74
+
75
+ @dataclass(frozen=True, slots=True)
76
+ class TableBodyWireSpec:
77
+ """保存 table body 的唯一 canonical 载荷。"""
78
+
79
+ element: etree._Element
80
+ kind: Literal["empty", "html", "text", "image"]
81
+ payload_element: etree._Element | None
82
+
83
+
84
+ @dataclass(frozen=True, slots=True)
85
+ class CodeBodyWireSpec:
86
+ """保存 code/algorithm body 的唯一 canonical 内容载体。"""
87
+
88
+ element: etree._Element
89
+ kind: Literal["code", "algorithm"]
90
+ content_element: etree._Element
91
+
92
+
93
+ VisualBodyWireSpec: TypeAlias = Union[
94
+ RichVisualBodyWireSpec,
95
+ FlowchartBodyWireSpec,
96
+ TableBodyWireSpec,
97
+ CodeBodyWireSpec,
98
+ ]
99
+ VisualChildWireSpec: TypeAlias = Union[VisualBodyWireSpec, AnnotationWireSpec]
100
+
101
+
102
+ @dataclass(frozen=True, slots=True)
103
+ class VisualWireSpec:
104
+ """保存 visual 顶层 block 与已按 DOM 顺序解析的子节点。"""
105
+
106
+ wrapper: etree._Element
107
+ content_root: etree._Element
108
+ block_type: BlockType
109
+ page_idx: int
110
+ block_index: int | None
111
+ sub_type: str
112
+ guess_lang: str
113
+ children: tuple[VisualChildWireSpec, ...]
114
+
115
+
116
+ @dataclass(frozen=True, slots=True)
117
+ class ListLeafWireSpec:
118
+ """保存一个列表叶子的内容 carrier、marker 与公开类型。"""
119
+
120
+ block_type: BlockType
121
+ block_index: int | None
122
+ content_element: etree._Element | None
123
+ marker: str
124
+
125
+
126
+ @dataclass(frozen=True, slots=True)
127
+ class ListWireSpec:
128
+ """保存一个 canonical 列表及其递归子项。"""
129
+
130
+ element: etree._Element
131
+ block_index: int | None
132
+ ordered: bool
133
+ start: int
134
+ sub_type: str
135
+ classes: frozenset[str]
136
+ children: tuple[Union[ListLeafWireSpec, "ListWireSpec"], ...]
137
+
138
+
139
+ @dataclass(frozen=True, slots=True)
140
+ class ListBlockWireSpec:
141
+ """保存顶层 ListBlock wrapper 与列表树。"""
142
+
143
+ wrapper: etree._Element
144
+ page_idx: int
145
+ block_index: int | None
146
+ root: ListWireSpec
147
+
148
+
149
+ @dataclass(frozen=True, slots=True)
150
+ class IndexLeafWireSpec:
151
+ """保存一个目录叶子的 canonical 内容 carrier 与元数据。"""
152
+
153
+ block_type: BlockType
154
+ block_index: int | None
155
+ content_element: etree._Element | None
156
+ anchor: str
157
+ level: int | None
158
+
159
+
160
+ @dataclass(frozen=True, slots=True)
161
+ class IndexWireSpec:
162
+ """保存一个 canonical 目录列表及其递归子项。"""
163
+
164
+ element: etree._Element
165
+ block_index: int | None
166
+ children: tuple[Union[IndexLeafWireSpec, "IndexWireSpec"], ...]
167
+
168
+
169
+ @dataclass(frozen=True, slots=True)
170
+ class IndexBlockWireSpec:
171
+ """保存顶层 IndexBlock wrapper 与目录树。"""
172
+
173
+ wrapper: etree._Element
174
+ page_idx: int
175
+ block_index: int | None
176
+ root: IndexWireSpec
177
+
178
+
179
+ PageWireSpec: TypeAlias = Union[
180
+ TextWireSpec,
181
+ EquationWireSpec,
182
+ VisualWireSpec,
183
+ ListBlockWireSpec,
184
+ IndexBlockWireSpec,
185
+ ]
186
+
187
+
188
+ @dataclass(frozen=True, slots=True)
189
+ class DocVortexHtmlWirePlan:
190
+ """保存一次无资源副作用的完整 canonical wire 解析结果。"""
191
+
192
+ root: etree._Element
193
+ render_mode: WireRenderMode
194
+ blocks: tuple[PageWireSpec, ...]
195
+
196
+
197
+ @dataclass(frozen=True, slots=True)
198
+ class WireDecodeResult:
199
+ """区分未命中 wire、精确解码成功与需要通用回退。"""
200
+
201
+ blocks: list[dict[str, object]] | None
202
+ fallback_reason: WireFallbackReason | None = None
203
+
204
+
205
+ __all__ = [
206
+ "AnnotationWireSpec",
207
+ "CodeBodyWireSpec",
208
+ "EquationWireSpec",
209
+ "FlowchartBodyWireSpec",
210
+ "IndexBlockWireSpec",
211
+ "IndexLeafWireSpec",
212
+ "IndexWireSpec",
213
+ "ListBlockWireSpec",
214
+ "ListLeafWireSpec",
215
+ "ListWireSpec",
216
+ "DOCVORTEX_HTML_VERSION",
217
+ "DocVortexHtmlWirePlan",
218
+ "PageWireSpec",
219
+ "RichVisualBodyWireSpec",
220
+ "TableBodyWireSpec",
221
+ "TextWireSpec",
222
+ "VisualBodyWireSpec",
223
+ "VisualChildWireSpec",
224
+ "VisualWireSpec",
225
+ "WireDecodeResult",
226
+ "WireFallbackReason",
227
+ "WireRenderMode",
228
+ "WIRE_BLOCK_CLASS",
229
+ "WIRE_DOCUMENT_CLASS",
230
+ "WIRE_INDEX_CLASS",
231
+ "WIRE_LIST_CONTENT_CLASS",
232
+ "WIRE_LIST_MARKER_CLASS",
233
+ "WIRE_PAGE_BREAK_CLASS",
234
+ "WIRE_PAGE_CLASS",
235
+ "WIRE_VISUAL_BODY_CLASS",
236
+ ]