Skip to main content

OARStructureBuilder

Struct OARStructureBuilder 

Source
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

Source

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
Source

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.

Source

pub fn layout_detection_config(self, config: LayoutDetectionConfig) -> Self

Sets the layout detection model configuration.

Source

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-l
  • pp-docblocklayout
  • picodet_layout_1x, picodet_layout_1x_table
  • rt-detr-h_layout_3cls, rt-detr-h_layout_17cls
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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:

  1. Group layout elements by their parent regions
  2. Apply XY-cut ordering within each region
  3. Order regions based on their relative positions
Source

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.

Source

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.

Source

pub fn table_classification_config( self, config: TableClassificationConfig, ) -> Self

Sets the table classification configuration.

Source

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)
Source

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)

Source

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)

Source

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.

Source

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.

Source

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 model
  • cell_type - Type of cells to detect: “wired” or “wireless”
Source

pub fn table_cell_detection_config( self, config: TableCellDetectionConfig, ) -> Self

Sets the table cell detection configuration.

Source

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 model
  • table_type - Type of table structure: “wired” or “wireless”

This component recognizes the structure of tables and outputs HTML.

Source

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.txt for Chinese
  • table_structure_dict.txt for English
  • table_master_structure_dict.txt for extended tags
Source

pub fn table_structure_recognition_config( self, config: TableStructureRecognitionConfig, ) -> Self

Sets the table structure recognition configuration.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 model
  • tokenizer_path - Path to the tokenizer JSON file
  • model_type - Type of formula model: “pp_formulanet” or “unimernet”

This component recognizes mathematical formulas and outputs LaTeX.

Source

pub fn formula_recognition_config( self, config: FormulaRecognitionConfig, ) -> Self

Sets the formula recognition configuration.

Source

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 model
  • text_recognition_model - Path to the text recognition model
  • character_dict_path - Path to the character dictionary file
Source

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
Source

pub fn text_detection_config(self, config: TextDetectionConfig) -> Self

Sets the text detection configuration.

Source

pub fn text_recognition_config(self, config: TextRecognitionConfig) -> Self

Sets the text recognition configuration.

Source

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

Source§

fn clone(&self) -> OARStructureBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OARStructureBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more