Skip to main content

A Cython reimplementation of Peter Norvig's spelling corrector.

Project description

spellcheckmate

License Python Cython

description

A Cython reimplementation of Peter Norvig's spelling corrector with minor modifications. Checking for spelling and/or grammar mistakes by calling the .check(text) method of the SpellCheckMate() class enables users to interactively correct their mistakes sentence by sentence. Correct a single word by calling .correct(word) and get a list of all the alternative corrections by calling .alternatives(word) or print them out directly by .print_alternatives(word).

installation

pip install spellcheckmate

usage

from spellcheckmate import SpellCheckMate

spell_check = SpellCheckMate()

word = "somthign"
corrected_word = spell_check.correct(word)
""" the words 'somthign' and the correct 'something' are 1 character deletion and 1 transposed character away from each other. """
print(corrected_word) # prints the correct version, 'something'

word = "smthign"
corrected_word = spell_check.correct(word)
"""this is a limitation of the library, since it won't search for words of which Damerau–Levenshtein distance is greater than 2. """
print(corrected_word) # prints '404', since 'smthign' and 'something' are more than 2 edits away from each other.

word = "aie"
word_alternatives = spell_check.alternatives(word)
print(word_alternatives) # prints ['ave', 'amie', 'ate', 'ale', 'die', 'tie', 'ai', 'aye', 'are', ... ]
spell_check.print_alternatives(word)
"""
ave
amie
ate
ale
die
tie
ai
aye
are
...
"""

text = "We lov everithin. Or smthign like that."
""" parses text interactively sentence by sentence and points to mistyped word after which user can select from recommendations
or type correct version if not found in recommendations. """
corrected_text = spell_check.check(text)

"""
we lov everithin
   ^
low
lot
log
love
lo
nov
sov
los
loi
> love
we lov everithin
       ^
everything
> everything
we lov everithin
we love everything 
 or smthign like that
    ^
404
> something
 or smthign like that
or something like that 
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spellcheckmate-0.1.3.tar.gz (2.4 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page