pub struct Detector { /* private fields */ }
Expand description
Configurable structure that holds detection options and provides functions to detect language and script.
Examples
Specifying an allowlist:
use whatlang::{Detector, Lang};
// Create detector with allowlist
let detector = Detector::with_allowlist(vec![Lang::Eng, Lang::Rus]);
let lang = detector.detect_lang("That is not Russian");
assert_eq!(lang, Some(Lang::Eng));
Specifying a blacklist:
use whatlang::{Detector, Lang};
let detector = Detector::with_denylist(vec![Lang::Eng, Lang::Ita]);
let lang = detector.detect_lang("Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo.");
assert_eq!(lang, Some(Lang::Epo));
Implementations§
source§impl Detector
impl Detector
pub fn new() -> Self
pub fn with_allowlist(list: Vec<Lang>) -> Self
pub fn with_denylist(list: Vec<Lang>) -> Self
pub fn detect(&self, text: &str) -> Option<Info>
pub fn detect_lang(&self, text: &str) -> Option<Lang>
pub fn detect_script(&self, text: &str) -> Option<Script>
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Detector
impl Send for Detector
impl Sync for Detector
impl Unpin for Detector
impl UnwindSafe for Detector
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