简体   繁体   English

IndexError:列表索引超出范围-附魔

[英]IndexError: list index out of range - enchant

I'm trying to use python to correct the spelling of a large corpus (about 100000 phrases): 我正在尝试使用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! 不需要在网站上进行搜索或在汽车上贴上产品名称,我需要知道产品的尺寸,但是在网站上找不到很长一段时间,因为参考文献不允许我找到我购买的一些物品前段时间有损坏的产品(对绘画不利),但是自从我想要它的时间以来....我问这是否是最后的副本,因为这是购买产品仿制品的bannais,所以我被迫用力!

... ...

Script: 脚本:

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)

The program works, but stops at a time with the error: 该程序可以工作,但是会因以下错误而停止:

Traceback (most recent call last): 追溯(最近一次通话):

File "correction.py", line 4, in correction = error.suggest()[0] IndexError: list index out of range 文件“ correction.py”,第4行,更正= error.suggest()[0] IndexError:列表索引超出范围

Just check that suggest has at least one item: you can have an error without a proposed correction: 只需检查建议是否至少有一项:如果没有建议的更正,可能会出错:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM