Skip to content

Commit

Permalink
fixed principle part adding error if part to add to does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cqb13 committed Mar 7, 2024
1 parent 675711b commit e17b1e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/use_data/parsers/latin_dictionary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::dictionary_structures::dictionary_values::LatinWordInfo;
use crate::use_data::utils::word_fits_filters;
use rand::Rng;

// need to generate principal parts before checking if the word fits the filter, to account for length filters
pub fn parse_latin_dictionary(
dictionary: Vec<LatinWordInfo>,
pos_list: Option<Vec<PartOfSpeech>>,
Expand All @@ -20,6 +21,7 @@ pub fn parse_latin_dictionary(
while latin_word_info_list.len() as i32 != amount {
let random_index = rng.gen_range(0..dictionary.len());
let mut word_at_index = dictionary[random_index].clone();
word_at_index.generate_principle_parts();
if !word_fits_filters(
&word_at_index.orth,
&word_at_index.pos,
Expand All @@ -30,15 +32,14 @@ pub fn parse_latin_dictionary(
) {
continue;
}
word_at_index.generate_principle_parts();
latin_word_info_list.push(word_at_index);
}
} else {
for mut word in dictionary {
word.generate_principle_parts();
if !word_fits_filters(&word.orth, &word.pos, &pos_list, &max, &min, &exact) {
continue;
}
word.generate_principle_parts();
latin_word_info_list.push(word);
if latin_word_info_list.len() as i32 == amount {
break;
Expand All @@ -47,12 +48,11 @@ pub fn parse_latin_dictionary(
}
} else {
for mut word in dictionary {
word.generate_principle_parts();
if !word_fits_filters(&word.orth, &word.pos, &pos_list, &max, &min, &exact) {
continue;
}

word.generate_principle_parts();

latin_word_info_list.push(word);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils/principle_part_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ pub fn set_principle_parts(
continue;
}

let mut part = parts[part_to_add_ending_to as usize - 1].to_string();
let mut part = if part_to_add_ending_to as usize - 1 >= parts.len() {
"---".to_string()
} else {
parts[part_to_add_ending_to as usize - 1].to_string()
};

if part == "zzz" {
principle_parts.push("---".to_string());
Expand Down

0 comments on commit e17b1e8

Please # to comment.