Skip to content

Instantly share code, notes, and snippets.

@widiger-anna
Last active May 4, 2018 18:36
Show Gist options
  • Save widiger-anna/deb6afff5937ac2073b4110fd45bc286 to your computer and use it in GitHub Desktop.
Save widiger-anna/deb6afff5937ac2073b4110fd45bc286 to your computer and use it in GitHub Desktop.
Spell check for English using PyEnchant and spaCy
from __future__ import unicode_literals, print_function
# Install pyenchant: PyEnchant https://github.com/rfk/pyenchant
# Install spaCy: pip install spacy && python -m spacy download en
import spacy
import enchant
nlp = spacy.load('en_core_web_sm')
doc = nlp(u"This sentence is grammatically correct. THis sentence definately has sum mispeled wordz.")
# create a dictionary
d = enchant.Dict('en_US')
for token in doc:
word = str(token)
if not d.check(word):
corrections = d.suggest(word)
print("Misspelled word: {}".format(word))
print("Suggested corrections: {}, {}".format(corrections[0], corrections[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment