-
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.
added modifier and stem parsing to get list
- Loading branch information
Showing
3 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
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,72 @@ | ||
use crate::dictionary_structures::dictionary_keys::PartOfSpeech; | ||
use crate::dictionary_structures::dictionary_values::Modifier; | ||
use crate::use_data::utils::word_fits_filters; | ||
use rand::Rng; | ||
|
||
pub fn parse_modifiers( | ||
modifiers: Vec<Modifier>, | ||
pos_list: Option<Vec<PartOfSpeech>>, | ||
max: Option<i32>, | ||
min: Option<i32>, | ||
exact: Option<i32>, | ||
amount: Option<i32>, | ||
random: bool, | ||
) -> Vec<Modifier> { | ||
let mut modifier_list: Vec<Modifier> = Vec::new(); | ||
|
||
if let Some(amount) = amount { | ||
if random { | ||
let mut rng = rand::thread_rng(); | ||
while modifier_list.len() as i32 != amount { | ||
let random_index = rng.gen_range(0..modifiers.len()); | ||
let modifier_at_index = modifiers[random_index].clone(); | ||
if !word_fits_filters( | ||
&modifier_at_index.orth, | ||
&modifier_at_index.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
modifier_list.push(modifier_at_index); | ||
} | ||
} else { | ||
for modifier in modifiers { | ||
if !word_fits_filters( | ||
&modifier.orth, | ||
&modifier.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
|
||
modifier_list.push(modifier); | ||
if modifier_list.len() as i32 == amount { | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
for modifier in modifiers { | ||
if !word_fits_filters( | ||
&modifier.orth, | ||
&modifier.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
|
||
modifier_list.push(modifier); | ||
} | ||
} | ||
|
||
modifier_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
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::Stem; | ||
use crate::use_data::utils::word_fits_filters; | ||
use crate::utils::data::get_latin_stems; | ||
use rand::Rng; | ||
|
||
pub fn parse_latin_stems( | ||
pos_list: Option<Vec<PartOfSpeech>>, | ||
max: Option<i32>, | ||
min: Option<i32>, | ||
exact: Option<i32>, | ||
amount: Option<i32>, | ||
random: bool, | ||
) -> Vec<Stem> { | ||
let latin_stems = get_latin_stems(); | ||
let mut stem_list: Vec<Stem> = Vec::new(); | ||
|
||
if let Some(amount) = amount { | ||
if random { | ||
let mut rng = rand::thread_rng(); | ||
while stem_list.len() as i32 != amount { | ||
let random_index = rng.gen_range(0..latin_stems.len()); | ||
let stem_at_index = latin_stems[random_index].clone(); | ||
if !word_fits_filters( | ||
&stem_at_index.orth, | ||
&stem_at_index.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
stem_list.push(stem_at_index); | ||
} | ||
} else { | ||
for stem in latin_stems { | ||
if !word_fits_filters(&stem.orth, &stem.pos, &pos_list, &max, &min, &exact) { | ||
continue; | ||
} | ||
|
||
stem_list.push(stem); | ||
if stem_list.len() as i32 == amount { | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
for stem in latin_stems { | ||
if !word_fits_filters(&stem.orth, &stem.pos, &pos_list, &max, &min, &exact) { | ||
continue; | ||
} | ||
|
||
stem_list.push(stem); | ||
} | ||
} | ||
|
||
stem_list | ||
} |