diff --git a/src/main.rs b/src/main.rs index 47dd4ee..c52d159 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use translators::english_to_latin::translate_english_to_latin; use translators::latin_to_english::translate_latin_to_english; use translators::{DisplayType, Language, Translation, TranslationType}; use use_data::{get_list, WordType}; +use utils::data::{get_english_dictionary, get_latin_dictionary}; use utils::sanitize_word; use crate::cli::ArgValue; @@ -307,8 +308,17 @@ fn english_to_latin( let english_words: Vec<&str> = english_text.split(" ").collect(); let mut translations: Vec = Vec::new(); + let latin_dictionary = get_latin_dictionary(); + let english_dictionary = get_english_dictionary(); + for word in english_words { - let definitions = translate_english_to_latin(&sanitize_word(word), max, sort); + let definitions = translate_english_to_latin( + &english_dictionary, + &latin_dictionary, + &sanitize_word(word), + max, + sort, + ); let mut translation = Translation::new(word.to_string(), TranslationType::English(definitions)); translation.post_process(Language::English, sort); diff --git a/src/translators/english_to_latin/mod.rs b/src/translators/english_to_latin/mod.rs index 6a5b803..57202b3 100644 --- a/src/translators/english_to_latin/mod.rs +++ b/src/translators/english_to_latin/mod.rs @@ -7,7 +7,6 @@ use crate::dictionary_structures::dictionary_keys::{ use crate::dictionary_structures::dictionary_values::{ EnglishWordInfo, Form, LatinWordInfo, LongForm, }; -use crate::utils::data::{get_english_dictionary, get_latin_dictionary}; use crate::utils::{convert_number_to_roman_numeral, is_all_numbers}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -25,6 +24,8 @@ impl EnglishTranslationInfo { } pub fn translate_english_to_latin( + english_dictionary: &Vec, + latin_dictionary: &Vec, english_word: &str, max: usize, sort: bool, @@ -69,13 +70,12 @@ pub fn translate_english_to_latin( } } - let english_words = get_english_dictionary(); - let latin_words = get_latin_dictionary(); + let latin_words_map: HashMap = latin_dictionary + .iter() + .map(|word| (word.id, word)) + .collect(); - let latin_words_map: HashMap = - latin_words.iter().map(|word| (word.id, word)).collect(); - - for word in english_words { + for word in english_dictionary { if word.orth.to_lowercase() == english_word.to_lowercase() { let mut translation = EnglishTranslationInfo::new(EnglishWordInfo::new(), LatinWordInfo::new()); @@ -84,7 +84,7 @@ pub fn translate_english_to_latin( translation.translation.set_word(latin_word); } - translation.word.set_word(word); + translation.word.set_word(word.clone()); output.push(translation); } } diff --git a/src/translators/latin_to_english/mod.rs b/src/translators/latin_to_english/mod.rs index c9afad5..0ca14ec 100644 --- a/src/translators/latin_to_english/mod.rs +++ b/src/translators/latin_to_english/mod.rs @@ -94,6 +94,7 @@ pub fn translate_latin_to_english(latin_word: &str, tricks: bool) -> Vec currebantur if tricks { let trick_results = try_tricks(&latin_word); diff --git a/src/utils/principle_part_generator/mod.rs b/src/utils/principle_part_generator/mod.rs index 26d869e..ca59ae7 100644 --- a/src/utils/principle_part_generator/mod.rs +++ b/src/utils/principle_part_generator/mod.rs @@ -81,8 +81,8 @@ pub fn set_principle_parts( return vec![parts[0].clone() + " | " + special_case.unwrap_or("")]; } - for ending in endings { - if parts[ending.1 as usize - 1] == "zzz" { + for (ending_number, ending) in endings.into_iter().enumerate() { + if parts[ending_number] == "zzz" { principle_parts.push("---".to_string()); continue; }