Skip to main content

Crate langdetect

Crate langdetect 

Source
Expand description

A port of langdetect (itself a port of Nakatani Shuyo’s language-detection) that reproduces its results bit for bit, including the random walk: with the same seed, the probabilities equal those of langdetect 1.0.9 on the CPython version selected by Compat.

use langdetect::{DetectorFactory, Seed};

assert_eq!(langdetect::detect("Ein, zwei, drei, vier").unwrap(), "de");

let mut factory = DetectorFactory::builtin().clone();
factory.seed = Seed::Int(0);
let langs = factory.detect_langs("Ceci est une phrase en français.").unwrap();
assert_eq!(langs[0].lang, "fr");

Modules§

text
Text preprocessing of Detector.append, Detector.cleaning_text and NGram.

Structs§

Compat
The Python behaviour to reproduce. Results are bit-identical to langdetect running on a CPython whose version matches these settings.
DetectOptions
Options of one detection, the attributes of langdetect.detector.Detector.
Detector
Detects the language of the appended text, the equivalent of langdetect.detector.Detector.
DetectorFactory
Language profiles and n-gram probabilities, the equivalent of DetectorFactory.
LangProfile
A language profile: n-gram counts and the total number of 1-, 2- and 3-grams.
Language
A detected language and its probability.

Enums§

Error
An error, mirroring the exception langdetect raises in the same situation.
ErrorCode
Error codes of langdetect.lang_detect_exception.ErrorCode.
Seed
Seed of the random walk, mirroring DetectorFactory.seed.
SumMode
How sum() adds the probabilities when they are normalised.
UnicodeVersion
Unicode version that decides which characters str.isupper() reports as uppercase.

Functions§

detect
The most probable language of text with the built-in profiles and a random seed.
detect_langs
Languages of text with probability above 0.1, most probable first.