enchant.utils: Misc utilities for the enchant package — PyEnchant 3.3.0 documentation

# enchant.utils: Misc utilities for the enchant package

This module provides miscellaneous utilities for use with the enchant spellchecking package. Currently available functionality includes:

> - functions for dealing with locale/language settings

> - ability to list supporting data files (win32 only)

> - functions for bundling supporting data files from a build

enchant.utils.get_default_language(default: str | None = None) → str | None

  Determine the user’s default language, if possible.

  This function uses the `locale` module to try to determine the user’s preferred language. The return value is as follows:

  > - if a locale is available for the LC_MESSAGES category, that language is used

  > - if a default locale is available, that language is used

  > - if the keyword argument default is given, it is used

  > - if nothing else works, None is returned

  Note that determining the user’s language is in general only possible if they have set the necessary environment variables on their system.

enchant.utils.levenshtein(s1: str, s2: str) → int

  Calculate the Levenshtein distance between two strings.

  This is straight from Wikipedia.

enchant.utils.trim_suggestions(word: str, suggs: Iterable[str], maxlen: int, calcdist: Callable[[str, str], int] = None) → List[str]

  Trim a list of suggestions to a maximum length.

  If the list of suggested words is too long, you can use this function to trim it down to a maximum length. It tries to keep the “best” suggestions based on similarity to the original word.

  If the optional calcdist argument is provided, it must be a callable taking two words and returning the distance between them. It will be used to determine which words to retain in the list. The default is a simple Levenshtein distance.