Crate whatlang [−] [src]
Whatlang is a Rust library to detect(regonize) natural languages. Apart from it, the library also recognizes scripts (writing system). Every language and script are represented by determined list of enums.
Examples
Using detect
function:
use whatlang::{detect, Lang, Script}; let info = detect("Ĉu vi ne volas eklerni Esperanton? Bonvolu!").unwrap(); assert_eq!(info.lang, Lang::Epo); assert_eq!(info.script, Script::Latin);
Using Detector
with specified blacklist or whitelist:
use whatlang::{Detector, Lang}; const WHITELIST : &'static [Lang] = &[Lang::Eng, Lang::Rus]; // You can also create detector using with_blacklist function let detector = Detector::with_whitelist(WHITELIST); let lang = detector.detect_lang("There is no reason not to learn Esperanto."); assert_eq!(lang, Some(Lang::Eng));
Structs
Detector |
Configurable structure that holds detection options and provides functions to detect language and script. |
Info |
Represents a full outcome of language detection. |
Enums
Lang |
Represents a language following ISO 639-3 standard. |
Script |
Represents a writing system (Latin, Cyrillic, Arabic, etc). |
Functions
detect |
Detect a language and a script by a given text. |
detect_lang |
Detect only a language by a given text. |
detect_script |
Detect only a script by a given text |