Skip to content

simonemainardi/pyspell

Repository files navigation

pyspell

A fast pure-python spell checking algorithm. Seriously, it's really fast. And supports Redis.

Features

pyspell quickly finds the best suggestions of a word. Suggestions are stored in a dictionary and can be dynamically updated. The dictionary can be initialized using, for example, a text book. Word frequencies in the text are taken into account to return the most accurate suggestions.

Examples

Suppose we want to initialize our dictionary with a book. Let's download Moby Dick from Project Gutenberg.

>>> import urllib
>>> import re, string
>>> 
>>> book = urllib.urlopen('https://www.gutenberg.org/files/2701/2701-0.txt').read()
>>> pattern = re.compile('[\W_]+')  # alpha-num only
>>> book = pattern.sub(' ', book).lower().split()  # lower case

Using the book as a dictionary for pyspell is as simple as:

>>> from pyspell import Dictionary
>>> d = Dictionary()
>>> d.add_words(book)
>>> d.lookup('moubtains')
    ['mountains']
>>> d.lookup('cricumstances')
    ['circumstances']

About

A fast pure-python spell checking algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages