2

我有一个拼写检查功能(Peter Novig 的拼写更正),它适用于小型数据帧,但对于 5000 个单词的数据帧,它需要很长时间才能运行并且我停止了程序。有没有人有办法解决吗?

#correct spelling
import enchant
from spellchecker import SpellChecker
spell = SpellChecker()
def spell_correct(text):
        try:
            output = ""
            splited_words = text.split()
            d = enchant.Dict("en_US")
            for i in splited_words:
                if d.check(i):
                    output = output + i + " "
                else:
                    output = output + spell.correction(i) + " "
        except Exception as e:
            print(e)
        return output
    
df["Text"] = df["Text"].apply(spell_correct)
df

4

0 回答 0