pypwl: pure-python personal word list in the style of Enchant — PyEnchant 3.2.2 documentation

# 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=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)

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

  add_to_pwl(word)

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

  add_to_session(word)

    Add a word to the session list.

  check(word)

    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)

    Check whether a word is in the personal word list.

  is_removed(word)

    Check whether a word is in the personal exclude list.

  remove(word)

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

  store_replacement(mis, cor)

    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)

    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=())

  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, nerrs=0)

    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.