Natural language detection for Rust. Documentation.
The library is still in active development. Here is the short example how to use it:
Add to you Cargo.toml
:
```
[dependencies]
whatlang = "0.3.0" ```
Small example:
```rust use whatlang::{detect, Lang, Script};
// Detect Esperanto (there are also detect_lang
and detect_script
functions)
let info = detect("Ĉu vi ne volas eklerni Esperanton? Bonvolu!").unwrap();
asserteq!(info.lang, Lang::Epo);
asserteq!(info.script, Script::Latin);
```
You can create configured detector to apply blacklist or whitelist:
```rust 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);
// There are also detect
and detect_script
functions
let lang = detector.detectlang("There is no reason not to learn Esperanto.");
asserteq!(lang, Some(Lang::Eng));
```
For more details, please check documentation.
cargo bench
Info
structMIT