Class HybridMlParser


public class HybridMlParser extends HybridParser
Experimental hybrid parser that invokes an injected ML extractor only when the existing Stream, Lattice, and OCR strategies return no tables.

This keeps ML optional and preserves the current deterministic parser behaviour. The ML implementation can live in a separate module and may use ONNX Runtime without introducing that dependency into the core module.

  • Constructor Details

    • HybridMlParser

      public HybridMlParser(String filepath, MlTableExtractor mlExtractor)
      Creates an ML-enabled hybrid parser for a file.
      Parameters:
      filepath - PDF path
      mlExtractor - optional ML extraction strategy
    • HybridMlParser

      public HybridMlParser(MlTableExtractor mlExtractor)
      Creates an ML-enabled parser for in-memory PDFBox documents.
      Parameters:
      mlExtractor - optional ML extraction strategy
  • Method Details

    • enableMlFallback

      public HybridMlParser enableMlFallback(boolean enabled)
      Enables or disables ML fallback. Enabled by default for this parser.
    • failOnMlError

      public HybridMlParser failOnMlError(boolean enabled)
      Controls whether ML inference errors fail parsing or fall back to an empty ML result. The default is false.
    • pages

      public HybridMlParser pages(String pages)
      Description copied from class: HybridParser
      Sets the page selection for this parser and propagates the same selection to all underlying strategies.
      Overrides:
      pages in class HybridParser
      Parameters:
      pages - page selection string (e.g., "all", "1", "2-5", "1,3-4")
      Returns:
      this parser
    • dpi

      public HybridMlParser dpi(float dpi)
      Description copied from class: HybridParser
      Sets DPI for image-based parsing (used by lattice + OCR strategies).
      Overrides:
      dpi in class HybridParser
      Parameters:
      dpi - dots per inch used for rasterization (e.g., 300f for scans)
      Returns:
      this parser
    • debug

      public HybridMlParser debug(boolean enabled)
      Description copied from class: HybridParser
      Enables or disables debug outputs for lattice/OCR strategies.
      Overrides:
      debug in class HybridParser
      Parameters:
      enabled - true to enable, false to disable
      Returns:
      this parser
    • stripText

      public HybridMlParser stripText(boolean strip)
      Description copied from class: HybridParser
      Enables or disables text normalization for stream-style extraction across all underlying strategies.
      Overrides:
      stripText in class HybridParser
      Parameters:
      strip - true to normalize/strip text, false to keep raw text
      Returns:
      this parser (for chaining)
    • parsePage

      protected List<Table> parsePage(int page) throws IOException
      Description copied from class: HybridParser
      Runs stream, lattice, and OCR-backed stream for the requested page(s) and returns the best-scoring set of tables.

      If page == -1, each strategy is run across all pages. Otherwise, each strategy is temporarily narrowed to the single requested page (restoring the original page spec afterward).

      Overrides:
      parsePage in class HybridParser
      Parameters:
      page - page index to parse, or -1 to parse all pages
      Returns:
      the winning list of Table objects (possibly empty)
      Throws:
      IOException - if an underlying parser fails
    • parse

      public List<Table> parse(org.apache.pdfbox.pdmodel.PDDocument document) throws IOException
      Description copied from class: BaseParser
      Parses a previously loaded PDF document. This is the preferred method for in-memory processing.
      Overrides:
      parse in class HybridParser
      Parameters:
      document - The PDDocument to parse.
      Returns:
      A list of extracted tables.
      Throws:
      IOException - for I/O issues during parsing.