pypwl: pure-python personal word list in the style of Enchant

This module provides a pure-python version of the personal word list functionality found in the spellchecking package Enchant. While the same effect can be achieved (with better performance) using the python bindings for Enchant, it requires a C extension.

This pure-python implementation uses the same algorithm but without any external dependencies or C code (in fact, it was the author’s original prototype for the C version found in Enchant).

class enchant.pypwl.PyPWL(pwl: str | None = None)

Pure-python implementation of Personal Word List dictionary. This class emulates the PWL objects provided by PyEnchant, but implemented purely in python.

add(word: str) None

Add a word to the user’s personal dictionary. For a PWL, this means appending it to the file.

add_to_pwl(word: str) None

Add a word to the user’s personal dictionary. For a PWL, this means appending it to the file.

add_to_session(word: str) None

Add a word to the session list.

check(word: str) bool

Check spelling of a word.

This method takes a word in the dictionary language and returns True if it is correctly spelled, and False otherwise.

is_added(word: str) bool

Check whether a word is in the personal word list.

is_removed(word: str) bool

Check whether a word is in the personal exclude list.

remove(word: str) None

Add a word to the user’s personal exclude list.

store_replacement(mis: str, cor: str) None

Store a replacement spelling for a miss-spelled word.

This method makes a suggestion to the spellchecking engine that the miss-spelled word mis is in fact correctly spelled as cor. Such a suggestion will typically mean that cor appears early in the list of suggested spellings offered for later instances of mis.

suggest(word: str) List[str]

Suggest possible spellings for a word.

This method tries to guess the correct spelling for a given word, returning the possibilities in a list.

class enchant.pypwl.Trie(words: Iterable[str] = ())

Class implementing a trie-based dictionary of words.

A Trie is a recursive data structure storing words by their prefix. “Fuzzy matching” can be done by allowing a certain number of missteps when traversing the Trie.

search(word: str, nerrs: int = 0) List[str]

Search for the given word, possibly making errors.

This method searches the trie for the given word, making precisely nerrs errors. It returns a list of words found.