pub use pdf_ocr::runtime::{
default_model_root, model_error, resolve_model_file, resolve_model_root, resolve_ort_dylib,
ModelError, ModelErrorKind, ModelSpec, RuntimeConfig, ORT_VERSION,
};
#[cfg(not(feature = "ort-layout"))]
use crate::EngineError;
use crate::Result;
pub const LAYOUT_EP03: ModelSpec = ModelSpec::new(
"layout-heron-ep03",
"heron_ep03.onnx",
"b7cc5d31f3223c74cc477a1386b894793618aeb398ca59cf5eb7264ec61d8afa",
"pdfluent models install layout",
);
pub const TABLES_TATR: ModelSpec = ModelSpec::new(
"tatr-v1.1-all",
"tatr-v1.1-all.onnx",
"8c28418690b896a845a53633736a62c22ef8c9a515a23c06e9976e61360f1fcf",
"pdfluent models install tables",
);
#[cfg(not(feature = "ort-layout"))]
pub(crate) fn balanced_unavailable() -> EngineError {
EngineError::Io(std::io::Error::from(ModelError::feature_not_compiled(
&LAYOUT_EP03,
"ort-layout",
)))
}
pub(crate) fn balanced_markdown_for(
doc: &crate::PdfDocument,
options: &crate::ExtractOptions,
) -> Result<String> {
#[cfg(feature = "ort-layout")]
{
let mut config = RuntimeConfig::new();
if let Some(dir) = &options.model_dir {
config = config.with_model_dir(dir.clone());
}
let mut balanced =
crate::balanced::BalancedOptions::default().keep_furniture(options.keep_furniture);
if let Some(tatr) = options.tatr() {
balanced = balanced.with_tatr(tatr.clone());
}
crate::balanced::balanced_markdown(doc, &config, &balanced)
}
#[cfg(not(feature = "ort-layout"))]
{
let _ = (doc, options);
Err(balanced_unavailable())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_layout_spec_names_the_ep03_package() {
assert_eq!(LAYOUT_EP03.name, "layout-heron-ep03");
assert_eq!(LAYOUT_EP03.file, "heron_ep03.onnx");
assert_eq!(
LAYOUT_EP03.sha256,
"b7cc5d31f3223c74cc477a1386b894793618aeb398ca59cf5eb7264ec61d8afa"
);
assert_eq!(
LAYOUT_EP03.install_command,
"pdfluent models install layout"
);
assert_eq!(ORT_VERSION, "1.23.2");
}
#[test]
fn the_tables_spec_names_the_tatr_package() {
assert_eq!(TABLES_TATR.name, "tatr-v1.1-all");
assert_eq!(TABLES_TATR.file, "tatr-v1.1-all.onnx");
assert_eq!(
TABLES_TATR.sha256,
"8c28418690b896a845a53633736a62c22ef8c9a515a23c06e9976e61360f1fcf"
);
assert_eq!(
TABLES_TATR.install_command,
"pdfluent models install tables"
);
}
#[cfg(not(feature = "ort-layout"))]
#[test]
fn balanced_unavailable_names_the_feature_and_the_install() {
let error = balanced_unavailable();
let EngineError::Io(io) = &error else {
panic!("a model failure rides as Io");
};
let model = model_error(io).expect("the chain carries the ModelError");
assert_eq!(model.kind, ModelErrorKind::ModelNotAvailable);
assert_eq!(model.kind.code(), "MODEL_NOT_AVAILABLE");
let message = error.to_string();
assert!(
message.contains("`ort-layout`"),
"the message names the cargo feature: {message}"
);
assert!(
message.contains("pdfluent models install layout"),
"the message names the install command: {message}"
);
}
}