diff --git a/src/translators/latin_to_english/parser.rs b/src/translators/latin_to_english/parser.rs index 8d05849..6322580 100644 --- a/src/translators/latin_to_english/parser.rs +++ b/src/translators/latin_to_english/parser.rs @@ -4,6 +4,7 @@ use crate::translators::latin_to_english::translator::lookup_stems; use crate::translators::latin_to_english::utils::reduce; use crate::translators::latin_to_english::LatinTranslationInfo; use crate::utils::data::{get_latin_inflections, get_latin_stems, get_unique_latin_words}; +use crate::translators::latin_to_english::tricks::try_medieval_tricks; pub fn parse(latin_word: &str, reduced: bool) -> Option> { match parse_unique_latin_words(latin_word) { @@ -51,6 +52,8 @@ pub fn find_form(latin_word: &str, reduced: bool) -> Option TrickResult { TrickResult::NotFound } +pub fn try_medieval_tricks(word: &str) -> TrickResult { + let new_word = word.to_string(); + + let (updated_word, updated_explanation) = double_consonants(&new_word); + if updated_word != new_word { + return TrickResult::Found(updated_word, vec![updated_explanation]); + } + + TrickResult::NotFound +} + fn iterate_over_tricks(trick_list: &Vec, word: &str) -> (String, Vec) { // word should be modified after each operation is applied. let mut explanations = Vec::new(); diff --git a/src/translators/latin_to_english/tricks/word_mods.rs b/src/translators/latin_to_english/tricks/word_mods.rs index 1f0b00d..bc6ebd0 100644 --- a/src/translators/latin_to_english/tricks/word_mods.rs +++ b/src/translators/latin_to_english/tricks/word_mods.rs @@ -1,3 +1,5 @@ +use crate::utils::is_vowel; + pub fn flip(str_to_replace: &str, replacement_str: &str, word: &str) -> (String, String) { let mut new_word = String::from(word); let mut explanation = String::from(""); @@ -69,3 +71,38 @@ pub fn internal(str_to_replace: &str, replacement_str: &str, word: &str) -> (Str (word.to_string(), explanation) } + +pub fn double_consonants(latin_word: &str) -> (String, String) { + let mut doubled_word = String::new(); + let mut explanation = String::new(); + + let split_word: Vec = latin_word.chars().collect(); + + for (i, letter) in split_word.iter().enumerate() { + if is_vowel(letter.to_owned()) { + doubled_word.push(*letter); + continue; + } + + if i == 0 || i == split_word.len() - 1 { + doubled_word.push(*letter); + continue; + } + + // make sure in bounds for both checks + if is_vowel(split_word[i - 1]) && is_vowel(split_word[i + 1]) { + doubled_word.push(*letter); + doubled_word.push(*letter); + } else { + doubled_word.push(*letter); + } + } + + println!("{}", doubled_word); + + if doubled_word.len() > latin_word.len() { + explanation = format!("Consonants may be doubled in '{}'", latin_word); + } + + (doubled_word, explanation) +}