pub struct VariantDetector { /* private fields */ }Expand description
Variation detector
Implementations§
Source§impl VariantDetector
impl VariantDetector
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new detector
The detector starts empty; register words with VariantDetector::add_word before
calling VariantDetector::detect.
§Examples
use sensitive_rs::VariantDetector;
let mut vd = VariantDetector::new();
vd.add_word("赌博");
assert_eq!(vd.detect("dubo", &["赌博"]), vec!["赌博"]); // pinyin variantSourcepub fn detect<'a>(
&'a self,
text: &str,
original_words: &[&'a str],
) -> Vec<&'a str>
pub fn detect<'a>( &'a self, text: &str, original_words: &[&'a str], ) -> Vec<&'a str>
Detect variants in text
Returns the subset of original_words whose pinyin or shape variant appears in text.
The returned slices borrow from original_words.
§Examples
use sensitive_rs::VariantDetector;
let mut vd = VariantDetector::new();
vd.add_word("赌博");
// Shape variant: 睹 is shape-confusable with 赌.
assert_eq!(vd.detect("睹博", &["赌博"]), vec!["赌博"]);Trait Implementations§
Source§impl Debug for VariantDetector
impl Debug for VariantDetector
Auto Trait Implementations§
impl Freeze for VariantDetector
impl RefUnwindSafe for VariantDetector
impl Send for VariantDetector
impl Sync for VariantDetector
impl Unpin for VariantDetector
impl UnsafeUnpin for VariantDetector
impl UnwindSafe for VariantDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more