-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved latin list and added english list
- Loading branch information
Showing
8 changed files
with
228 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::dictionary_structures::dictionary_keys::PartOfSpeech; | ||
use crate::dictionary_structures::dictionary_values::EnglishWordInfo; | ||
use crate::use_data::utils::word_fits_filters; | ||
use crate::utils::data::get_english_dictionary; | ||
use rand::Rng; | ||
|
||
pub fn parse_english_dictionary( | ||
pos_list: Option<Vec<PartOfSpeech>>, | ||
max: Option<i32>, | ||
min: Option<i32>, | ||
exact: Option<i32>, | ||
amount: Option<i32>, | ||
random: bool, | ||
) -> Vec<EnglishWordInfo> { | ||
let english_dictionary = get_english_dictionary(); | ||
let mut english_word_info_list: Vec<EnglishWordInfo> = Vec::new(); | ||
|
||
if let Some(amount) = amount { | ||
if random { | ||
let mut rng = rand::thread_rng(); | ||
while english_word_info_list.len() as i32 != amount { | ||
let random_index = rng.gen_range(0..english_dictionary.len()); | ||
let word_at_index = english_dictionary[random_index].clone(); | ||
if !word_fits_filters( | ||
&word_at_index.orth, | ||
&word_at_index.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
english_word_info_list.push(word_at_index); | ||
} | ||
} else { | ||
for word in english_dictionary { | ||
if !word_fits_filters(&word.orth, &word.pos, &pos_list, &max, &min, &exact) { | ||
continue; | ||
} | ||
|
||
english_word_info_list.push(word); | ||
if english_word_info_list.len() as i32 == amount { | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
for word in english_dictionary { | ||
if !word_fits_filters(&word.orth, &word.pos, &pos_list, &max, &min, &exact) { | ||
continue; | ||
} | ||
|
||
english_word_info_list.push(word); | ||
} | ||
} | ||
|
||
english_word_info_list | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::dictionary_structures::dictionary_keys::PartOfSpeech; | ||
|
||
pub fn word_fits_filters( | ||
word_orth: &str, | ||
word_pos: &PartOfSpeech, | ||
pos_list: &Option<Vec<PartOfSpeech>>, | ||
max: &Option<i32>, | ||
min: &Option<i32>, | ||
exact: &Option<i32>, | ||
) -> bool { | ||
if let Some(pos_list) = pos_list { | ||
if !pos_list.contains(word_pos) { | ||
return false; | ||
} | ||
} | ||
|
||
if let Some(max) = max { | ||
if word_orth.len() > *max as usize { | ||
return false; | ||
} | ||
} | ||
|
||
if let Some(min) = min { | ||
if word_orth.len() < *min as usize { | ||
return false; | ||
} | ||
} | ||
|
||
if let Some(exact) = exact { | ||
if word_orth.len() != *exact as usize { | ||
return false; | ||
} | ||
} | ||
|
||
true | ||
} |