@@ -0,0 +1,31 @@
|
||||
"""PDF parser entry point — delegates to the PyMuPDF pipeline."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from rag_cut.models import Block
|
||||
from rag_cut.parsers.base import BaseParser
|
||||
from rag_cut.parsers.mineru_adapter import parse_pdf_with_mineru
|
||||
from rag_cut.parsers.pdf.noise_filter import filter_noise_blocks
|
||||
from rag_cut.parsers.pdf.pipeline import parse_pdf
|
||||
|
||||
|
||||
class PdfParser(BaseParser):
|
||||
def parse(self, path: Path, assets_dir: Path) -> list[Block]:
|
||||
engine = os.getenv("RAG_CUT_PDF_ENGINE", "auto").strip().lower()
|
||||
if engine not in {"auto", "mineru", "pymupdf"}:
|
||||
engine = "auto"
|
||||
|
||||
blocks: list[Block] | None = None
|
||||
if engine in {"auto", "mineru"}:
|
||||
blocks = parse_pdf_with_mineru(path, assets_dir)
|
||||
if blocks is None and engine == "mineru":
|
||||
raise RuntimeError("MinerU parsing failed or MinerU is not installed")
|
||||
|
||||
if blocks is None:
|
||||
blocks = parse_pdf(path, assets_dir)
|
||||
|
||||
# filter_noise_blocks already includes TOC removal.
|
||||
return filter_noise_blocks(blocks)
|
||||
Reference in New Issue
Block a user