diff options
Diffstat (limited to 'autofeur_db/src/inference.rs')
| -rw-r--r-- | autofeur_db/src/inference.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/autofeur_db/src/inference.rs b/autofeur_db/src/inference.rs index b8f2f87..49192f3 100644 --- a/autofeur_db/src/inference.rs +++ b/autofeur_db/src/inference.rs @@ -1,9 +1,8 @@ -use std::{collections::VecDeque, env, ops::Add}; +use std::{env, ops::Add}; use anyhow::anyhow; +use hypher::hyphenate; use itertools::Itertools; -use levenshtein::levenshtein; -use unicode_segmentation::UnicodeSegmentation; use crate::save::Save; @@ -38,26 +37,27 @@ impl Save<'_> { println!("Matching {} by adding {}", word, completion); - // we finally just need to compute the end of the word which matches the sound - let mut found = None; + let mut completed_syllabes: Vec<&str> = hyphenate(word, hypher::Lang::French).into_iter().collect_vec(); + let source_word_syllabes: Vec<&str> = hyphenate(prefix, hypher::Lang::French).into_iter().collect_vec(); - let mut characters: VecDeque<&str> = word.graphemes(true).collect(); - while let Some(_) = characters.pop_front() { - let sub: String = characters.iter().join(""); - let inference = call_inference_service(&sub).await?; + // input: test + // output found: testames + // out syl: tes - tames + // output expect: tames + // we just need to remove the prefix - if levenshtein(&inference, &completion) < 5 { - found = Some(sub); - break; + + let mut i = 0; + for (index, syl) in source_word_syllabes.iter().enumerate() { + if *source_word_syllabes[index] == **syl { + i = index } else { - if found.is_none() { - found = Some(sub); - } - println!("did not match a={}, b={}", inference, completion) + break; } } - let found = found.ok_or_else(|| anyhow!("no prefix could be matched"))?; + completed_syllabes.drain(0..i); // we finally just need to compute the end of the word which matches the sound + let found = completed_syllabes.join(""); println!("{} is equivalent to {}", completion, found); Ok(format!("{} ({})", found, word)) |
