pub struct OARStructureBuilder { /* private fields */ }Expand description
High-level builder for document structure analysis pipelines.
This builder provides a fluent API for constructing document structure analysis pipelines with various components:
- Document preprocessing (optional): orientation detection and rectification
- Layout detection (required)
- Table classification (optional)
- Table cell detection (optional)
- Table structure recognition (optional)
- Formula recognition (optional)
- Seal text detection (optional)
- OCR integration (optional)
§Example
use oar_ocr::oarocr::structure::OARStructureBuilder;
let structure = OARStructureBuilder::new("models/layout.onnx")
.with_table_classification("models/table_cls.onnx")
.with_table_cell_detection("models/table_cell.onnx", "wired")
.with_table_structure_recognition("models/table_struct.onnx", "wired")
.with_formula_recognition(
"models/formula.onnx",
"models/tokenizer.json",
"pp_formulanet"
)
.build()?;Implementations§
Source§impl OARStructureBuilder
impl OARStructureBuilder
Sourcepub fn new(layout_detection_model: impl Into<PathBuf>) -> Self
pub fn new(layout_detection_model: impl Into<PathBuf>) -> Self
Creates a new structure builder with the required layout detection model.
§Arguments
layout_detection_model- Path to the layout detection model file
Sourcepub fn ort_session(self, config: OrtSessionConfig) -> Self
pub fn ort_session(self, config: OrtSessionConfig) -> Self
Sets the ONNX Runtime session configuration.
This configuration will be applied to all models in the pipeline.
Sourcepub fn layout_detection_config(self, config: LayoutDetectionConfig) -> Self
pub fn layout_detection_config(self, config: LayoutDetectionConfig) -> Self
Sets the layout detection model configuration.
Sourcepub fn layout_model_name(self, name: impl Into<String>) -> Self
pub fn layout_model_name(self, name: impl Into<String>) -> Self
Overrides the built-in layout model preset used to configure preprocessing/postprocessing.
This is useful when the ONNX file name alone is not enough to infer the correct model family. Supported presets include:
pp-doclayout_plus-l(default)pp-doclayout-s,pp-doclayout-m,pp-doclayout-lpp-docblocklayoutpicodet_layout_1x,picodet_layout_1x_tablert-detr-h_layout_3cls,rt-detr-h_layout_17cls
Sourcepub fn region_model_name(self, name: impl Into<String>) -> Self
pub fn region_model_name(self, name: impl Into<String>) -> Self
Sets the region detection model name preset.
This is used to load the correct preprocessing/postprocessing for the region
detection model. Supported presets: PP-DocBlockLayout.
Sourcepub fn wired_table_structure_model_name(self, name: impl Into<String>) -> Self
pub fn wired_table_structure_model_name(self, name: impl Into<String>) -> Self
Sets the wired table structure model name preset.
Supported presets: SLANet, SLANeXt_wired.
Sourcepub fn wireless_table_structure_model_name(
self,
name: impl Into<String>,
) -> Self
pub fn wireless_table_structure_model_name( self, name: impl Into<String>, ) -> Self
Sets the wireless table structure model name preset.
Supported presets: SLANet_plus.
Sourcepub fn wired_table_cell_model_name(self, name: impl Into<String>) -> Self
pub fn wired_table_cell_model_name(self, name: impl Into<String>) -> Self
Sets the wired table cell detection model name preset.
Supported presets: RT-DETR-L_wired_table_cell_det.
Sourcepub fn wireless_table_cell_model_name(self, name: impl Into<String>) -> Self
pub fn wireless_table_cell_model_name(self, name: impl Into<String>) -> Self
Sets the wireless table cell detection model name preset.
Supported presets: RT-DETR-L_wireless_table_cell_det.
Sourcepub fn text_detection_model_name(self, name: impl Into<String>) -> Self
pub fn text_detection_model_name(self, name: impl Into<String>) -> Self
Sets the text detection model name preset.
Supported presets: PP-OCRv5_mobile_det, PP-OCRv5_server_det.
Sourcepub fn text_recognition_model_name(self, name: impl Into<String>) -> Self
pub fn text_recognition_model_name(self, name: impl Into<String>) -> Self
Sets the text recognition model name preset.
Supported presets: PP-OCRv5_mobile_rec, PP-OCRv5_server_rec.
Sourcepub fn image_batch_size(self, size: usize) -> Self
pub fn image_batch_size(self, size: usize) -> Self
Sets the batch size for image-level processing.
Note: Currently not used in structure analysis as each image is processed individually.
Sourcepub fn region_batch_size(self, size: usize) -> Self
pub fn region_batch_size(self, size: usize) -> Self
Sets the batch size for region-level processing (text recognition).
Controls how many text regions are processed together during OCR recognition. Larger values improve throughput but use more memory.
Sourcepub fn with_document_orientation(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_document_orientation(self, model_path: impl Into<PathBuf>) -> Self
Adds document orientation detection to the pipeline.
This component detects and corrects document rotation (0°, 90°, 180°, 270°). Should be run before other processing for best results.
Sourcepub fn with_document_rectification(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_document_rectification(self, model_path: impl Into<PathBuf>) -> Self
Adds document rectification to the pipeline.
This component corrects document distortion and perspective issues. Should be run after orientation detection if both are enabled.
Sourcepub fn with_region_detection(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_region_detection(self, model_path: impl Into<PathBuf>) -> Self
Adds region detection to the pipeline (PP-DocBlockLayout).
This component detects document regions (columns, blocks) for hierarchical layout ordering. Region blocks provide grouping information for improved reading order within multi-column or complex layouts.
§PP-StructureV3 Integration
When enabled, the pipeline uses region detection results to:
- Group layout elements by their parent regions
- Apply XY-cut ordering within each region
- Order regions based on their relative positions
Sourcepub fn with_seal_text_detection(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_seal_text_detection(self, model_path: impl Into<PathBuf>) -> Self
Adds seal text detection to the pipeline.
This component detects circular/curved seal and stamp text regions. Seal regions will be included in the layout elements.
Sourcepub fn with_table_classification(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_table_classification(self, model_path: impl Into<PathBuf>) -> Self
Adds table classification to the pipeline.
This component classifies tables as wired or wireless.
Sourcepub fn table_classification_config(
self,
config: TableClassificationConfig,
) -> Self
pub fn table_classification_config( self, config: TableClassificationConfig, ) -> Self
Sets the table classification configuration.
Sourcepub fn with_table_orientation(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_table_orientation(self, model_path: impl Into<PathBuf>) -> Self
Adds table orientation detection to the pipeline.
This component detects if tables are rotated (0°, 90°, 180°, 270°) and corrects them before structure recognition. Uses the same model as document orientation detection (PP-LCNet_x1_0_doc_ori).
§Arguments
model_path- Path to the orientation classification model (same as document orientation)
Sourcepub fn use_e2e_wired_table_rec(self, enabled: bool) -> Self
pub fn use_e2e_wired_table_rec(self, enabled: bool) -> Self
Sets whether to use end-to-end mode for wired table recognition.
When enabled, cell detection model is skipped and only the table structure recognition model’s cell output is used. When disabled, RT-DETR cell detection provides more precise cell bounding boxes.
Default: false (use cell detection for wired tables)
Sourcepub fn use_e2e_wireless_table_rec(self, enabled: bool) -> Self
pub fn use_e2e_wireless_table_rec(self, enabled: bool) -> Self
Sets whether to use end-to-end mode for wireless table recognition.
When enabled, cell detection model is skipped and only the table structure recognition model’s cell output is used. When disabled, RT-DETR cell detection provides more precise cell bounding boxes.
Default: true (E2E mode for wireless tables)
Sourcepub fn use_wired_table_cells_trans_to_html(self, enabled: bool) -> Self
pub fn use_wired_table_cells_trans_to_html(self, enabled: bool) -> Self
Enables PaddleX-compatible conversion of wired cell detections to HTML structure tokens.
When enabled, wired tables can derive structure tokens directly from detected cell boxes,
which is useful for parity testing with PaddleX use_wired_table_cells_trans_to_html.
Sourcepub fn use_wireless_table_cells_trans_to_html(self, enabled: bool) -> Self
pub fn use_wireless_table_cells_trans_to_html(self, enabled: bool) -> Self
Enables PaddleX-compatible conversion of wireless cell detections to HTML structure tokens.
When enabled, wireless tables can derive structure tokens directly from detected cell boxes,
which is useful for parity testing with PaddleX use_wireless_table_cells_trans_to_html.
Sourcepub fn with_table_cell_detection(
self,
model_path: impl Into<PathBuf>,
cell_type: impl Into<String>,
) -> Self
pub fn with_table_cell_detection( self, model_path: impl Into<PathBuf>, cell_type: impl Into<String>, ) -> Self
Adds table cell detection to the pipeline.
§Arguments
model_path- Path to the table cell detection modelcell_type- Type of cells to detect: “wired” or “wireless”
Sourcepub fn table_cell_detection_config(
self,
config: TableCellDetectionConfig,
) -> Self
pub fn table_cell_detection_config( self, config: TableCellDetectionConfig, ) -> Self
Sets the table cell detection configuration.
Sourcepub fn with_table_structure_recognition(
self,
model_path: impl Into<PathBuf>,
table_type: impl Into<String>,
) -> Self
pub fn with_table_structure_recognition( self, model_path: impl Into<PathBuf>, table_type: impl Into<String>, ) -> Self
Adds table structure recognition to the pipeline.
§Arguments
model_path- Path to the table structure recognition modeltable_type- Type of table structure: “wired” or “wireless”
This component recognizes the structure of tables and outputs HTML.
Sourcepub fn table_structure_dict_path(self, path: impl Into<PathBuf>) -> Self
pub fn table_structure_dict_path(self, path: impl Into<PathBuf>) -> Self
Sets the dictionary path for table structure recognition.
The dictionary file should match the model type:
table_structure_dict_ch.txtfor Chinesetable_structure_dict.txtfor Englishtable_master_structure_dict.txtfor extended tags
Sourcepub fn table_structure_recognition_config(
self,
config: TableStructureRecognitionConfig,
) -> Self
pub fn table_structure_recognition_config( self, config: TableStructureRecognitionConfig, ) -> Self
Sets the table structure recognition configuration.
Sourcepub fn with_wired_table_structure(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_wired_table_structure(self, model_path: impl Into<PathBuf>) -> Self
Adds wired table structure recognition model.
When both wired and wireless models are configured along with table classification, the system automatically selects the appropriate model based on classification results.
Sourcepub fn with_wireless_table_structure(
self,
model_path: impl Into<PathBuf>,
) -> Self
pub fn with_wireless_table_structure( self, model_path: impl Into<PathBuf>, ) -> Self
Adds wireless table structure recognition model.
When both wired and wireless models are configured along with table classification, the system automatically selects the appropriate model based on classification results.
Sourcepub fn with_wired_table_cell_detection(
self,
model_path: impl Into<PathBuf>,
) -> Self
pub fn with_wired_table_cell_detection( self, model_path: impl Into<PathBuf>, ) -> Self
Adds wired table cell detection model.
When both wired and wireless models are configured along with table classification, the system automatically selects the appropriate model based on classification results.
Sourcepub fn with_wireless_table_cell_detection(
self,
model_path: impl Into<PathBuf>,
) -> Self
pub fn with_wireless_table_cell_detection( self, model_path: impl Into<PathBuf>, ) -> Self
Adds wireless table cell detection model.
When both wired and wireless models are configured along with table classification, the system automatically selects the appropriate model based on classification results.
Sourcepub fn with_formula_recognition(
self,
model_path: impl Into<PathBuf>,
tokenizer_path: impl Into<PathBuf>,
model_type: impl Into<String>,
) -> Self
pub fn with_formula_recognition( self, model_path: impl Into<PathBuf>, tokenizer_path: impl Into<PathBuf>, model_type: impl Into<String>, ) -> Self
Adds formula recognition to the pipeline.
§Arguments
model_path- Path to the formula recognition modeltokenizer_path- Path to the tokenizer JSON filemodel_type- Type of formula model: “pp_formulanet” or “unimernet”
This component recognizes mathematical formulas and outputs LaTeX.
Sourcepub fn formula_recognition_config(
self,
config: FormulaRecognitionConfig,
) -> Self
pub fn formula_recognition_config( self, config: FormulaRecognitionConfig, ) -> Self
Sets the formula recognition configuration.
Sourcepub fn with_ocr(
self,
text_detection_model: impl Into<PathBuf>,
text_recognition_model: impl Into<PathBuf>,
character_dict_path: impl Into<PathBuf>,
) -> Self
pub fn with_ocr( self, text_detection_model: impl Into<PathBuf>, text_recognition_model: impl Into<PathBuf>, character_dict_path: impl Into<PathBuf>, ) -> Self
Integrates OCR into the pipeline for text extraction.
§Arguments
text_detection_model- Path to the text detection modeltext_recognition_model- Path to the text recognition modelcharacter_dict_path- Path to the character dictionary file
Sourcepub fn with_text_line_orientation(self, model_path: impl Into<PathBuf>) -> Self
pub fn with_text_line_orientation(self, model_path: impl Into<PathBuf>) -> Self
Adds text line orientation detection to the OCR pipeline.
This component detects whether text lines are upright (0°) or inverted (180°), which helps improve OCR accuracy for documents with mixed text orientations.
§PP-StructureV3 Integration
When enabled, detected text lines are classified before recognition:
- Lines classified as 180° rotated are flipped before OCR
- This improves accuracy for documents scanned upside-down or with mixed orientations
Sourcepub fn text_detection_config(self, config: TextDetectionConfig) -> Self
pub fn text_detection_config(self, config: TextDetectionConfig) -> Self
Sets the text detection configuration.
Sourcepub fn text_recognition_config(self, config: TextRecognitionConfig) -> Self
pub fn text_recognition_config(self, config: TextRecognitionConfig) -> Self
Sets the text recognition configuration.
Sourcepub fn build(self) -> Result<OARStructure, OCRError>
pub fn build(self) -> Result<OARStructure, OCRError>
Builds the structure analyzer runtime.
This method instantiates all adapters and returns a ready-to-use structure analyzer.
Trait Implementations§
Source§impl Clone for OARStructureBuilder
impl Clone for OARStructureBuilder
Source§fn clone(&self) -> OARStructureBuilder
fn clone(&self) -> OARStructureBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for OARStructureBuilder
impl RefUnwindSafe for OARStructureBuilder
impl Send for OARStructureBuilder
impl Sync for OARStructureBuilder
impl Unpin for OARStructureBuilder
impl UnsafeUnpin for OARStructureBuilder
impl UnwindSafe for OARStructureBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.