From e17b1e8dfc8a48bb6b7d203075fe8e854aaadcb1 Mon Sep 17 00:00:00 2001 From: cqb13 Date: Thu, 7 Mar 2024 12:55:40 -0500 Subject: [PATCH] fixed principle part adding error if part to add to does not exist --- src/use_data/parsers/latin_dictionary_parser.rs | 8 ++++---- src/utils/principle_part_generator/mod.rs | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/use_data/parsers/latin_dictionary_parser.rs b/src/use_data/parsers/latin_dictionary_parser.rs index e497d2a..360bd32 100644 --- a/src/use_data/parsers/latin_dictionary_parser.rs +++ b/src/use_data/parsers/latin_dictionary_parser.rs @@ -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, pos_list: Option>, @@ -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, @@ -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; @@ -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); } } diff --git a/src/utils/principle_part_generator/mod.rs b/src/utils/principle_part_generator/mod.rs index 6976673..dfcd4c9 100644 --- a/src/utils/principle_part_generator/mod.rs +++ b/src/utils/principle_part_generator/mod.rs @@ -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());