Skip to content

Commit

Permalink
Fixes rust fmt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
luflow committed Aug 28, 2024
1 parent 257972f commit f6999c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion charabia/src/segmenter/german.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub struct GermanSegmenter;
static WORDS_FST: Lazy<Fst<&[u8]>> =
Lazy::new(|| Fst::new(&include_bytes!("../../dictionaries/fst/german/words.fst")[..]).unwrap());

static FST_SEGMENTER: Lazy<FstSegmenter> = Lazy::new(|| FstSegmenter::new(&WORDS_FST, Some(4), true));
static FST_SEGMENTER: Lazy<FstSegmenter> =
Lazy::new(|| FstSegmenter::new(&WORDS_FST, Some(4), true));

impl Segmenter for GermanSegmenter {
fn segment_str<'o>(&self, to_segment: &'o str) -> Box<dyn Iterator<Item = &'o str> + 'o> {
Expand Down
15 changes: 10 additions & 5 deletions charabia/src/segmenter/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ use fst::raw::{Fst, Output};
/// Final-state-transducer (FST) Segmenter
pub(crate) struct FstSegmenter<'fst> {
words_fst: &'fst Fst<&'fst [u8]>,
min_length: Option<usize>, // Optional minimum length for a word to be segmented
allow_char_split: bool, // Flag to allow or disallow splitting words into characters
min_length: Option<usize>, // Optional minimum length for a word to be segmented
allow_char_split: bool, // Flag to allow or disallow splitting words into characters
}

impl<'fst> FstSegmenter<'fst> {
pub(crate) fn new(words_fst: &'fst Fst<&'fst [u8]>, min_length: Option<usize>, allow_char_split: bool) -> Self {
pub(crate) fn new(
words_fst: &'fst Fst<&'fst [u8]>,
min_length: Option<usize>,
allow_char_split: bool,
) -> Self {
Self { words_fst, min_length, allow_char_split }
}

Expand Down Expand Up @@ -66,7 +70,8 @@ impl<'fst> FstSegmenter<'fst> {

Box::new(iter)
}
}/// find the longest key that is prefix of the given value.
}
/// find the longest key that is prefix of the given value.
#[inline]
fn find_longest_prefix(fst: &Fst<&[u8]>, value: &[u8]) -> Option<(u64, usize)> {
let mut node = fst.root();
Expand All @@ -85,4 +90,4 @@ fn find_longest_prefix(fst: &Fst<&[u8]>, value: &[u8]) -> Option<(u64, usize)> {
}
}
last_match
}
}

0 comments on commit f6999c6

Please sign in to comment.