Skip to main content

pyspellchecker

https://travis-ci.org/barrust/pyspellchecker.svg?branch=master https://coveralls.io/repos/github/barrust/pyspellchecker/badge.svg?branch=master

Pure Python Spell Checking based on Peter Norvig’s blog post on setting up a simple spell checking algorithm.

It uses a Levenshtein Distance algorithm to find permutations within an edit distance of 2 from the original word. It then compares all permutations (insertions, deletions, replacements, and transpositions) to known words in a word frequency list. Those words that are found more often in the frequency list are *more likely* the correct results.

pyspellchecker supports multiple languages including English, Spanish, German, and French. Dictionaries were generated using the WordFrequency project on GitHub.

pyspellchecker supports Python 3. If may work for Python 2.7 but it is not guaranteed (especially for Non-English dictionaries)!

Installation

The easiest method to install is using pip:

pip install pyspellchecker

To install from source:

git clone https://github.com/barrust/pyspellchecker.git
cd pyspellchecker
python setup.py install

As always, I highly recommend using the Pipenv package to help manage dependencies!

Quickstart

After installation, using pyspellchecker should be fairly straight forward:

from spellchecker import SpellChecker

spell = SpellChecker()

# find those words that may be misspelled
misspelled = spell.unknown(['something', 'is', 'hapenning', 'here'])

for word in misspelled:
    # Get the one `most likely` answer
    print(spell.correction(word))

    # Get a list of `likely` options
    print(spell.candidates(word))

If the Word Frequency list is not to your liking, you can add additional text to generate a more appropriate list for your use case.

from spellchecker import SpellChecker

spell = SpellChecker()  # loads default word frequency list
spell.word_frequency.load_text_file('./my_free_text_doc.txt')

# if I just want to make sure some words are not flagged as misspelled
spell.word_frequency.load_words(['microsoft', 'apple', 'google'])
spell.known(['microsoft', 'google'])  # will return both now!

More work in storing and loading word frequency lists is planned; stay tuned.

Additional Methods

On-line documentation is available; below contains the cliff-notes version of some of the available functions:

correction(word): Returns the most probable result for the misspelled word

candidates(word): Returns a set of possible candidates for the misspelled word

known([words]): Returns those words that are in the word frequency list

unknown([words]): Returns those words that are not in the frequency list

word_probability(word): The frequency of the given word out of all words in the frequency list

The following are less likely to be needed by the user but are available:

edit_distance_1(word): Returns a set of all strings at a Levenshtein Distance of one based on the alphabet of the selected language

edit_distance_2(word): Returns a set of all strings at a Levenshtein Distance of two based on the alphabet of the selected language

Credits

Metadata

Release files for pyspellchecker 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyspellchecker 0.1.4
File Size Uploaded
pyspellchecker-0.1.4.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyspellchecker 0.1.4
File Interpreter ABI Platform
pyspellchecker-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 1.6 MB

Release files / pyspellchecker-0.1.4.tar.gz

Download URL pyspellchecker-0.1.4.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4ddf97038ad4e645c0716664ec4caaa3b17ce8135314365a0a3ce37707c811ff
BLAKE2b-256 checksum
How to use checksums
cb3a790b3ca23daa54015364f07eedf6d212b6ff2178907e0252add676882a51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.8.1 pkginfo/1.4.1 requests/2.18.1 setuptools/36.2.0 requests-toolbelt/0.7.0 clint/0.5.1 CPython/2.7.12 Linux/4.4.0-135-generic

Release files / pyspellchecker-0.1.4-py3-none-any.whl

Download URL pyspellchecker-0.1.4-py3-none-any.whl
Size 1.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5733c5115d8972634d33f7b8aa6b1d9cacbe97f8c6a6e1bf1c0e72f3430267c9
BLAKE2b-256 checksum
How to use checksums
a28d305277ac1fe4105cf63fc296d806c1f2f1dd05ac0b7005ca8a034b0ea037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.8.1 pkginfo/1.4.1 requests/2.18.1 setuptools/36.2.0 requests-toolbelt/0.7.0 clint/0.5.1 CPython/2.7.12 Linux/4.4.0-135-generic

Release history Release notifications | RSS feed

0.9.1

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2.0

2 release files

0.1.5

2 release files

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page