### Get all language scores with Paasaa.all/2 Source: https://hexdocs.pm/paasaa/Paasaa.html Shows how to use Paasaa.all/2 to get a list of languages scored by probability, limited to the top 5 results. ```elixir iex> Paasaa.all("Detect this!") |> Enum.take(5) [ {"eng", 1.0}, {"sco", 0.8230731943771207}, {"nob", 0.6030053320407174}, {"nno", 0.5525933107125545}, {"swe", 0.508482792050412} ] ``` -------------------------------- ### Get scored language list with Paasaa.all/1 Source: https://hexdocs.pm/paasaa/readme.html Detect the language and return a scored list of possible languages, ordered by likelihood. The output is a list of tuples with language code and score. ```elixir iex> Paasaa.all("Detect this!") [ {"eng", 1.0}, {"sco", 0.8230731943771207}, {"nob", 0.6030053320407174}, {"nno", 0.5525933107125545}, ... ] ``` -------------------------------- ### Set minimum text length with :min_length option Source: https://hexdocs.pm/paasaa/readme.html Adjust the minimum text length threshold with the `:min_length` option. By default, very short strings return "und". Setting a lower threshold allows detection of shorter texts. ```elixir iex> Paasaa.detect("Привет", min_length: 10) "und" iex> Paasaa.detect("Привет", min_length: 6) "rus" ``` -------------------------------- ### Use blacklist and whitelist options with Paasaa.detect/2 Source: https://hexdocs.pm/paasaa/readme.html Restrict language detection using the `blacklist` and `whitelist` options. Blacklist excludes languages, whitelist limits to a set. Useful when the text is known to be from a few languages or to avoid false positives. ```elixir # Exclude English to find the next most likely language iex> Paasaa.detect("Detect this!", blacklist: ["eng"]) "sco" # Only consider Polish and Serbian iex> text = "Pošto je priznavanje urođenog dostojanstva i jednakih i neotuđivih prava..." iex> Paasaa.detect(text, whitelist: ["pol", "srp"]) "srp" ``` -------------------------------- ### Detect script with Paasaa.detect_script/1 Source: https://hexdocs.pm/paasaa/Paasaa.html Shows how to use Paasaa.detect_script/1 to detect the script of a string, returning a tuple with the script name and score. ```elixir iex> Paasaa.detect_script("Detect this!") {"Latin", 0.8333333333333334} ``` -------------------------------- ### Regenerate language data with mix script/generate_language_data.exs Source: https://hexdocs.pm/paasaa/index.html Regenerate the language data modules when updating language data. Run this command from the project root. ```shell mix script/generate_language_data.exs ``` -------------------------------- ### Add paasaa dependency in mix.exs Source: https://hexdocs.pm/paasaa/readme.html Add the paasaa dependency to your mix.exs file. After adding, run `mix deps.get` to fetch and compile the library. ```elixir def deps do [{:paasaa, "~> 1.0.0"}] end ``` -------------------------------- ### Detect language with Paasaa.detect/2 Source: https://hexdocs.pm/paasaa/Paasaa.html Shows the basic usage of Paasaa.detect/2 to detect the language of a string, returning the ISO6393 language code "eng". ```elixir iex> Paasaa.detect "Detect this!" "eng" ``` -------------------------------- ### Paasaa.detect/2 Source: https://hexdocs.pm/paasaa/Paasaa.html Detects a language and returns a string with ISO6393 language code (e.g. "eng"). Accepts a text string and optional keyword options. ```APIDOC ## Paasaa.detect/2 ### Description Detects a language and returns a string with ISO6393 language code (e.g. "eng"). ### Function Signature `detect(str :: String.t(), options()) :: language :: String.t()` ### Parameters - `str` (String.t()) - Required - A text string. - `options` (keyword list) - Optional - A keyword list with options: - `:min_length` (integer) - Optional - If the text is shorter than `:min_length` it will return `und`. Default: `10`. - `:max_length` (integer) - Optional - Maximum length to analyze. Default: `2048`. - `:whitelist` (list of strings) - Optional - Allow languages. Default: `[]`. - `:blacklist` (list of strings) - Optional - Disallow languages. Default: `[]`. ### Examples ```elixir Paasaa.detect "Detect this!" # => "eng" ``` With the `:blacklist` option: ```elixir Paasaa.detect "Detect this!", blacklist: ["eng"] # => "sco" ``` With the `:min_length` option: ```elixir Paasaa.detect "Привет", min_length: 6 # => "rus" ``` It returns `und` for undetermined language: ```elixir Paasaa.detect "1234567890" # => "und" ``` ### Response Returns a string with ISO6393 language code. ### Response Example ```elixir "eng" ``` ``` -------------------------------- ### Detect language with min_length option Source: https://hexdocs.pm/paasaa/Paasaa.html Shows using the :min_length option to require a minimum text length; here the text is shorter than the default but still detected as "rus". ```elixir iex> Paasaa.detect "Привет", min_length: 6 "rus" ``` -------------------------------- ### Detect language with blacklist option Source: https://hexdocs.pm/paasaa/Paasaa.html Shows using the :blacklist option to disallow a language, causing the detection to return "sco" instead of "eng". ```elixir iex> Paasaa.detect "Detect this!", blacklist: ["eng"] "sco" ``` -------------------------------- ### Detect undetermined language Source: https://hexdocs.pm/paasaa/Paasaa.html Shows that detect/2 returns "und" for undetermined language when the text is not recognized. ```elixir iex> Paasaa.detect "1234567890" "und" ``` -------------------------------- ### Define options type Source: https://hexdocs.pm/paasaa/Paasaa.html Defines the options type used by Paasaa functions, with min_length, max_length, whitelist, and blacklist keys. ```elixir @type options() :: [ min_length: integer(), max_length: integer(), whitelist: [String.t()], blacklist: [String.t()] ] ``` -------------------------------- ### Regenerate language data modules Source: https://hexdocs.pm/paasaa/readme.html Regenerate the language data modules when updating language data. Run this command from the project root. ```shell mix run script/generate_language_data.exs ``` -------------------------------- ### Spec for detect/2 Source: https://hexdocs.pm/paasaa/Paasaa.html Specifies the type signature for the detect/2 function, which returns a string with the ISO6393 language code. ```elixir @spec detect(str :: String.t(), options()) :: language :: String.t() ``` -------------------------------- ### Paasaa.all/2 Source: https://hexdocs.pm/paasaa/Paasaa.html Detects a language and returns a list of languages scored by probability. Accepts a text string and optional keyword options. ```APIDOC ## Paasaa.all/2 ### Description Detects a language and returns a list of languages scored by probability. ### Function Signature `all(str :: String.t(), options()) :: result()` ### Parameters - `str` (String.t()) - Required - A text string. - `options` (keyword list) - Optional - A keyword list with options: `:min_length`, `:max_length`, `:whitelist`, `:blacklist`. Defaults to `[min_length: 10, max_length: 2048, whitelist: [], blacklist: []]`. ### Example ```elixir Paasaa.all("Detect this!") |> Enum.take(5) ``` ### Response Returns a list of tuples `{language, score}` where `language` is a string and `score` is a number. ### Response Example ```elixir [ {"eng", 1.0}, {"sco", 0.8230731943771207}, {"nob", 0.6030053320407174}, {"nno", 0.5525933107125545}, {"swe", 0.508482792050412} ] ``` ``` -------------------------------- ### Detect language with Paasaa.detect/1 Source: https://hexdocs.pm/paasaa/readme.html Detect the language of a given text. Returns the language code as a string, e.g., "eng" for English. ```elixir iex> Paasaa.detect("Detect this!") "eng" ``` -------------------------------- ### Paasaa.detect_script/1 Source: https://hexdocs.pm/paasaa/Paasaa.html Detects a script of a text string and returns a tuple with the script name and a score. ```APIDOC ## Paasaa.detect_script/1 ### Description Detects a script of a text string. ### Function Signature `detect_script(str :: String.t()) :: {String.t(), number()}` ### Parameters - `str` (String.t()) - Required - A text string. ### Example ```elixir Paasaa.detect_script("Detect this!") ``` ### Response Returns a tuple `{script_name, score}` where `script_name` is a string and `score` is a number. ### Response Example ```elixir {"Latin", 0.8333333333333334} ``` ``` -------------------------------- ### Spec for detect_script/1 Source: https://hexdocs.pm/paasaa/Paasaa.html Specifies the type signature for the detect_script/1 function, which returns a tuple with the script name and a score. ```elixir @spec detect_script(str :: String.t()) :: {String.t(), number()} ``` -------------------------------- ### Spec for all/2 Source: https://hexdocs.pm/paasaa/Paasaa.html Specifies the type signature for the all/2 function, which returns a list of languages scored by probability. ```elixir @spec all(str :: String.t(), options()) :: result() ``` -------------------------------- ### Define result type Source: https://hexdocs.pm/paasaa/Paasaa.html Defines the result type as a list of tuples with language code and score. ```elixir @type result() :: [{language :: String.t(), score :: number()}] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.