pub fn optimize<'a>(
ground: &str,
blocks: &[&'a str],
) -> (MatchingLoss, Vec<(usize, &'a str)>)Expand description
Examples found in repository?
examples/run_ab.rs (line 17)
5fn main() {
6 // Load the ground truth text (a.txt) and the OCR blocks (b.txt)
7 let ground = fs::read_to_string("a.txt").expect("Failed to read a.txt");
8 let blocks_raw = fs::read_to_string("b.txt").expect("Failed to read b.txt");
9
10 // Each line in b.txt is one block
11 let blocks: Vec<&str> = blocks_raw.lines().collect();
12
13 println!("Ground truth length: {} chars", ground.len());
14 println!("Number of blocks: {}", blocks.len());
15 println!();
16
17 let (loss, optimized) = optimize(&ground, &blocks);
18
19 println!();
20 println!("=== Result ===");
21 println!(
22 "Loss: fuzzy={:.2}, jump={:.2}, geo={:.2}, total={:.2}",
23 loss.fuzzy,
24 loss.jump_distance,
25 loss.geo_distance,
26 loss.abs()
27 );
28 println!();
29
30 // Print the optimized text
31 let result_text: String = optimized
32 .iter()
33 .map(|(_, text)| *text)
34 .collect::<Vec<&str>>()
35 .join(" ");
36
37 println!("Optimized text (first 500 chars):");
38 println!("{}", &result_text[..result_text.len().min(500)]);
39}