Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 1.01 KB

README.md

File metadata and controls

28 lines (24 loc) · 1.01 KB

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']