-
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.
- Loading branch information
Showing
5 changed files
with
225 additions
and
10 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
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::Attachment; | ||
use crate::use_data::utils::word_fits_filters; | ||
use rand::Rng; | ||
|
||
pub fn parse_attachments( | ||
attachments: Vec<Attachment>, | ||
pos_list: Option<Vec<PartOfSpeech>>, | ||
max: Option<i32>, | ||
min: Option<i32>, | ||
exact: Option<i32>, | ||
amount: Option<i32>, | ||
random: bool, | ||
) -> Vec<Attachment> { | ||
let mut attachment_list: Vec<Attachment> = Vec::new(); | ||
|
||
if let Some(amount) = amount { | ||
if random { | ||
let mut rng = rand::thread_rng(); | ||
while attachment_list.len() as i32 != amount { | ||
let random_index = rng.gen_range(0..attachments.len()); | ||
let attachment_at_index = attachments[random_index].clone(); | ||
if !word_fits_filters( | ||
&attachment_at_index.orth, | ||
&attachment_at_index.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
attachment_list.push(attachment_at_index); | ||
} | ||
} else { | ||
for attachment in attachments { | ||
if !word_fits_filters( | ||
&attachment.orth, | ||
&attachment.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
|
||
attachment_list.push(attachment); | ||
if attachment_list.len() as i32 == amount { | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
for attachment in attachments { | ||
if !word_fits_filters( | ||
&attachment.orth, | ||
&attachment.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
|
||
attachment_list.push(attachment); | ||
} | ||
} | ||
|
||
attachment_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,73 @@ | ||
use crate::dictionary_structures::dictionary_keys::PartOfSpeech; | ||
use crate::dictionary_structures::dictionary_values::Inflection; | ||
use crate::use_data::utils::word_fits_filters; | ||
use crate::utils::data::get_latin_inflections; | ||
use rand::Rng; | ||
|
||
pub fn parse_latin_inflections( | ||
pos_list: Option<Vec<PartOfSpeech>>, | ||
max: Option<i32>, | ||
min: Option<i32>, | ||
exact: Option<i32>, | ||
amount: Option<i32>, | ||
random: bool, | ||
) -> Vec<Inflection> { | ||
let latin_inflections = get_latin_inflections(); | ||
let mut inflection_list: Vec<Inflection> = Vec::new(); | ||
|
||
if let Some(amount) = amount { | ||
if random { | ||
let mut rng = rand::thread_rng(); | ||
while inflection_list.len() as i32 != amount { | ||
let random_index = rng.gen_range(0..latin_inflections.len()); | ||
let inflection_at_index = latin_inflections[random_index].clone(); | ||
if !word_fits_filters( | ||
&inflection_at_index.ending, | ||
&inflection_at_index.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
inflection_list.push(inflection_at_index); | ||
} | ||
} else { | ||
for inflection in latin_inflections { | ||
if !word_fits_filters( | ||
&inflection.ending, | ||
&inflection.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
|
||
inflection_list.push(inflection); | ||
if inflection_list.len() as i32 == amount { | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
for inflection in latin_inflections { | ||
if !word_fits_filters( | ||
&inflection.ending, | ||
&inflection.pos, | ||
&pos_list, | ||
&max, | ||
&min, | ||
&exact, | ||
) { | ||
continue; | ||
} | ||
|
||
inflection_list.push(inflection); | ||
} | ||
} | ||
|
||
inflection_list | ||
} |