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

code_to_eng_name(code)

@spec code_to_eng_name(String.t()) :: String.t() | nil

Get the full language English name from language code.

Examples

iex> code_to_eng_name("fra")
"French"

iex> code_to_eng_name("abc")
nil

code_to_name(code)

@spec code_to_name(String.t()) :: String.t() | nil

Get the full language native name from language code.

Examples

iex> code_to_name("fra")
"Français"

iex> code_to_name("abc")
nil

detect(sentence)

@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

detect(sentence, opts)

@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 is nil.

  • :denylist - List of language codes to exclude (e.g., ["rus", "ukr"]) The default value is nil.

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