Skip to content

Commit

Permalink
added a new trick
Browse files Browse the repository at this point in the history
  • Loading branch information
cqb13 committed May 6, 2024
1 parent 269d70a commit 960d967
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/translators/latin_to_english/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<LatinTranslationInfo>> {
match parse_unique_latin_words(latin_word) {
Expand Down Expand Up @@ -51,6 +52,8 @@ pub fn find_form(latin_word: &str, reduced: bool) -> Option<Vec<LatinTranslation
output = reduce(latin_word);
}

// do tricks on stems

output
}

Expand Down
15 changes: 14 additions & 1 deletion src/translators/latin_to_english/tricks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pub mod word_mods;
use crate::translators::latin_to_english::tricks::trick_lists::{
get_any_tricks, match_slur_trick_list, match_tricks_list, Trick,
};
use crate::translators::latin_to_english::tricks::word_mods::{flip, flip_flop, internal};
use crate::translators::latin_to_english::tricks::word_mods::{
double_consonants, flip, flip_flop, internal,
};

pub enum Operation {
FlipFlop,
Expand Down Expand Up @@ -96,6 +98,17 @@ pub fn try_syncopes(word: &str) -> 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<Trick>, word: &str) -> (String, Vec<String>) {
// word should be modified after each operation is applied.
let mut explanations = Vec::new();
Expand Down
37 changes: 37 additions & 0 deletions src/translators/latin_to_english/tricks/word_mods.rs
Original file line number Diff line number Diff line change
@@ -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("");
Expand Down Expand Up @@ -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<char> = 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)
}

0 comments on commit 960d967

Please # to comment.