Skip to content

Commit

Permalink
aff: Add helper to check if dictionary supports compounding
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Sep 15, 2024
1 parent 2d490f6 commit fd2d75b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/aff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,15 @@ impl Default for AffOptions {
}
}

impl AffOptions {
pub fn allows_compounding(&self) -> bool {
self.compound_flag.is_some()
|| self.compound_begin_flag.is_some()
|| self.compound_middle_flag.is_some()
|| self.compound_end_flag.is_some()
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
6 changes: 1 addition & 5 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,7 @@ impl<'a, S: BuildHasher> Checker<'a, S> {
word: &str,
allow_bad_forceucase: Forceucase,
) -> Option<CompoundingResult<'_>> {
if self.aff.options.compound_flag.is_some()
|| self.aff.options.compound_begin_flag.is_some()
|| self.aff.options.compound_middle_flag.is_some()
|| self.aff.options.compound_end_flag.is_some()
{
if self.aff.options.allows_compounding() {
// Note that Nuspell passes along basically a `&mut String`. We can avoid that by
// subslicing the word `&str`. Also see `check_compound_with_rules`.
if let Some(result) = self.check_compound_impl::<MODE>(word, 0, 0, allow_bad_forceucase)
Expand Down
7 changes: 1 addition & 6 deletions src/suggester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,7 @@ impl<'a, S: BuildHasher> Suggester<'a, S> {
}
cost = cost.clamp(250_000, 25_000_000_000);
let mut attempts = 25_000_000_000 / cost;
let options = &self.checker.aff.options;
if options.compound_flag.is_some()
|| options.compound_begin_flag.is_some()
|| options.compound_middle_flag.is_some()
|| options.compound_end_flag.is_some()
{
if self.checker.aff.options.allows_compounding() {
attempts /= word.len() as u64;
}
attempts
Expand Down

0 comments on commit fd2d75b

Please sign in to comment.