首页 > 解决方案 > 我需要 Python 拼写检查器的帮助

问题描述

from spellchecker import SpellChecker
spell = SpellChecker()
misspelled = spell.unknown(['let', 'us', 'wlak','on','the','groun'])
for word in misspelled:
    print(spell.correction(word))
print(spell.candidates(word))

这是程序。我收到以下错误

ValueError: 提供的字典语言 (en) 不存在

标签: python

解决方案


如果您使用

pip install pyspellchecker

您需要卸载它,因为对于 2.7,它不会自动安装语言包。

pip uninstall pyspellchecker

然后你应该使用重新安装它

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

如果你重新运行你的程序,它现在应该可以工作了,但我想如果你想为循环中的每个单词获取候选者,你需要稍微调整一下。

from spellchecker import SpellChecker
spell = SpellChecker()
misspelled = spell.unknown(['let', 'us', 'wlak','on','the','groun'])
for word in misspelled:
    print(spell.correction(word))
    print(spell.candidates(word))

推荐阅读