1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! OCR (Optical Character Recognition) subsystem.
//!
//! This module provides OCR functionality using Tesseract as the backend.
//! It includes caching, table reconstruction, hOCR parsing, and batch processing.
//!
//! # Features
//!
//! - **Tesseract integration**: Native Tesseract backend via `xberg-tesseract`
//! - **Result caching**: Persistent cache for OCR results using file hashing
//! - **Table reconstruction**: Extract and reconstruct tables from hOCR/TSV output
//! - **hOCR to Markdown**: Convert hOCR format to clean Markdown
//! - **Batch processing**: Process multiple images efficiently
//! - **Language support**: Validate and configure Tesseract languages
//! - **PSM modes**: Support for all Tesseract Page Segmentation Modes
//!
//! # Example
//!
//! Configure OCR through the extraction pipeline:
//!
//! ```no_run
//! use xberg::{extract, ExtractInput, ExtractionConfig, OcrConfig};
//!
//! # async fn run(image_bytes: Vec<u8>) -> xberg::Result<()> {
//! let config = ExtractionConfig {
//! ocr: Some(OcrConfig::default()),
//! ..Default::default()
//! };
//! let input = ExtractInput::from_bytes(image_bytes, "image/png", Some("scan.png".into()));
//! let output = extract(input, &config).await?;
//! let document = output
//! .results
//! .first()
//! .ok_or_else(|| xberg::XbergError::Other("OCR produced no document".into()))?;
//! assert!(!document.content.is_empty());
//! # Ok(())
//! # }
//! ```
//!
//! # Optional Feature
//!
//! This module requires the `ocr` feature to be enabled:
//! ```toml
//! [dependencies]
//! xberg = { version = "1.1", features = ["ocr"] }
//! ```
/// Persistent file-backed cache for OCR results keyed by image hash and config.
/// Type conversions between internal OCR types and public API types.
/// OCR error types.
/// hOCR HTML output parser that extracts word bounding boxes and confidence scores.
/// Assembles layout-detection bounding boxes with OCR word spans for region-level extraction.
pub
/// High-level Tesseract OCR processor with caching and table reconstruction.
/// TSV and hOCR table reconstruction utilities.
/// Runtime tessdata language pack download utilities.
/// Tessdata language-pack download and management utilities.
/// Native Tesseract backend using `xberg-tesseract` (C FFI).
/// WebAssembly Tesseract backend using `tesseract-wasm`.
/// OCR configuration and result types shared across all backends.
/// Utility functions for OCR result hashing and formatting constants.
/// Validation helpers for language codes and Tesseract version constraints.
pub use ;
pub use OcrError;
pub use OcrProcessor;
pub use TessdataManager;
pub use TesseractBackend;
pub use TesseractWasmBackend;
pub use ;
pub use compute_hash;