Package com.extractpdf4j.parsers
Class HybridMlParser
java.lang.Object
com.extractpdf4j.parsers.BaseParser
com.extractpdf4j.parsers.HybridParser
com.extractpdf4j.parsers.HybridMlParser
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.
-
Field Summary
Fields inherited from class com.extractpdf4j.parsers.BaseParser
diagnosticsEnabled, filepath, pages, stripText -
Constructor Summary
ConstructorsConstructorDescriptionHybridMlParser(MlTableExtractor mlExtractor) Creates an ML-enabled parser for in-memory PDFBox documents.HybridMlParser(String filepath, MlTableExtractor mlExtractor) Creates an ML-enabled hybrid parser for a file. -
Method Summary
Modifier and TypeMethodDescriptiondebug(boolean enabled) Enables or disables debug outputs for lattice/OCR strategies.dpi(float dpi) Sets DPI for image-based parsing (used by lattice + OCR strategies).enableMlFallback(boolean enabled) Enables or disables ML fallback.failOnMlError(boolean enabled) Controls whether ML inference errors fail parsing or fall back to an empty ML result.Sets the page selection for this parser and propagates the same selection to all underlying strategies.parse(org.apache.pdfbox.pdmodel.PDDocument document) Parses a previously loaded PDF document.parsePage(int page) Runs stream, lattice, and OCR-backed stream for the requested page(s) and returns the best-scoring set of tables.stripText(boolean strip) Enables or disables text normalization for stream-style extraction across all underlying strategies.Methods inherited from class com.extractpdf4j.parsers.HybridParser
debugDir, diagnostics, keepCells, minScore, parseResultMethods inherited from class com.extractpdf4j.parsers.BaseParser
collectWarnings, finalizeResults, pagesProcessedCount, parse, parserSelection
-
Constructor Details
-
HybridMlParser
Creates an ML-enabled hybrid parser for a file.- Parameters:
filepath- PDF pathmlExtractor- optional ML extraction strategy
-
HybridMlParser
Creates an ML-enabled parser for in-memory PDFBox documents.- Parameters:
mlExtractor- optional ML extraction strategy
-
-
Method Details
-
enableMlFallback
Enables or disables ML fallback. Enabled by default for this parser. -
failOnMlError
Controls whether ML inference errors fail parsing or fall back to an empty ML result. The default isfalse. -
pages
Description copied from class:HybridParserSets the page selection for this parser and propagates the same selection to all underlying strategies.- Overrides:
pagesin classHybridParser- Parameters:
pages- page selection string (e.g.,"all","1","2-5","1,3-4")- Returns:
- this parser
-
dpi
Description copied from class:HybridParserSets DPI for image-based parsing (used by lattice + OCR strategies).- Overrides:
dpiin classHybridParser- Parameters:
dpi- dots per inch used for rasterization (e.g., 300f for scans)- Returns:
- this parser
-
debug
Description copied from class:HybridParserEnables or disables debug outputs for lattice/OCR strategies.- Overrides:
debugin classHybridParser- Parameters:
enabled-trueto enable,falseto disable- Returns:
- this parser
-
stripText
Description copied from class:HybridParserEnables or disables text normalization for stream-style extraction across all underlying strategies.- Overrides:
stripTextin classHybridParser- Parameters:
strip-trueto normalize/strip text,falseto keep raw text- Returns:
- this parser (for chaining)
-
parsePage
Description copied from class:HybridParserRuns 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:
parsePagein classHybridParser- Parameters:
page- page index to parse, or-1to parse all pages- Returns:
- the winning list of
Tableobjects (possibly empty) - Throws:
IOException- if an underlying parser fails
-
parse
Description copied from class:BaseParserParses a previously loaded PDF document. This is the preferred method for in-memory processing.- Overrides:
parsein classHybridParser- Parameters:
document- The PDDocument to parse.- Returns:
- A list of extracted tables.
- Throws:
IOException- for I/O issues during parsing.
-