【发布时间】:2021-12-19 09:39:22
【问题描述】:
所以我有这行代码使用 NLTK 库
def autospell(text):
spells = [spell(w) for w in (nltk.word_tokenize(text))]
return " ".join(spells)
train_data['Phrase'][:200].apply(autospell)
我收到这个错误,告诉我名称拼写没有定义,我不知道这是什么意思,因为我认为它来自 NLTK 库,还是我在某处遗漏了什么?
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
【问题讨论】:
-
好吧,代码正在调用一个名为
spell()的函数;它在哪里声明? -
之前的函数是这样的: ``` !pip install nltk from autocorrect import Speller def word_tokenize(text): return nltk.word_tokenize(text) ``` 我不确定那个函数 spell 是什么来自图书馆还是应该来自我?
标签: python nltk spell-checking