Compare commits
1
Commits
No files matched your search
@@ -308,6 +308,8 @@ pub fn reconstruct_to(vector: &Vec<EditOperation>) -> String {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::wrapper_::CostOperationDP;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -498,4 +500,13 @@ mod tests {
|
|||||||
assert_eq!(aligned_str1, "test");
|
assert_eq!(aligned_str1, "test");
|
||||||
assert_eq!(aligned_str2, "test");
|
assert_eq!(aligned_str2, "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_2() {
|
||||||
|
let str1 = "sentence";
|
||||||
|
let str2 = "interesting";
|
||||||
|
let (c, dp) = levenshtein_with_operations(str1, str2, &EditCost::default());
|
||||||
|
|
||||||
|
println!("{c}\n{}", CostOperationDP(&dp))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+42
-5
@@ -1,5 +1,6 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use crate::levenshtein;
|
||||||
use crate::levenshtein::EditOperation;
|
use crate::levenshtein::EditOperation;
|
||||||
|
|
||||||
pub struct EditOperationVec<'e>(pub &'e Vec<EditOperation>);
|
pub struct EditOperationVec<'e>(pub &'e Vec<EditOperation>);
|
||||||
@@ -89,6 +90,11 @@ impl Display for InsanelySpecific<'_> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use lda_ansi::ansi_backbone::Style as StyleConstruct;
|
||||||
|
use lda_ansi::ansi_colors_2::ansi_color_interface::ColorContext;
|
||||||
|
use lda_ansi::ansi_colors_2::Color;
|
||||||
|
use lda_ansi::ansi_colors_2::CustomColor;
|
||||||
|
use lda_ansi::ansi_styles::Style;
|
||||||
|
|
||||||
impl Display for ColoredInsanelySpecific<'_> {
|
impl Display for ColoredInsanelySpecific<'_> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
@@ -99,11 +105,7 @@ impl Display for ColoredInsanelySpecific<'_> {
|
|||||||
write!(f, " {i}")?;
|
write!(f, " {i}")?;
|
||||||
}
|
}
|
||||||
writeln!(f)?;
|
writeln!(f)?;
|
||||||
use lda_ansi::ansi_backbone::Style as StyleConstruct;
|
|
||||||
use lda_ansi::ansi_colors_2::ansi_color_interface::ColorContext;
|
|
||||||
use lda_ansi::ansi_colors_2::Color;
|
|
||||||
use lda_ansi::ansi_colors_2::CustomColor;
|
|
||||||
use lda_ansi::ansi_styles::Style;
|
|
||||||
// use lda_ansi::AnsiStyles;
|
// use lda_ansi::AnsiStyles;
|
||||||
|
|
||||||
let hl = StyleConstruct::new().color(Color::Green.fg()).to_owned();
|
let hl = StyleConstruct::new().color(Color::Green.fg()).to_owned();
|
||||||
@@ -139,3 +141,38 @@ impl Display for ColoredInsanelySpecific<'_> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CostOperationDP<'e>(pub &'e Vec<Vec<CostOperation>>);
|
||||||
|
|
||||||
|
impl Display for CostOperationDP<'_> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let _w2 = levenshtein::edit_sequence(self.0); // no clue no idea
|
||||||
|
let l = i32::max(
|
||||||
|
self.0[0].last().unwrap().cost,
|
||||||
|
self.0.last().unwrap()[0].cost,
|
||||||
|
)
|
||||||
|
.checked_ilog10()
|
||||||
|
.map_or(1, |d| d + 1) as usize;
|
||||||
|
let reset = StyleConstruct::new().style(Style::Reset).to_owned();
|
||||||
|
let rem = StyleConstruct::new().color(Color::Red.bg()).to_owned();
|
||||||
|
let add = StyleConstruct::new().color(Color::Green.bg()).to_owned();
|
||||||
|
let ch = StyleConstruct::new().color(Color::Yellow.bg()).to_owned();
|
||||||
|
let ma = StyleConstruct::new()
|
||||||
|
.color(CustomColor::Color256(248).bg())
|
||||||
|
.to_owned();
|
||||||
|
for i in self.0 {
|
||||||
|
for j in i {
|
||||||
|
let st = match j.operation {
|
||||||
|
Some(EditOperation::Delete { .. }) => &rem,
|
||||||
|
Some(EditOperation::Insert { .. }) => &add,
|
||||||
|
Some(EditOperation::Substitute { .. }) => &ch,
|
||||||
|
Some(EditOperation::Match { .. }) => &ma,
|
||||||
|
None => &reset,
|
||||||
|
};
|
||||||
|
write!(f, "{st}{:>1$}{reset} ", j.cost, l)?;
|
||||||
|
}
|
||||||
|
writeln!(f)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user