diff options
| author | Matthieu Pignolet <matthieu@puffer.fish> | 2025-05-18 22:49:46 +0400 |
|---|---|---|
| committer | Matthieu Pignolet <matthieu@puffer.fish> | 2025-05-18 22:49:46 +0400 |
| commit | b60f1b531635a0abec09c909580ac5144cc609b3 (patch) | |
| tree | 345942b788909d44277537be9562bae982d50412 | |
| parent | acb624a1d1b91558183209f82b5d184af9932b20 (diff) | |
fix: bug in the vowel function where the results were inversed
| -rw-r--r-- | aline/src/lib.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/aline/src/lib.rs b/aline/src/lib.rs index caf5810..fde55b1 100644 --- a/aline/src/lib.rs +++ b/aline/src/lib.rs @@ -28,7 +28,7 @@ pub fn align(str1: &str, str2: &str, epsilon: f64) -> Vec<Vec<(String, String)>> let edit1 = s[i - 1][j] + sigma_skip(); let edit2 = s[i][j - 1] + sigma_skip(); - let edit3 = s[i - 1][j - 1] + sigma_sub(str1_chars[i - 1], str2_chars[j - 1]); + let edit3 = s[i - 1][j - 1] + sigma_sub(str1_chars[i - 1], str2_chars[j - 1]); let edit4 = if i > 1 { s[i - 2][j - 1] + sigma_exp(str2_chars[j - 1], str1_chars[i - 2], str1_chars[i - 1]) @@ -47,12 +47,12 @@ pub fn align(str1: &str, str2: &str, epsilon: f64) -> Vec<Vec<(String, String)>> .fold(0f64, |prev, curr| f64::max(prev, *curr)); } } - let amax = s - .iter() - .flat_map(|row| row.iter()) - .cloned() - .fold(f64::NAN, f64::max); - let t = (1.0 - epsilon) * amax; + + let t = (1.0 - epsilon) + * s.iter() + .flat_map(|row| row.iter()) + .cloned() + .fold(f64::NAN, f64::max); let mut aligns = Vec::new(); for i in 1..=m { @@ -218,10 +218,9 @@ fn r<'a>(p: &str, q: &str) -> &'static HashSet<String> { /// (Kondrak 2002: 54) #[inline] fn v(p: &str) -> f64 { - EXTRACTED - .consonants - .get(&p.to_string()) - .map(|_| EXTRACTED.cvwl) - .or(Some(0f64)) - .unwrap_or_else(|| unreachable!()) + if !EXTRACTED.consonants.contains(&p.to_string()) { + EXTRACTED.cvwl + } else { + 0.0 + } } |
