Whatlangex (whatlangex v0.4.0)
NIF bindings for Whatlang, a natural language detection library written in Rust.
Summary
Functions
Get the full language English name from language code.
Get the full language native name from language code.
Detect the language of the given sentence.
Detect the language of the given sentence with filtering options.
Functions
Get the full language English name from language code.
Examples
iex> code_to_eng_name("fra")
"French"
iex> code_to_eng_name("abc")
nil
Get the full language native name from language code.
Examples
iex> code_to_name("fra")
"Français"
iex> code_to_name("abc")
nil
@spec detect(String.t()) :: Whatlangex.Detection.t() | nil
Detect the language of the given sentence.
Examples
iex> detect("This is a cool sentence.")
%Whatlangex.Detection{lang: "eng", script: "Latin", confidence: ...}
iex> detect("")
nil
@spec detect( String.t(), keyword() ) :: Whatlangex.Detection.t() | nil
Detect the language of the given sentence with filtering options.
Options
:allowlist- List of language codes to consider (e.g.,["eng", "fra", "spa"]) The default value isnil.:denylist- List of language codes to exclude (e.g.,["rus", "ukr"]) The default value isnil.
Note: allowlist and denylist are mutually exclusive. If both are provided, only allowlist will be used.
Examples
iex> detect("Ceci est une phrase.", allowlist: ["eng", "fra"])
%Whatlangex.Detection{lang: "fra", script: "Latin", confidence: ...}
iex> detect("Hello world", denylist: ["spa", "fra"])
%Whatlangex.Detection{lang: "eng", script: "Latin", confidence: ...}
iex> detect("", allowlist: ["eng"])
nil