whatlang/
lib.rs

1//! Whatlang is a Rust library to detect(regonize) natural languages.
2//! Apart from it, the library also recognizes scripts (writing system).
3//! Every language and script are represented by determined list of enums.
4//!
5//! # Examples
6//!
7//! Using `detect` function:
8//!
9//! ```
10//! use whatlang::{detect, Lang, Script};
11//!
12//! let text = "Ĉu vi ne volas eklerni Esperanton? Bonvolu! Estas unu de la plej bonaj aferoj!";
13//! let info = detect(text).unwrap();
14//! assert_eq!(info.lang(), Lang::Epo);
15//! assert_eq!(info.script(), Script::Latin);
16//!
17//! // Confidence is in the range from 0 to 1.
18//! assert_eq!(info.confidence(), 1.0);
19//! assert!(info.is_reliable());
20//! ```
21//!
22//! Using `Detector` with specified denylist or allowlist:
23//!
24//! ```
25//! use whatlang::{Detector, Lang};
26//!
27//! let allowlist = vec![Lang::Eng, Lang::Rus];
28//!
29//! // You can also create detector using with_denylist function
30//! let detector = Detector::with_allowlist(allowlist);
31//! let lang = detector.detect_lang("There is no reason not to learn Esperanto.");
32//! assert_eq!(lang, Some(Lang::Eng));
33//! ```
34//!
35//! # Features
36//!
37//! | Feature     | Description                                                                           |
38//! |-------------|---------------------------------------------------------------------------------------|
39//! | `enum-map`  | `Lang` and `Script` implement `Enum` trait from [enum-map](https://docs.rs/enum-map/) |
40//! | `arbitrary` | Support [Arbitrary](https://crates.io/crates/arbitrary)                               |
41//! | `serde`     | Implements `Serialize` and `Deserialize` for `Lang` and `Script`                      |
42//! | `dev`       | Enables `whatlang::dev` module which provides some internal API.<br/> It exists for profiling purposes and normal users are discouraged to to rely on this API.  |
43//!
44mod alphabets;
45mod combined;
46mod core;
47mod error;
48mod lang;
49mod scripts;
50mod trigrams;
51mod utils;
52
53#[cfg(feature = "dev")]
54pub mod dev;
55
56pub use crate::core::{Detector, Info, detect, detect_lang};
57pub use crate::lang::Lang;
58pub use crate::scripts::{Script, detect_script};