pub struct MatchingLoss {
pub fuzzy: f64,
pub jump_distance: f64,
pub geo_distance: f64,
}Fields§
§fuzzy: f64§jump_distance: f64§geo_distance: f64Implementations§
Source§impl MatchingLoss
impl MatchingLoss
Sourcepub fn abs(&self) -> f64
pub fn abs(&self) -> f64
Examples found in repository?
examples/run_ab.rs (line 26)
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}Trait Implementations§
Source§impl Clone for MatchingLoss
impl Clone for MatchingLoss
Source§fn clone(&self) -> MatchingLoss
fn clone(&self) -> MatchingLoss
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MatchingLoss
impl RefUnwindSafe for MatchingLoss
impl Send for MatchingLoss
impl Sync for MatchingLoss
impl Unpin for MatchingLoss
impl UnsafeUnpin for MatchingLoss
impl UnwindSafe for MatchingLoss
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
Mutably borrows from an owned value. Read more
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>
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 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>
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