Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

refactor: group Flash PDF and Office implementations

myhlolie1c72fc6d3cf
diff --git a/mineru/model/flash/__init__.py b/mineru/model/flash/__init__.py
index 404d9f81..33b34bab 100644
--- a/mineru/model/flash/__init__.py
+++ b/mineru/model/flash/__init__.py
@@ -2,6 +2,6 @@
"""Flash PDF 与 Office 模型公开入口。"""
-from .model import DocModel, DocxModel, PdfModel, PptModel, PptxModel, XlsModel, XlsxModel
+from .models import DocModel, DocxModel, PdfModel, PptModel, PptxModel, XlsModel, XlsxModel
__all__ = ["PdfModel", "DocModel", "DocxModel", "PptModel", "PptxModel", "XlsModel", "XlsxModel"]
diff --git a/mineru/model/flash/_shared/__init__.py b/mineru/model/flash/_shared/__init__.py
new file mode 100644
index 00000000..0f2e49ec
--- /dev/null
+++ b/mineru/model/flash/_shared/__init__.py
@@ -0,0 +1,4 @@
+# Copyright (c) Opendatalab. All rights reserved.
+"""Flash PDF 与 Office 复用的轻量算法。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/xycut.py b/mineru/model/flash/_shared/xycut.py
similarity index 100%
rename from mineru/model/flash/xycut.py
rename to mineru/model/flash/_shared/xycut.py
diff --git a/mineru/model/flash/model.py b/mineru/model/flash/models.py
similarity index 86%
rename from mineru/model/flash/model.py
rename to mineru/model/flash/models.py
index 0c5cb480..b9d38a37 100644
--- a/mineru/model/flash/model.py
+++ b/mineru/model/flash/models.py
@@ -4,11 +4,10 @@
from __future__ import annotations
-from typing import Any, BinaryIO
+from typing import TYPE_CHECKING, Any, BinaryIO
-from mineru.utils.pdf_document import PDFDocument
-
-from .native_pdf import pipeline
+if TYPE_CHECKING:
+ from .pdf.document import PDFDocument
class PdfModel:
@@ -16,6 +15,7 @@ class PdfModel:
def predict(self, pdf_doc: PDFDocument) -> list[list[dict[str, Any]]]:
"""分析调用方持有的 PDFDocument,并原样返回分页 model_list。"""
+ from .pdf import pipeline
return pipeline._analyze_native_document(pdf_doc)
@@ -27,7 +27,7 @@ class DocxModel:
"""转换调用方持有的 DOCX 二进制流,并返回分页 model_list。"""
# 延迟加载 Converter,避免纯 PDF 路径提前加载 Office 依赖。
- from .docx.docx_converter import DocxConverter
+ from .office.docx.docx_converter import DocxConverter
converter = DocxConverter()
converter.convert(file_binary)
@@ -41,7 +41,7 @@ class DocModel:
"""转换调用方持有的 DOC 二进制流,并返回逐 section model-list。"""
# 延迟加载旧版 DOC 解析器,避免其他格式提前加载 olefile。
- from .doc.doc_converter import DocConverter
+ from .office.doc.doc_converter import DocConverter
converter = DocConverter()
converter.convert(file_binary)
@@ -55,7 +55,7 @@ class PptxModel:
"""转换调用方持有的 PPTX 二进制流,并返回分页 model_list。"""
# 延迟加载 Converter,避免纯 PDF 路径提前加载 Office 依赖。
- from .pptx.pptx_converter import PptxConverter
+ from .office.pptx.pptx_converter import PptxConverter
converter = PptxConverter()
converter.convert(file_binary)
@@ -69,7 +69,7 @@ class PptModel:
"""转换调用方持有的 PPT 二进制流,并返回逐幻灯片 model-list。"""
# 延迟加载旧版 PPT 解析器,避免其他格式提前加载 olefile。
- from .ppt.ppt_converter import PptConverter
+ from .office.ppt.ppt_converter import PptConverter
converter = PptConverter()
converter.convert(file_binary)
@@ -83,7 +83,7 @@ class XlsModel:
"""转换调用方持有的 XLS 二进制流,并返回逐工作表 model-list。"""
# 延迟加载旧版 XLS 解析器,避免其他格式提前加载 olefile/openpyxl。
- from .xls.xls_converter import XlsConverter
+ from .office.xls.xls_converter import XlsConverter
converter = XlsConverter()
converter.convert(file_binary)
@@ -97,7 +97,7 @@ class XlsxModel:
"""转换调用方持有的 XLSX 二进制流,并返回分页 model_list。"""
# 延迟加载 Converter,避免纯 PDF 路径提前加载 Office 依赖。
- from .xlsx.xlsx_converter import XlsxConverter
+ from .office.xlsx.xlsx_converter import XlsxConverter
converter = XlsxConverter()
converter.convert(file_binary)
diff --git a/mineru/model/flash/office/__init__.py b/mineru/model/flash/office/__init__.py
index 987b6c08..f94f2b1f 100644
--- a/mineru/model/flash/office/__init__.py
+++ b/mineru/model/flash/office/__init__.py
@@ -1 +1,4 @@
+# Copyright (c) Opendatalab. All rights reserved.
"""Flash Office 模型共享实现。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/doc/__init__.py b/mineru/model/flash/office/doc/__init__.py
similarity index 81%
rename from mineru/model/flash/doc/__init__.py
rename to mineru/model/flash/office/doc/__init__.py
index f6a747e1..73da6cd6 100644
--- a/mineru/model/flash/doc/__init__.py
+++ b/mineru/model/flash/office/doc/__init__.py
@@ -2,3 +2,4 @@
"""Word 97–2003 二进制文档解析实现。"""
+__all__: list[str] = []
diff --git a/mineru/model/flash/doc/bookmarks.py b/mineru/model/flash/office/doc/bookmarks.py
similarity index 100%
rename from mineru/model/flash/doc/bookmarks.py
rename to mineru/model/flash/office/doc/bookmarks.py
diff --git a/mineru/model/flash/doc/doc_converter.py b/mineru/model/flash/office/doc/doc_converter.py
similarity index 97%
rename from mineru/model/flash/doc/doc_converter.py
rename to mineru/model/flash/office/doc/doc_converter.py
index b489d33e..ba97db0f 100644
--- a/mineru/model/flash/doc/doc_converter.py
+++ b/mineru/model/flash/office/doc/doc_converter.py
@@ -8,14 +8,14 @@ from html import escape
import re
from typing import Any, BinaryIO, Iterable
-from mineru.model.flash.legacy_office import BoundedOleReader, LegacyOfficeEncryptedError
-from mineru.model.flash.office.image import serialize_office_image
-from mineru.model.office_stream import read_stream_bytes_from_start
-from mineru.types import RAW_CAPTION, BlockType
-from mineru.utils.office_rich_text import OfficeRichTextSegment, build_rich_text_from_segments
+from ..legacy import BoundedOleReader, LegacyOfficeEncryptedError
+from ..image import serialize_office_image
+from ..legacy.stream import read_stream_bytes_from_start
+from .....types import RAW_CAPTION, BlockType
+from ..rich_text import OfficeRichTextSegment, build_rich_text_from_segments
from .fib import parse_fib
-from mineru.model.flash.legacy_office.mtef import read_object_pool_equations
+from ..legacy.mtef import read_object_pool_equations
from ..xls.embedded_chart import extract_embedded_chart_html
from .models import (
DocCharStyle,
diff --git a/mineru/model/flash/doc/fib.py b/mineru/model/flash/office/doc/fib.py
similarity index 99%
rename from mineru/model/flash/doc/fib.py
rename to mineru/model/flash/office/doc/fib.py
index 002a2043..9603f6da 100644
--- a/mineru/model/flash/doc/fib.py
+++ b/mineru/model/flash/office/doc/fib.py
@@ -7,7 +7,7 @@ from __future__ import annotations
from dataclasses import dataclass
import struct
-from mineru.model.flash.legacy_office import LegacyOfficeMalformedError
+from ..legacy import LegacyOfficeMalformedError
FIB_IDENT = 0xA5EC
MIN_WORD97_NFIB = 0x00C1
diff --git a/mineru/model/flash/doc/fields.py b/mineru/model/flash/office/doc/fields.py
similarity index 100%
rename from mineru/model/flash/doc/fields.py
rename to mineru/model/flash/office/doc/fields.py
diff --git a/mineru/model/flash/doc/formatting.py b/mineru/model/flash/office/doc/formatting.py
similarity index 100%
rename from mineru/model/flash/doc/formatting.py
rename to mineru/model/flash/office/doc/formatting.py
diff --git a/mineru/model/flash/doc/images.py b/mineru/model/flash/office/doc/images.py
similarity index 95%
rename from mineru/model/flash/doc/images.py
rename to mineru/model/flash/office/doc/images.py
index 23ccf11e..f898f4fe 100644
--- a/mineru/model/flash/doc/images.py
+++ b/mineru/model/flash/office/doc/images.py
@@ -9,16 +9,16 @@ import hashlib
from loguru import logger
-from mineru.model.flash.legacy_office import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import MAX_ASSET_TOTAL_BYTES
-from mineru.model.flash.legacy_office.officeart import (
+from ..legacy import LegacyOfficeResourceLimitError
+from ..legacy.limits import MAX_ASSET_TOTAL_BYTES
+from ..legacy.officeart import (
OfficeImagePayload,
decode_bstore,
extract_word_shapes,
first_blip,
record_at,
)
-from mineru.model.flash.office.image_equation import (
+from ..image_equation import (
OfficeImageEquationDecoder,
)
diff --git a/mineru/model/flash/doc/lists.py b/mineru/model/flash/office/doc/lists.py
similarity index 100%
rename from mineru/model/flash/doc/lists.py
rename to mineru/model/flash/office/doc/lists.py
diff --git a/mineru/model/flash/doc/models.py b/mineru/model/flash/office/doc/models.py
similarity index 100%
rename from mineru/model/flash/doc/models.py
rename to mineru/model/flash/office/doc/models.py
diff --git a/mineru/model/flash/doc/parser.py b/mineru/model/flash/office/doc/parser.py
similarity index 99%
rename from mineru/model/flash/doc/parser.py
rename to mineru/model/flash/office/doc/parser.py
index 8d8cc7d0..0c520346 100644
--- a/mineru/model/flash/doc/parser.py
+++ b/mineru/model/flash/office/doc/parser.py
@@ -7,7 +7,7 @@ from __future__ import annotations
from dataclasses import dataclass, field
from loguru import logger
-from mineru.model.flash.legacy_office import LegacyOfficeMalformedError
+from ..legacy import LegacyOfficeMalformedError
from .bookmarks import parse_bookmarks
from .fib import (
diff --git a/mineru/model/flash/doc/pieces.py b/mineru/model/flash/office/doc/pieces.py
similarity index 99%
rename from mineru/model/flash/doc/pieces.py
rename to mineru/model/flash/office/doc/pieces.py
index 15d22b21..896377d5 100644
--- a/mineru/model/flash/doc/pieces.py
+++ b/mineru/model/flash/office/doc/pieces.py
@@ -8,7 +8,7 @@ from bisect import bisect_left
from dataclasses import dataclass
import struct
-from mineru.model.flash.legacy_office import LegacyOfficeMalformedError
+from ..legacy import LegacyOfficeMalformedError
from .records import DocBudget, bounded_slice, get_u16, get_u32
diff --git a/mineru/model/flash/doc/records.py b/mineru/model/flash/office/doc/records.py
similarity index 94%
rename from mineru/model/flash/doc/records.py
rename to mineru/model/flash/office/doc/records.py
index 4e87a3e5..69b5e153 100644
--- a/mineru/model/flash/doc/records.py
+++ b/mineru/model/flash/office/doc/records.py
@@ -7,8 +7,8 @@ from __future__ import annotations
from dataclasses import dataclass
import struct
-from mineru.model.flash.legacy_office import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import MAX_RECORDS
+from ..legacy import LegacyOfficeResourceLimitError
+from ..legacy.limits import MAX_RECORDS
@dataclass(slots=True)
diff --git a/mineru/model/flash/doc/sprm.py b/mineru/model/flash/office/doc/sprm.py
similarity index 100%
rename from mineru/model/flash/doc/sprm.py
rename to mineru/model/flash/office/doc/sprm.py
diff --git a/mineru/model/flash/doc/styles.py b/mineru/model/flash/office/doc/styles.py
similarity index 100%
rename from mineru/model/flash/doc/styles.py
rename to mineru/model/flash/office/doc/styles.py
diff --git a/mineru/model/flash/docx/__init__.py b/mineru/model/flash/office/docx/__init__.py
similarity index 77%
rename from mineru/model/flash/docx/__init__.py
rename to mineru/model/flash/office/docx/__init__.py
index e0a59fbf..c1c131ee 100644
--- a/mineru/model/flash/docx/__init__.py
+++ b/mineru/model/flash/office/docx/__init__.py
@@ -1,3 +1,5 @@
# Copyright (c) Opendatalab. All rights reserved.
"""Flash DOCX 转换实现。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/docx/docx_converter.py b/mineru/model/flash/office/docx/docx_converter.py
similarity index 99%
rename from mineru/model/flash/docx/docx_converter.py
rename to mineru/model/flash/office/docx/docx_converter.py
index 68fa5236..0e1234e3 100644
--- a/mineru/model/flash/docx/docx_converter.py
+++ b/mineru/model/flash/office/docx/docx_converter.py
@@ -18,25 +18,25 @@ from mammoth.conversion import convert_document_element_to_html
from mammoth.docx import body_xml
from pydantic import AnyUrl
-from mineru.model.flash.office.chart import extract_chart_html_from_ooxml
-from mineru.model.flash.office.image import (
+from ..chart import extract_chart_html_from_ooxml
+from ..image import (
serialize_office_image,
)
-from mineru.model.flash.office.ooxml_equation import (
+from ..ooxml_equation import (
OoxmlEquationDecoder,
is_mathtype_equation_prog_id,
)
-from mineru.model.flash.office.image_equation import (
+from ..image_equation import (
OfficeImageEquationDecoder,
)
-from mineru.types import RAW_CAPTION
-from mineru.model.flash.docx.equationxml import DocxEquationXmlDecoder
-from mineru.model.flash.docx.package_normalizer import normalize_docx_package
-from mineru.model.flash.docx.tools.math.omml import oMath2Latex
-from mineru.model.flash.docx.tools.office_xml import read_str
-from mineru.types import BlockType
-from mineru.utils.docx_formatting import Formatting, Script
-from mineru.utils.office_rich_text import (
+from .....types import RAW_CAPTION
+from .equationxml import DocxEquationXmlDecoder
+from .package_normalizer import normalize_docx_package
+from .tools.math.omml import oMath2Latex
+from .tools.office_xml import read_str
+from .....types import BlockType
+from .formatting_types import Formatting, Script
+from ..rich_text import (
append_rich_text_element,
build_text_mappings_from_elements,
format_hyperlink_group,
diff --git a/mineru/model/flash/docx/equationxml.py b/mineru/model/flash/office/docx/equationxml.py
similarity index 95%
rename from mineru/model/flash/docx/equationxml.py
rename to mineru/model/flash/office/docx/equationxml.py
index aff249ae..afdc9b89 100644
--- a/mineru/model/flash/docx/equationxml.py
+++ b/mineru/model/flash/office/docx/equationxml.py
@@ -9,11 +9,11 @@ import hashlib
from lxml import etree # type: ignore[reportAttributeAccessIssue]
-from mineru.model.flash.docx.tools.math.omml import oMath2Latex
-from mineru.model.flash.legacy_office.errors import (
+from .tools.math.omml import oMath2Latex
+from ..legacy.errors import (
LegacyOfficeResourceLimitError,
)
-from mineru.model.flash.legacy_office.limits import (
+from ..legacy.limits import (
MAX_ASSET_TOTAL_BYTES,
MAX_ENTRY_BYTES,
)
diff --git a/mineru/utils/docx_formatting.py b/mineru/model/flash/office/docx/formatting_types.py
similarity index 100%
rename from mineru/utils/docx_formatting.py
rename to mineru/model/flash/office/docx/formatting_types.py
diff --git a/mineru/model/flash/docx/main.py b/mineru/model/flash/office/docx/main.py
similarity index 97%
rename from mineru/model/flash/docx/main.py
rename to mineru/model/flash/office/docx/main.py
index 9fff99a4..b6024a81 100644
--- a/mineru/model/flash/docx/main.py
+++ b/mineru/model/flash/office/docx/main.py
@@ -1,7 +1,7 @@
# Copyright (c) Opendatalab. All rights reserved.
from typing import Any, BinaryIO
-from mineru.model.flash import DocxModel
+from ... import DocxModel
def convert_path(file_path: str) -> list[list[dict[str, Any]]]:
diff --git a/mineru/model/flash/docx/package_normalizer.py b/mineru/model/flash/office/docx/package_normalizer.py
similarity index 100%
rename from mineru/model/flash/docx/package_normalizer.py
rename to mineru/model/flash/office/docx/package_normalizer.py
diff --git a/mineru/model/flash/docx/tools/__init__.py b/mineru/model/flash/office/docx/tools/__init__.py
similarity index 66%
rename from mineru/model/flash/docx/tools/__init__.py
rename to mineru/model/flash/office/docx/tools/__init__.py
index 1e17167c..818730ae 100644
--- a/mineru/model/flash/docx/tools/__init__.py
+++ b/mineru/model/flash/office/docx/tools/__init__.py
@@ -1 +1,3 @@
# Copyright (c) Opendatalab. All rights reserved.
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/docx/tools/math/__init__.py b/mineru/model/flash/office/docx/tools/math/__init__.py
similarity index 66%
rename from mineru/model/flash/docx/tools/math/__init__.py
rename to mineru/model/flash/office/docx/tools/math/__init__.py
index 1e17167c..818730ae 100644
--- a/mineru/model/flash/docx/tools/math/__init__.py
+++ b/mineru/model/flash/office/docx/tools/math/__init__.py
@@ -1 +1,3 @@
# Copyright (c) Opendatalab. All rights reserved.
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/docx/tools/math/latex_dict.py b/mineru/model/flash/office/docx/tools/math/latex_dict.py
similarity index 100%
rename from mineru/model/flash/docx/tools/math/latex_dict.py
rename to mineru/model/flash/office/docx/tools/math/latex_dict.py
diff --git a/mineru/model/flash/docx/tools/math/omml.py b/mineru/model/flash/office/docx/tools/math/omml.py
similarity index 100%
rename from mineru/model/flash/docx/tools/math/omml.py
rename to mineru/model/flash/office/docx/tools/math/omml.py
diff --git a/mineru/model/flash/docx/tools/office_xml.py b/mineru/model/flash/office/docx/tools/office_xml.py
similarity index 100%
rename from mineru/model/flash/docx/tools/office_xml.py
rename to mineru/model/flash/office/docx/tools/office_xml.py
diff --git a/mineru/model/flash/office/image.py b/mineru/model/flash/office/image.py
index 5f02fc75..2be0450e 100644
--- a/mineru/model/flash/office/image.py
+++ b/mineru/model/flash/office/image.py
@@ -9,8 +9,8 @@ from typing import Final
from loguru import logger
from PIL import Image, ImageDraw, ImageFont, UnidentifiedImageError
-from ....utils.check_sys_env import is_windows_environment
-from ....utils.pdf_reader import image_to_b64str
+from ....utils.platform import is_windows_environment
+from ..pdf.raster import image_to_b64str
VECTOR_IMAGE_FORMATS = frozenset({"WMF", "EMF"})
VECTOR_IMAGE_EXTENSIONS = frozenset({".wmf", ".emf"})
diff --git a/mineru/model/flash/office/image_equation.py b/mineru/model/flash/office/image_equation.py
index 9424cec7..ae008852 100644
--- a/mineru/model/flash/office/image_equation.py
+++ b/mineru/model/flash/office/image_equation.py
@@ -11,15 +11,15 @@ import struct
from loguru import logger
-from mineru.model.flash.legacy_office.errors import (
+from .legacy.errors import (
LegacyOfficeResourceLimitError,
)
-from mineru.model.flash.legacy_office.limits import (
+from .legacy.limits import (
MAX_ASSET_TOTAL_BYTES,
MAX_ENTRY_BYTES,
MAX_PICTURE_RECORDS,
)
-from mineru.model.flash.legacy_office.mtef import decode_mtef
+from .legacy.mtef import decode_mtef
_PLACEABLE_WMF_MAGIC = b"\xd7\xcd\xc6\x9a"
_META_ESCAPE = 0x0626
diff --git a/mineru/model/flash/legacy_office/__init__.py b/mineru/model/flash/office/legacy/__init__.py
similarity index 100%
rename from mineru/model/flash/legacy_office/__init__.py
rename to mineru/model/flash/office/legacy/__init__.py
diff --git a/mineru/model/flash/legacy_office/errors.py b/mineru/model/flash/office/legacy/errors.py
similarity index 100%
rename from mineru/model/flash/legacy_office/errors.py
rename to mineru/model/flash/office/legacy/errors.py
diff --git a/mineru/model/flash/legacy_office/limits.py b/mineru/model/flash/office/legacy/limits.py
similarity index 100%
rename from mineru/model/flash/legacy_office/limits.py
rename to mineru/model/flash/office/legacy/limits.py
diff --git a/mineru/model/flash/legacy_office/mtef.py b/mineru/model/flash/office/legacy/mtef.py
similarity index 100%
rename from mineru/model/flash/legacy_office/mtef.py
rename to mineru/model/flash/office/legacy/mtef.py
diff --git a/mineru/model/flash/legacy_office/mtef_v5.py b/mineru/model/flash/office/legacy/mtef_v5.py
similarity index 100%
rename from mineru/model/flash/legacy_office/mtef_v5.py
rename to mineru/model/flash/office/legacy/mtef_v5.py
diff --git a/mineru/model/flash/legacy_office/officeart.py b/mineru/model/flash/office/legacy/officeart.py
similarity index 100%
rename from mineru/model/flash/legacy_office/officeart.py
rename to mineru/model/flash/office/legacy/officeart.py
diff --git a/mineru/model/flash/legacy_office/ole.py b/mineru/model/flash/office/legacy/ole.py
similarity index 100%
rename from mineru/model/flash/legacy_office/ole.py
rename to mineru/model/flash/office/legacy/ole.py
diff --git a/mineru/model/office_stream.py b/mineru/model/flash/office/legacy/stream.py
similarity index 100%
rename from mineru/model/office_stream.py
rename to mineru/model/flash/office/legacy/stream.py
diff --git a/mineru/model/flash/office/ooxml_equation.py b/mineru/model/flash/office/ooxml_equation.py
index 34f9200c..26fcc9c4 100644
--- a/mineru/model/flash/office/ooxml_equation.py
+++ b/mineru/model/flash/office/ooxml_equation.py
@@ -7,12 +7,12 @@ from __future__ import annotations
from dataclasses import dataclass, field
import hashlib
-from mineru.model.flash.legacy_office.errors import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import (
+from .legacy.errors import LegacyOfficeResourceLimitError
+from .legacy.limits import (
MAX_ASSET_TOTAL_BYTES,
MAX_ENTRY_BYTES,
)
-from mineru.model.flash.legacy_office.mtef import decode_equation_object
+from .legacy.mtef import decode_equation_object
CFB_MAGIC = b"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1"
EQUATION_PROG_ID = "equation"
diff --git a/mineru/model/flash/ppt/__init__.py b/mineru/model/flash/office/ppt/__init__.py
similarity index 81%
rename from mineru/model/flash/ppt/__init__.py
rename to mineru/model/flash/office/ppt/__init__.py
index 40ec1201..333ac38b 100644
--- a/mineru/model/flash/ppt/__init__.py
+++ b/mineru/model/flash/office/ppt/__init__.py
@@ -2,3 +2,4 @@
"""PowerPoint 97–2003 二进制解析实现。"""
+__all__: list[str] = []
diff --git a/mineru/model/flash/ppt/models.py b/mineru/model/flash/office/ppt/models.py
similarity index 100%
rename from mineru/model/flash/ppt/models.py
rename to mineru/model/flash/office/ppt/models.py
diff --git a/mineru/model/flash/ppt/parser.py b/mineru/model/flash/office/ppt/parser.py
similarity index 99%
rename from mineru/model/flash/ppt/parser.py
rename to mineru/model/flash/office/ppt/parser.py
index b105ed66..a476f73c 100644
--- a/mineru/model/flash/ppt/parser.py
+++ b/mineru/model/flash/office/ppt/parser.py
@@ -13,27 +13,27 @@ import zlib
from loguru import logger
-from mineru.model.flash.legacy_office import (
+from ..legacy import (
BoundedOleReader,
LegacyOfficeEncryptedError,
LegacyOfficeMalformedError,
LegacyOfficeResourceLimitError,
)
-from mineru.model.flash.legacy_office.limits import (
+from ..legacy.limits import (
MAX_ASSET_TOTAL_BYTES,
MAX_ENTRY_BYTES,
MAX_GRID_SLOTS,
MAX_PICTURE_RECORDS,
MAX_USER_EDIT_CHAIN,
)
-from mineru.model.flash.legacy_office.mtef import decode_equation_object
-from mineru.model.flash.legacy_office.officeart import (
+from ..legacy.mtef import decode_equation_object
+from ..legacy.officeart import (
OfficeArtRecord,
OfficeImagePayload,
decode_blip as decode_officeart_blip,
)
-from mineru.model.flash.office.image import serialize_office_image
-from mineru.model.flash.office.image_equation import (
+from ..image import serialize_office_image
+from ..image_equation import (
OfficeImageEquationDecoder,
)
from ..xls.embedded_chart import extract_embedded_chart_html_from_storage
diff --git a/mineru/model/flash/ppt/ppt_converter.py b/mineru/model/flash/office/ppt/ppt_converter.py
similarity index 97%
rename from mineru/model/flash/ppt/ppt_converter.py
rename to mineru/model/flash/office/ppt/ppt_converter.py
index 5a700ed9..60f327e4 100644
--- a/mineru/model/flash/ppt/ppt_converter.py
+++ b/mineru/model/flash/office/ppt/ppt_converter.py
@@ -7,11 +7,11 @@ from __future__ import annotations
from html import escape
from typing import Any, BinaryIO
-from mineru.model.flash.legacy_office import BoundedOleReader
-from mineru.model.flash.xycut import sort_entries
-from mineru.model.office_stream import read_stream_bytes_from_start
-from mineru.types import BlockType
-from mineru.utils.office_rich_text import OfficeRichTextSegment, build_rich_text_from_segments
+from ..legacy import BoundedOleReader
+from ..._shared.xycut import sort_entries
+from ..legacy.stream import read_stream_bytes_from_start
+from .....types import BlockType
+from ..rich_text import OfficeRichTextSegment, build_rich_text_from_segments
from .models import (
PptChartElement,
diff --git a/mineru/model/flash/ppt/records.py b/mineru/model/flash/office/ppt/records.py
similarity index 97%
rename from mineru/model/flash/ppt/records.py
rename to mineru/model/flash/office/ppt/records.py
index e68f12cd..82632e7e 100644
--- a/mineru/model/flash/ppt/records.py
+++ b/mineru/model/flash/office/ppt/records.py
@@ -8,11 +8,11 @@ from dataclasses import dataclass
import struct
from typing import Iterator
-from mineru.model.flash.legacy_office.errors import (
+from ..legacy.errors import (
LegacyOfficeMalformedError,
LegacyOfficeResourceLimitError,
)
-from mineru.model.flash.legacy_office.limits import MAX_RECORD_DEPTH, MAX_RECORDS
+from ..legacy.limits import MAX_RECORD_DEPTH, MAX_RECORDS
CONTAINER_VERSION = 0xF
ROUNDTRIP_OPAQUE_MIN = 1053
diff --git a/mineru/model/flash/ppt/style_text.py b/mineru/model/flash/office/ppt/style_text.py
similarity index 100%
rename from mineru/model/flash/ppt/style_text.py
rename to mineru/model/flash/office/ppt/style_text.py
diff --git a/mineru/model/flash/pptx/__init__.py b/mineru/model/flash/office/pptx/__init__.py
similarity index 77%
rename from mineru/model/flash/pptx/__init__.py
rename to mineru/model/flash/office/pptx/__init__.py
index 23020b12..f38f86cb 100644
--- a/mineru/model/flash/pptx/__init__.py
+++ b/mineru/model/flash/office/pptx/__init__.py
@@ -1,3 +1,5 @@
# Copyright (c) Opendatalab. All rights reserved.
"""Flash PPTX 转换实现。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/pptx/main.py b/mineru/model/flash/office/pptx/main.py
similarity index 93%
rename from mineru/model/flash/pptx/main.py
rename to mineru/model/flash/office/pptx/main.py
index 125c0405..a1edb789 100644
--- a/mineru/model/flash/pptx/main.py
+++ b/mineru/model/flash/office/pptx/main.py
@@ -1,7 +1,7 @@
# Copyright (c) Opendatalab. All rights reserved.
from typing import Any, BinaryIO
-from mineru.model.flash import PptxModel
+from ... import PptxModel
def convert_path(file_path: str) -> list[list[dict[str, Any]]]:
diff --git a/mineru/model/flash/pptx/package_normalizer.py b/mineru/model/flash/office/pptx/package_normalizer.py
similarity index 100%
rename from mineru/model/flash/pptx/package_normalizer.py
rename to mineru/model/flash/office/pptx/package_normalizer.py
diff --git a/mineru/model/flash/pptx/pptx_converter.py b/mineru/model/flash/office/pptx/pptx_converter.py
similarity index 99%
rename from mineru/model/flash/pptx/pptx_converter.py
rename to mineru/model/flash/office/pptx/pptx_converter.py
index 7a0a58af..f3fca782 100644
--- a/mineru/model/flash/pptx/pptx_converter.py
+++ b/mineru/model/flash/office/pptx/pptx_converter.py
@@ -12,22 +12,22 @@ from pptx import Presentation, presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDER
from pptx.oxml.text import CT_TextLineBreak
-from mineru.model.flash.office.chart import extract_chart_html_from_ooxml
-from mineru.model.flash.office.image import PIL_IMAGE_LOAD_ERRORS, is_vector_image, serialize_vector_image_with_placeholder
-from mineru.model.flash.office.image_equation import (
+from ..chart import extract_chart_html_from_ooxml
+from ..image import PIL_IMAGE_LOAD_ERRORS, is_vector_image, serialize_vector_image_with_placeholder
+from ..image_equation import (
OfficeImageEquationDecoder,
)
-from mineru.model.flash.office.ooxml_equation import (
+from ..ooxml_equation import (
OoxmlEquationDecoder,
is_mathtype_equation_prog_id,
)
-from mineru.model.flash.docx.tools.math.omml import oMath2Latex
-from mineru.model.office_stream import read_stream_bytes_from_start, rewind_stream
-from mineru.model.flash.pptx.package_normalizer import normalize_pptx_package
-from mineru.model.flash.xycut import sort_entries
-from mineru.types import BlockType
-from mineru.utils.office_rich_text import OfficeRichTextSegment, build_rich_text_from_segments
-from mineru.utils.pdf_reader import image_to_b64str
+from ..docx.tools.math.omml import oMath2Latex
+from ..legacy.stream import read_stream_bytes_from_start, rewind_stream
+from .package_normalizer import normalize_pptx_package
+from ..._shared.xycut import sort_entries
+from .....types import BlockType
+from ..rich_text import OfficeRichTextSegment, build_rich_text_from_segments
+from ...pdf.raster import image_to_b64str
IGNORED_NOTES_PLACEHOLDER_TYPES: Final = {
PP_PLACEHOLDER.SLIDE_IMAGE,
diff --git a/mineru/utils/office_rich_text.py b/mineru/model/flash/office/rich_text.py
similarity index 100%
rename from mineru/utils/office_rich_text.py
rename to mineru/model/flash/office/rich_text.py
diff --git a/mineru/model/flash/xls/__init__.py b/mineru/model/flash/office/xls/__init__.py
similarity index 79%
rename from mineru/model/flash/xls/__init__.py
rename to mineru/model/flash/office/xls/__init__.py
index f8de07d2..ff83e083 100644
--- a/mineru/model/flash/xls/__init__.py
+++ b/mineru/model/flash/office/xls/__init__.py
@@ -1,3 +1,5 @@
# Copyright (c) Opendatalab. All rights reserved.
"""Excel 97–2003 二进制解析实现。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/xls/chart.py b/mineru/model/flash/office/xls/chart.py
similarity index 100%
rename from mineru/model/flash/xls/chart.py
rename to mineru/model/flash/office/xls/chart.py
diff --git a/mineru/model/flash/xls/embedded_chart.py b/mineru/model/flash/office/xls/embedded_chart.py
similarity index 98%
rename from mineru/model/flash/xls/embedded_chart.py
rename to mineru/model/flash/office/xls/embedded_chart.py
index 2c581009..f3a82497 100644
--- a/mineru/model/flash/xls/embedded_chart.py
+++ b/mineru/model/flash/office/xls/embedded_chart.py
@@ -9,12 +9,12 @@ import struct
from loguru import logger
-from ..legacy_office import BoundedOleReader
-from ..legacy_office.errors import (
+from ..legacy import BoundedOleReader
+from ..legacy.errors import (
LegacyOfficeMalformedError,
LegacyOfficeResourceLimitError,
)
-from ..legacy_office.limits import MAX_GRID_SLOTS
+from ..legacy.limits import MAX_GRID_SLOTS
from .models import XlsCell, XlsRichText, XlsSheet, XlsWorkbook
from .number_format import builtin_number_format, format_number
from .parser import parse_xls_workbook
diff --git a/mineru/model/flash/xls/models.py b/mineru/model/flash/office/xls/models.py
similarity index 100%
rename from mineru/model/flash/xls/models.py
rename to mineru/model/flash/office/xls/models.py
diff --git a/mineru/model/flash/xls/number_format.py b/mineru/model/flash/office/xls/number_format.py
similarity index 100%
rename from mineru/model/flash/xls/number_format.py
rename to mineru/model/flash/office/xls/number_format.py
diff --git a/mineru/model/flash/xls/parser.py b/mineru/model/flash/office/xls/parser.py
similarity index 99%
rename from mineru/model/flash/xls/parser.py
rename to mineru/model/flash/office/xls/parser.py
index 6b26c874..df727e94 100644
--- a/mineru/model/flash/xls/parser.py
+++ b/mineru/model/flash/office/xls/parser.py
@@ -11,18 +11,18 @@ import uuid
from loguru import logger
-from mineru.model.flash.legacy_office.errors import (
+from ..legacy.errors import (
LegacyOfficeEncryptedError,
LegacyOfficeMalformedError,
)
-from mineru.model.flash.legacy_office.officeart import (
+from ..legacy.officeart import (
OfficeArtShape,
OfficeImagePayload,
decode_bstore,
extract_excel_shapes,
)
-from mineru.model.flash.office.image import serialize_office_image
-from mineru.model.flash.office.image_equation import (
+from ..image import serialize_office_image
+from ..image_equation import (
OfficeImageEquationDecoder,
)
diff --git a/mineru/model/flash/xls/records.py b/mineru/model/flash/office/xls/records.py
similarity index 97%
rename from mineru/model/flash/xls/records.py
rename to mineru/model/flash/office/xls/records.py
index a1161b83..3c784d20 100644
--- a/mineru/model/flash/xls/records.py
+++ b/mineru/model/flash/office/xls/records.py
@@ -10,8 +10,8 @@ from typing import Iterator
from loguru import logger
-from mineru.model.flash.legacy_office.errors import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import MAX_RECORDS
+from ..legacy.errors import LegacyOfficeResourceLimitError
+from ..legacy.limits import MAX_RECORDS
BOF = 0x0809
EOF = 0x000A
diff --git a/mineru/model/flash/xls/strings.py b/mineru/model/flash/office/xls/strings.py
similarity index 100%
rename from mineru/model/flash/xls/strings.py
rename to mineru/model/flash/office/xls/strings.py
diff --git a/mineru/model/flash/xls/xls_converter.py b/mineru/model/flash/office/xls/xls_converter.py
similarity index 96%
rename from mineru/model/flash/xls/xls_converter.py
rename to mineru/model/flash/office/xls/xls_converter.py
index dc802b41..0761a43a 100644
--- a/mineru/model/flash/xls/xls_converter.py
+++ b/mineru/model/flash/office/xls/xls_converter.py
@@ -14,13 +14,13 @@ from openpyxl.cell.rich_text import CellRichText, TextBlock # type: ignore[repo
from openpyxl.cell.text import InlineFont # type: ignore[reportMissingModuleSource]
from openpyxl.worksheet.worksheet import Worksheet # type: ignore[reportMissingModuleSource]
-from mineru.model.flash.legacy_office import BoundedOleReader, LegacyOfficeEncryptedError
-from mineru.model.flash.legacy_office.errors import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import MAX_GRID_SLOTS
-from mineru.model.flash.legacy_office.mtef import decode_equation_native
-from mineru.model.flash.xlsx.xlsx_converter import ExcelTable, XlsxConverter
-from mineru.model.office_stream import read_stream_bytes_from_start
-from mineru.types import BlockType
+from ..legacy import BoundedOleReader, LegacyOfficeEncryptedError
+from ..legacy.errors import LegacyOfficeResourceLimitError
+from ..legacy.limits import MAX_GRID_SLOTS
+from ..legacy.mtef import decode_equation_native
+from ..xlsx.xlsx_converter import ExcelTable, XlsxConverter
+from ..legacy.stream import read_stream_bytes_from_start
+from .....types import BlockType
from .models import XlsChart, XlsChartSheet, XlsRichText, XlsSheet, XlsWorkbook
from .parser import parse_xls_workbook
diff --git a/mineru/model/flash/xlsx/__init__.py b/mineru/model/flash/office/xlsx/__init__.py
similarity index 77%
rename from mineru/model/flash/xlsx/__init__.py
rename to mineru/model/flash/office/xlsx/__init__.py
index ab4748ff..61fac43a 100644
--- a/mineru/model/flash/xlsx/__init__.py
+++ b/mineru/model/flash/office/xlsx/__init__.py
@@ -1,3 +1,5 @@
# Copyright (c) Opendatalab. All rights reserved.
"""Flash XLSX 转换实现。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/xlsx/main.py b/mineru/model/flash/office/xlsx/main.py
similarity index 93%
rename from mineru/model/flash/xlsx/main.py
rename to mineru/model/flash/office/xlsx/main.py
index 7efd1721..6938ee31 100644
--- a/mineru/model/flash/xlsx/main.py
+++ b/mineru/model/flash/office/xlsx/main.py
@@ -1,7 +1,7 @@
# Copyright (c) Opendatalab. All rights reserved.
from typing import Any, BinaryIO
-from mineru.model.flash import XlsxModel
+from ... import XlsxModel
def convert_path(file_path: str) -> list[list[dict[str, Any]]]:
diff --git a/mineru/model/flash/xlsx/ooxml_ole.py b/mineru/model/flash/office/xlsx/ooxml_ole.py
similarity index 98%
rename from mineru/model/flash/xlsx/ooxml_ole.py
rename to mineru/model/flash/office/xlsx/ooxml_ole.py
index 6159bcd5..cf49743a 100644
--- a/mineru/model/flash/xlsx/ooxml_ole.py
+++ b/mineru/model/flash/office/xlsx/ooxml_ole.py
@@ -12,13 +12,13 @@ import xml.etree.ElementTree as ET
from loguru import logger
-from mineru.model.flash.legacy_office.errors import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import MAX_ENTRY_BYTES
-from mineru.model.flash.office.image import serialize_office_image
-from mineru.model.flash.office.image_equation import (
+from ..legacy.errors import LegacyOfficeResourceLimitError
+from ..legacy.limits import MAX_ENTRY_BYTES
+from ..image import serialize_office_image
+from ..image_equation import (
OfficeImageEquationDecoder,
)
-from mineru.model.flash.office.ooxml_equation import (
+from ..ooxml_equation import (
OoxmlEquationDecoder,
is_mathtype_equation_prog_id,
)
diff --git a/mineru/model/flash/xlsx/package_normalizer.py b/mineru/model/flash/office/xlsx/package_normalizer.py
similarity index 100%
rename from mineru/model/flash/xlsx/package_normalizer.py
rename to mineru/model/flash/office/xlsx/package_normalizer.py
diff --git a/mineru/model/flash/xlsx/xlsx_converter.py b/mineru/model/flash/office/xlsx/xlsx_converter.py
similarity index 98%
rename from mineru/model/flash/xlsx/xlsx_converter.py
rename to mineru/model/flash/office/xlsx/xlsx_converter.py
index 49f431ed..3e144908 100644
--- a/mineru/model/flash/xlsx/xlsx_converter.py
+++ b/mineru/model/flash/office/xlsx/xlsx_converter.py
@@ -20,29 +20,29 @@ from PIL import Image
from pydantic import BaseModel, Field, NonNegativeInt, PositiveInt
from pydantic.dataclasses import dataclass
-from mineru.model.flash.office.image import is_vector_image, serialize_vector_image_with_placeholder
-from mineru.model.flash.office.image import serialize_office_image
-from mineru.model.flash.office.image_equation import (
+from ..image import is_vector_image, serialize_vector_image_with_placeholder
+from ..image import serialize_office_image
+from ..image_equation import (
OfficeImageEquationDecoder,
)
-from mineru.model.flash.office.ooxml_equation import OoxmlEquationDecoder
-from mineru.model.flash.legacy_office.errors import LegacyOfficeResourceLimitError
-from mineru.model.flash.legacy_office.limits import MAX_ENTRY_BYTES
-from mineru.model.flash.docx.tools.math.omml import oMath2Latex
-from mineru.model.office_stream import read_stream_bytes_from_start, rewind_stream
-from mineru.model.flash.xlsx.package_normalizer import (
+from ..ooxml_equation import OoxmlEquationDecoder
+from ..legacy.errors import LegacyOfficeResourceLimitError
+from ..legacy.limits import MAX_ENTRY_BYTES
+from ..docx.tools.math.omml import oMath2Latex
+from ..legacy.stream import read_stream_bytes_from_start, rewind_stream
+from .package_normalizer import (
normalize_xlsx_package,
strip_xlsx_ole_objects_for_openpyxl,
)
-from mineru.model.flash.xlsx.ooxml_ole import (
+from .ooxml_ole import (
XlsxOleEquationArtifact,
package_has_sheet_ole_objects,
read_sheet_image_artifacts,
read_sheet_equation_artifacts,
workbook_sheet_parts,
)
-from mineru.types import BlockType
-from mineru.utils.pdf_reader import image_to_b64str
+from .....types import BlockType
+from ...pdf.raster import image_to_b64str
AUTO_GAP_TOLERANCE_CANDIDATES = (0, 1, 2)
AUTO_GAP_TOLERANCE_PREFERENCE = {1: 0, 0: 1, 2: 2}
diff --git a/mineru/model/flash/native_pdf/__init__.py b/mineru/model/flash/pdf/__init__.py
similarity index 80%
rename from mineru/model/flash/native_pdf/__init__.py
rename to mineru/model/flash/pdf/__init__.py
index 0fbfb83e..ce36d0cf 100644
--- a/mineru/model/flash/native_pdf/__init__.py
+++ b/mineru/model/flash/pdf/__init__.py
@@ -1,3 +1,5 @@
# Copyright (c) Opendatalab. All rights reserved.
"""Flash 原生 PDF 提取的内部实现包。"""
+
+__all__: list[str] = []
diff --git a/mineru/model/flash/native_pdf/auxiliary_text.py b/mineru/model/flash/pdf/auxiliary_text.py
similarity index 99%
rename from mineru/model/flash/native_pdf/auxiliary_text.py
rename to mineru/model/flash/pdf/auxiliary_text.py
index ef482a4e..8694be2a 100644
--- a/mineru/model/flash/native_pdf/auxiliary_text.py
+++ b/mineru/model/flash/pdf/auxiliary_text.py
@@ -11,7 +11,7 @@ from difflib import SequenceMatcher
from typing import Literal
-from mineru.types import BBox
+from ....types import BBox
from .models import (
_AxisLine,
diff --git a/mineru/utils/pdf_classify.py b/mineru/model/flash/pdf/classify.py
similarity index 99%
rename from mineru/utils/pdf_classify.py
rename to mineru/model/flash/pdf/classify.py
index 6bd918ae..603b0aa1 100644
--- a/mineru/utils/pdf_classify.py
+++ b/mineru/model/flash/pdf/classify.py
@@ -13,7 +13,7 @@ from loguru import logger
from pypdf import PdfReader
from pypdf.generic import ContentStream
-from .pdfium_guard import close_pdfium_child, pdfium_guard
+from .pdfium import close_pdfium_child, pdfium_guard
MAX_SAMPLE_PAGES = 10
CHARS_THRESHOLD = 50
@@ -1156,7 +1156,7 @@ def get_high_image_coverage_ratio_pdfium(pdf_doc: pdfium.PdfDocument, page_indic
if __name__ == "__main__":
- from .pdf_document import PDFDocument
+ from .document import PDFDocument
with open("/Users/myhloli/pdf/luanma2x10.pdf", "rb") as f:
p_bytes = f.read()
diff --git a/mineru/model/flash/native_pdf/code_blocks.py b/mineru/model/flash/pdf/code_blocks.py
similarity index 99%
rename from mineru/model/flash/native_pdf/code_blocks.py
rename to mineru/model/flash/pdf/code_blocks.py
index 95f3a0c4..ce26995a 100644
--- a/mineru/model/flash/native_pdf/code_blocks.py
+++ b/mineru/model/flash/pdf/code_blocks.py
@@ -9,9 +9,9 @@ import statistics
import unicodedata
from typing import Any
-from mineru.utils.spatial_text import project_pdf_spatial_text
-from mineru.types import BBox
-from mineru.utils.pdf_document import PDFPathInfo
+from .spatial_text import project_pdf_spatial_text
+from ....types import BBox
+from .document import PDFPathInfo
from .geometry import (
_bbox_area,
diff --git a/mineru/utils/draw_bbox.py b/mineru/model/flash/pdf/diagnostics.py
similarity index 99%
rename from mineru/utils/draw_bbox.py
rename to mineru/model/flash/pdf/diagnostics.py
index 8b46d1ff..9de7f9a6 100644
--- a/mineru/utils/draw_bbox.py
+++ b/mineru/model/flash/pdf/diagnostics.py
@@ -9,7 +9,7 @@ from loguru import logger
from pypdf import PageObject, PdfReader, PdfWriter
from reportlab.pdfgen import canvas
-from ..types import BBox, RAW_PHONETIC, Block, BlockType, ContentType, PageInfo, Span
+from ....types import BBox, RAW_PHONETIC, Block, BlockType, ContentType, PageInfo, Span
# 文本类 block 共用 text bbox 样式,避免新增文本形态时遗漏多个绘制入口。
TEXT_LIKE_BLOCK_TYPES_FOR_BBOX = {
@@ -448,7 +448,7 @@ if __name__ == "__main__":
with open(json_path, "r", encoding="utf-8") as f:
pdf_ann = json.load(f)
pdf_info = pdf_ann["pdf_info"]
- from mineru.utils.pdf_document import PDFDocument
+ from .document import PDFDocument
doc = PDFDocument(pdf_bytes)
doc.draw_layout_bbox(pdf_info, "examples/output_with_layout.pdf")
diff --git a/mineru/utils/pdf_document.py b/mineru/model/flash/pdf/document.py
similarity index 99%
rename from mineru/utils/pdf_document.py
rename to mineru/model/flash/pdf/document.py
index 409007ac..90ffb4fe 100644
--- a/mineru/utils/pdf_document.py
+++ b/mineru/model/flash/pdf/document.py
@@ -21,11 +21,11 @@ from pdftext.pdf.pages import assign_scripts, get_lines, get_spans
from pdftext.schema import Bbox, Char, Line
from PIL import Image, ImageOps
-from ..types import BBox, PageInfo
-from .pdf_classify import classify
-from .pdf_image_tools import get_crop_img
-from .pdf_reader import image_to_bytes
-from .pdfium_guard import _pdfium_lock
+from ....types import BBox, PageInfo
+from ....utils.image import crop_pil_image
+from .classify import classify
+from .pdfium import _pdfium_lock
+from .raster import image_to_bytes
logger = logging.getLogger(__name__)
@@ -358,7 +358,7 @@ class PDFDocument:
image = self.render_page(page_idx, scale=scale)
crop = None
try:
- crop = get_crop_img(bbox, image.pil_image, scale=image.scale)
+ crop = crop_pil_image(bbox, image.pil_image, scale=image.scale)
return image_to_bytes(crop, image_format="JPEG")
finally:
if crop is not None:
@@ -502,14 +502,14 @@ class PDFDocument:
# ------------------------------------------------------------------ #
def draw_layout_bbox(self, pages: list[PageInfo], output_path: str) -> None:
- from .draw_bbox import draw_layout_bbox
+ from .diagnostics import draw_layout_bbox
out_dir = os.path.dirname(output_path) or "."
filename = os.path.basename(output_path)
draw_layout_bbox(pages, self._pdf_bytes, out_dir, filename)
def draw_span_bbox(self, pages: list[PageInfo], output_path: str) -> None:
- from .draw_bbox import draw_span_bbox
+ from .diagnostics import draw_span_bbox
out_dir = os.path.dirname(output_path) or "."
filename = os.path.basename(output_path)
diff --git a/mineru/model/flash/native_pdf/formulas.py b/mineru/model/flash/pdf/formulas.py
similarity index 99%
rename from mineru/model/flash/native_pdf/formulas.py
rename to mineru/model/flash/pdf/formulas.py
index 6583dc22..6c03d908 100644
--- a/mineru/model/flash/native_pdf/formulas.py
+++ b/mineru/model/flash/pdf/formulas.py
@@ -10,9 +10,9 @@ from dataclasses import dataclass, replace
from typing import Any
-from mineru.types import BBox
-from mineru.utils.pdf_document import PDFPathInfo
-from mineru.utils.text_utils import build_tagged_formula_content
+from ....types import BBox
+from .document import PDFPathInfo
+from ....utils.text import build_tagged_formula_content
from .models import (
_FormulaAnchor,
diff --git a/mineru/model/flash/native_pdf/geometry.py b/mineru/model/flash/pdf/geometry.py
similarity index 99%
rename from mineru/model/flash/native_pdf/geometry.py
rename to mineru/model/flash/pdf/geometry.py
index 4432029c..6cfda4d2 100644
--- a/mineru/model/flash/native_pdf/geometry.py
+++ b/mineru/model/flash/pdf/geometry.py
@@ -8,7 +8,7 @@ import math
from typing import Any, Literal, Sequence
-from mineru.types import BBox
+from ....types import BBox
from .models import (
_AxisLine,
diff --git a/mineru/model/flash/native_pdf/graphics.py b/mineru/model/flash/pdf/graphics.py
similarity index 99%
rename from mineru/model/flash/native_pdf/graphics.py
rename to mineru/model/flash/pdf/graphics.py
index 6f083d28..30d4ee03 100644
--- a/mineru/model/flash/native_pdf/graphics.py
+++ b/mineru/model/flash/pdf/graphics.py
@@ -11,8 +11,8 @@ import statistics
from typing import Any
-from mineru.types import BBox
-from mineru.utils.pdf_document import PDFPathInfo
+from ....types import BBox
+from .document import PDFPathInfo
from .models import (
_AxisLine,
diff --git a/mineru/model/flash/native_pdf/index_blocks.py b/mineru/model/flash/pdf/index_blocks.py
similarity index 99%
rename from mineru/model/flash/native_pdf/index_blocks.py
rename to mineru/model/flash/pdf/index_blocks.py
index c6cd494e..6a7e46ac 100644
--- a/mineru/model/flash/native_pdf/index_blocks.py
+++ b/mineru/model/flash/pdf/index_blocks.py
@@ -10,7 +10,7 @@ import re
import statistics
-from mineru.types import BBox, BlockType
+from ....types import BBox, BlockType
from .models import _LineItem
from .geometry import (
diff --git a/mineru/model/flash/native_pdf/line_layout.py b/mineru/model/flash/pdf/line_layout.py
similarity index 99%
rename from mineru/model/flash/native_pdf/line_layout.py
rename to mineru/model/flash/pdf/line_layout.py
index 6760d26a..15127358 100644
--- a/mineru/model/flash/native_pdf/line_layout.py
+++ b/mineru/model/flash/pdf/line_layout.py
@@ -9,8 +9,8 @@ import re
import statistics
-from mineru.utils.text_utils import is_hyphen_at_line_end
-from mineru.types import BBox
+from ....utils.text import is_hyphen_at_line_end
+from ....types import BBox
from .models import (
_LineItem,
diff --git a/mineru/model/flash/native_pdf/line_merging.py b/mineru/model/flash/pdf/line_merging.py
similarity index 99%
rename from mineru/model/flash/native_pdf/line_merging.py
rename to mineru/model/flash/pdf/line_merging.py
index e1d83289..5447501e 100644
--- a/mineru/model/flash/native_pdf/line_merging.py
+++ b/mineru/model/flash/pdf/line_merging.py
@@ -7,7 +7,7 @@ from __future__ import annotations
import statistics
-from mineru.types import BBox
+from ....types import BBox
from .models import (
_LineItem,
diff --git a/mineru/model/flash/native_pdf/models.py b/mineru/model/flash/pdf/models.py
similarity index 98%
rename from mineru/model/flash/native_pdf/models.py
rename to mineru/model/flash/pdf/models.py
index dab80037..28c51f71 100644
--- a/mineru/model/flash/native_pdf/models.py
+++ b/mineru/model/flash/pdf/models.py
@@ -9,8 +9,8 @@ from typing import Any, Literal
from pdftext.schema import Char
-from mineru.types import BBox
-from mineru.utils.pdf_document import PDFPathInfo
+from ....types import BBox
+from .document import PDFPathInfo
@dataclass(slots=True)
diff --git a/mineru/model/flash/native_pdf/native_text.py b/mineru/model/flash/pdf/native_text.py
similarity index 99%
rename from mineru/model/flash/native_pdf/native_text.py
rename to mineru/model/flash/pdf/native_text.py
index b3f334e8..004629e4 100644
--- a/mineru/model/flash/native_pdf/native_text.py
+++ b/mineru/model/flash/pdf/native_text.py
@@ -11,8 +11,8 @@ from typing import Any, Literal, Sequence
from pdftext.schema import Char
-from mineru.types import BBox
-from mineru.utils.pdf_document import PDFDocument
+from ....types import BBox
+from .document import PDFDocument
from .models import (
_AxisLine,
diff --git a/mineru/utils/pdfium_guard.py b/mineru/model/flash/pdf/pdfium.py
similarity index 100%
rename from mineru/utils/pdfium_guard.py
rename to mineru/model/flash/pdf/pdfium.py
diff --git a/mineru/model/flash/native_pdf/pipeline.py b/mineru/model/flash/pdf/pipeline.py
similarity index 99%
rename from mineru/model/flash/native_pdf/pipeline.py
rename to mineru/model/flash/pdf/pipeline.py
index 785a291d..10a447d8 100644
--- a/mineru/model/flash/native_pdf/pipeline.py
+++ b/mineru/model/flash/pdf/pipeline.py
@@ -8,9 +8,9 @@ from dataclasses import replace
from typing import Any
-from mineru.model.flash.xycut import sort_entries
-from mineru.utils.pdf_document import PDFDocument, PDFImageInfo, get_lines_from_chars
-from mineru.utils.pdf_text_styles import (
+from .._shared.xycut import sort_entries
+from .document import PDFDocument, PDFImageInfo, get_lines_from_chars
+from .text_styles import (
PDFTextLinkLine,
PDFTextStyleLine,
apply_pdf_text_links,
diff --git a/mineru/utils/pdf_reader.py b/mineru/model/flash/pdf/raster.py
similarity index 97%
rename from mineru/utils/pdf_reader.py
rename to mineru/model/flash/pdf/raster.py
index 1d9d6569..5c1256a3 100644
--- a/mineru/utils/pdf_reader.py
+++ b/mineru/model/flash/pdf/raster.py
@@ -6,7 +6,7 @@ from loguru import logger
from PIL import Image
from pypdfium2 import PdfBitmap, PdfPage
-from .pdfium_guard import pdfium_guard
+from .pdfium import pdfium_guard
def page_to_image(
diff --git a/mineru/utils/spatial_text.py b/mineru/model/flash/pdf/spatial_text.py
similarity index 99%
rename from mineru/utils/spatial_text.py
rename to mineru/model/flash/pdf/spatial_text.py
index c63a9dbe..904824e6 100644
--- a/mineru/utils/spatial_text.py
+++ b/mineru/model/flash/pdf/spatial_text.py
@@ -10,7 +10,7 @@ from typing import Any
import numpy as np
from pdftext.schema import Char
-from mineru.types import BBox
+from ....types import BBox
# 空间投影思路参考 LiteParse v2.6.0 的字符分段和网格投影;
diff --git a/mineru/utils/native_pdf_table/__init__.py b/mineru/model/flash/pdf/table_recovery/__init__.py
similarity index 100%
rename from mineru/utils/native_pdf_table/__init__.py
rename to mineru/model/flash/pdf/table_recovery/__init__.py
diff --git a/mineru/utils/native_pdf_table/candidate.py b/mineru/model/flash/pdf/table_recovery/candidate.py
similarity index 99%
rename from mineru/utils/native_pdf_table/candidate.py
rename to mineru/model/flash/pdf/table_recovery/candidate.py
index 6f892037..02d08979 100644
--- a/mineru/utils/native_pdf_table/candidate.py
+++ b/mineru/model/flash/pdf/table_recovery/candidate.py
@@ -7,7 +7,7 @@ import html
from bisect import bisect_left, bisect_right
from dataclasses import dataclass
-from mineru.types import BBox
+from .....types import BBox
from .contracts import (
NativeTableCandidate,
diff --git a/mineru/utils/native_pdf_table/contracts.py b/mineru/model/flash/pdf/table_recovery/contracts.py
similarity index 99%
rename from mineru/utils/native_pdf_table/contracts.py
rename to mineru/model/flash/pdf/table_recovery/contracts.py
index 2e5927a8..24853656 100644
--- a/mineru/utils/native_pdf_table/contracts.py
+++ b/mineru/model/flash/pdf/table_recovery/contracts.py
@@ -8,7 +8,7 @@ from typing import Literal
from pdftext.schema import Char
-from mineru.types import BBox
+from .....types import BBox
NativeTableCandidateSource = Literal[
"vector_grid",
diff --git a/mineru/utils/native_pdf_table/engine.py b/mineru/model/flash/pdf/table_recovery/engine.py
similarity index 100%
rename from mineru/utils/native_pdf_table/engine.py
rename to mineru/model/flash/pdf/table_recovery/engine.py
diff --git a/mineru/utils/native_pdf_table/geometry.py b/mineru/model/flash/pdf/table_recovery/geometry.py
similarity index 99%
rename from mineru/utils/native_pdf_table/geometry.py
rename to mineru/model/flash/pdf/table_recovery/geometry.py
index b3996d45..981371d0 100644
--- a/mineru/utils/native_pdf_table/geometry.py
+++ b/mineru/model/flash/pdf/table_recovery/geometry.py
@@ -5,7 +5,7 @@ from __future__ import annotations
from collections.abc import Iterable
-from mineru.types import BBox
+from .....types import BBox
def normalize_bbox(value: object) -> BBox | None:
diff --git a/mineru/utils/native_pdf_table/sparse_hybrid.py b/mineru/model/flash/pdf/table_recovery/sparse_hybrid.py
similarity index 100%
rename from mineru/utils/native_pdf_table/sparse_hybrid.py
rename to mineru/model/flash/pdf/table_recovery/sparse_hybrid.py
diff --git a/mineru/utils/native_pdf_table/sparse_multiline.py b/mineru/model/flash/pdf/table_recovery/sparse_multiline.py
similarity index 100%
rename from mineru/utils/native_pdf_table/sparse_multiline.py
rename to mineru/model/flash/pdf/table_recovery/sparse_multiline.py
diff --git a/mineru/utils/native_pdf_table/text.py b/mineru/model/flash/pdf/table_recovery/text.py
similarity index 99%
rename from mineru/utils/native_pdf_table/text.py
rename to mineru/model/flash/pdf/table_recovery/text.py
index 38c28e0e..53f2a9cb 100644
--- a/mineru/utils/native_pdf_table/text.py
+++ b/mineru/model/flash/pdf/table_recovery/text.py
@@ -8,8 +8,8 @@ from dataclasses import dataclass
from pdftext.schema import Char
-from mineru.types import BBox
-from mineru.utils.spatial_text import _normalize_table_text
+from .....types import BBox
+from ..spatial_text import _normalize_table_text
from .contracts import (
NativeTableGlyph,
diff --git a/mineru/utils/native_pdf_table/text_grid.py b/mineru/model/flash/pdf/table_recovery/text_grid.py
similarity index 100%
rename from mineru/utils/native_pdf_table/text_grid.py
rename to mineru/model/flash/pdf/table_recovery/text_grid.py
diff --git a/mineru/utils/native_pdf_table/vector.py b/mineru/model/flash/pdf/table_recovery/vector.py
similarity index 100%
rename from mineru/utils/native_pdf_table/vector.py
rename to mineru/model/flash/pdf/table_recovery/vector.py
diff --git a/mineru/model/flash/native_pdf/tables.py b/mineru/model/flash/pdf/tables.py
similarity index 99%
rename from mineru/model/flash/native_pdf/tables.py
rename to mineru/model/flash/pdf/tables.py
index 06bc5d88..8413f618 100644
--- a/mineru/model/flash/native_pdf/tables.py
+++ b/mineru/model/flash/pdf/tables.py
@@ -12,7 +12,7 @@ from typing import Any, Literal
from loguru import logger
from pdftext.schema import Char
-from mineru.utils.native_pdf_table import (
+from .table_recovery import (
NativeTableInput,
NativeTableRectangle,
NativeTableRule,
@@ -20,11 +20,11 @@ from mineru.utils.native_pdf_table import (
coerce_native_table_rules,
recover_native_pdf_table,
)
-from mineru.utils.text_utils import merge_text_line_contents
-from mineru.utils.spatial_text import project_pdf_table_text
-from mineru.types import BBox
-from mineru.utils.pdf_document import PDFPathInfo
-from mineru.utils.language import detect_lang
+from ....utils.text import merge_text_line_contents
+from .spatial_text import project_pdf_table_text
+from ....types import BBox
+from .document import PDFPathInfo
+from ....utils.language import detect_lang
from .models import (
_Fragment,
diff --git a/mineru/model/flash/native_pdf/text_blocks.py b/mineru/model/flash/pdf/text_blocks.py
similarity index 99%
rename from mineru/model/flash/native_pdf/text_blocks.py
rename to mineru/model/flash/pdf/text_blocks.py
index 56c46ffc..587f48db 100644
--- a/mineru/model/flash/native_pdf/text_blocks.py
+++ b/mineru/model/flash/pdf/text_blocks.py
@@ -9,12 +9,12 @@ import statistics
from typing import Any, Sequence
-from mineru.utils.text_utils import (
+from ....utils.text import (
is_hyphen_at_line_end,
merge_text_line_contents,
)
-from mineru.types import BBox
-from mineru.utils.language import detect_lang
+from ....types import BBox
+from ....utils.language import detect_lang
from .models import (
_AxisLine,
diff --git a/mineru/utils/pdf_text_styles.py b/mineru/model/flash/pdf/text_styles.py
similarity index 99%
rename from mineru/utils/pdf_text_styles.py
rename to mineru/model/flash/pdf/text_styles.py
index faecb131..c15d9067 100644
--- a/mineru/utils/pdf_text_styles.py
+++ b/mineru/model/flash/pdf/text_styles.py
@@ -12,9 +12,9 @@ from typing import Any, Iterable, Literal, Sequence, TypeVar, cast
from loguru import logger
-from mineru.types import BBox, BlockType, RAW_CAPTION, RAW_FOOTNOTE
-from mineru.utils.pdf_document import PDFLinkAnnotation
-from mineru.utils.text_utils import is_hyphen_at_line_end
+from ....types import BBox, BlockType, RAW_CAPTION, RAW_FOOTNOTE
+from .document import PDFLinkAnnotation
+from ....utils.text import is_hyphen_at_line_end
TEXT_DECORATION_MIN_LENGTH_HEIGHT_RATIO = 1.8
diff --git a/mineru/model/flash/native_pdf/titles.py b/mineru/model/flash/pdf/titles.py
similarity index 99%
rename from mineru/model/flash/native_pdf/titles.py
rename to mineru/model/flash/pdf/titles.py
index 63629108..fa4e8e81 100644
--- a/mineru/model/flash/native_pdf/titles.py
+++ b/mineru/model/flash/pdf/titles.py
@@ -9,8 +9,8 @@ from dataclasses import replace
from typing import Literal
-from mineru.types import BBox
-from mineru.utils.pdf_text_styles import (
+from ....types import BBox
+from .text_styles import (
PDF_FONT_FORCE_BOLD_FLAG,
PDF_FONT_ITALIC_FLAG,
)
diff --git a/mineru/model/flash/native_pdf/visual_annotations.py b/mineru/model/flash/pdf/visual_annotations.py
similarity index 99%
rename from mineru/model/flash/native_pdf/visual_annotations.py
rename to mineru/model/flash/pdf/visual_annotations.py
index 3ec2a1cb..8db8fdcf 100644
--- a/mineru/model/flash/native_pdf/visual_annotations.py
+++ b/mineru/model/flash/pdf/visual_annotations.py
@@ -12,8 +12,8 @@ from dataclasses import dataclass
from typing import Any, Literal
-from mineru.model.flash.xycut import sort_entries
-from mineru.types import BBox
+from .._shared.xycut import sort_entries
+from ....types import BBox
from .geometry import (
_bbox_center_x,