首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >问:使用NLTK的Python拼写检查器

问:使用NLTK的Python拼写检查器
EN

Stack Overflow用户
提问于 2021-11-05 09:58:20
回答 1查看 90关注 0票数 1

所以我使用NLTK库编写了这行代码

代码语言:javascript
复制
def autospell(text):
        spells = [spell(w) for w in (nltk.word_tokenize(text))]
        return " ".join(spells) 
train_data['Phrase'][:200].apply(autospell) 

我收到了这个错误,告诉我名字拼写没有定义,我不知道这是什么意思,因为我以为它来自NLTK库,或者我错过了什么?

代码语言:javascript
复制
NameError                                 Traceback (most recent call last)
<ipython-input-119-582bf5662c88> in <module>()
      5         spells = [spell(w) for w in (nltk.word_tokenize(text))]
      6         return " ".join(spells)
----> 7 train_data['Phrase'][:200].apply(autospell)

2 frames
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-119-582bf5662c88> in <listcomp>(.0)
      3         correct the spelling of the word.
      4         """
----> 5         spells = [spell(w) for w in (nltk.word_tokenize(text))]
      6         return " ".join(spells)
      7 train_data['Phrase'][:200].apply(autospell)

NameError: name 'spell' is not defined
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-05 10:07:53

查看Spell Checker for Python,您可能应该使用autocorrect库。示例代码:

代码语言:javascript
复制
from autocorrect import Speller

spell = Speller(lang='en')

def autospell(text):
        spells = [spell(w) for w in (nltk.word_tokenize(text))]
        return " ".join(spells) 
train_data['Phrase'][:200].apply(autospell) 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69851442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档