IndexError: list index out of range - enchant

IndexError: list index out of range - enchant

我正在尝试使用 python 来纠正大型语料库(大约 100000 个短语)的拼写:

Having bought a large carpet I was expecting a large package accordingly and surprised by its very small size I wanted to verify that the content was consistent with my order and the driver did not allow it, it is nevertheless recommend in the order?

Lower the sound of the ambient music ... we come for this quote cocooning resting when we come in this type of store deco, we do not want to find the supermarket atmosphere of the deco. Have the products in stock qu we can leave with.

Carrying caddies of the staff working in the shop in full passage everywhere in the stores without nobody takes care of it and which generate traffic and the general vision Take example on the shop of the forum

Package heavy and not easy to wear for a single woman: I parked at the door of the store and when I asked if anyone could help me was answered: no, we have no right to leave the store in case we have an acciden!!!.

Embed a search not refer to the website or note the name of the product on the label Car I needed to know the dimensions of the product but very long to find on the site because the reference did not allow me to find the object I bought some time ago a damaged product (bad for a painting) but since the time that I wanted it .... and I asked if it was the last copy because it was b annais to buy a product abime, I was sent to bolt a force!

...

脚本:

import enchant
from enchant.checker import SpellChecker

language = SpellChecker('en_US') # ou simplement 'en'
language.set_text(text)
for error in language:
    correction = error.suggest()[0]
    error.replace("%s" %(correction))
correcteur = language.get_text()
print (correcteur)

程序运行正常,但一次停止并出现错误:

Traceback (most recent call last):

File "correction.py", line 4, in correction = error.suggest()[0] IndexError: list index out of range

只需检查建议是否至少包含一项:您可能会遇到没有建议更正的错误:

for error in language:
    if len(error.suggest())>0: 
        correction = error.suggest()[0]
        error.replace("%s" %(correction))