Last active
May 4, 2018 18:36
-
-
Save widiger-anna/deb6afff5937ac2073b4110fd45bc286 to your computer and use it in GitHub Desktop.
Spell check for English using PyEnchant and spaCy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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