0

我正在尝试制作一个计数器,它会告诉我一篇文章中有多少单词是错误的。如果支票返回假,我想加一个计数器。这是我的编辑:Essay 是一个单词列表。我写了一篇文章,去掉了标点符号,把所有的字母都小写,然后列出了每个单词。我现在想编写一个循环来检查每个单词是否正确。不是,我想要一个计数器,它会返回多少单词是错误的

我已经四处搜索,但无法弄清楚如何将东西应用于此。我还没有找到可行的方法

我得到的错误我运行 num_spell_error 行 ** (python.exe:7804): CRITICAL **: enchant_dict_check: assertion `g_utf8_validate(word, len, NULL)' failed Traceback (last recent call last): File "", line 1、在文件“E:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py”中,第 538 行,在运行文件 execfile(filename, namespace) 文件“C:/Documents and Settings/stephen_beckham/. spyder2/admissions.py”,第 49 行,num_spel_errs_why = len(whybaylor) - len(filter(dictionary.check, whybaylor)) 文件“E:\Python27\lib\site-packages\enchant__init__.py”,第 577 行,检查 self._raise_error() 文件“E:\Python27\lib\site-packages\enchant__init__.py”,第 551 行,在 _raise_error 中引发 eclass(默认)附魔.errors.Error:未指定错误

当我尝试 for word 循环时出现的错误

** (python.exe:7804): CRITICAL **: enchant_dict_check: 断言 `g_utf8_validate(word, len, NULL)' 失败回溯(最近一次调用最后):文件“”,第 1 行,在文件“E:\Python27 \lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py”,第 538 行,在运行文件 execfile(文件名,命名空间)文件“C:/Documents and Settings/stephen_beckham/.spyder2/admissions.py”,第 51 行,如果 dictionary.check(word) 为 False:文件“E:\Python27\lib\site-packages\enchant__init__.py”,第 577 行,检查 self._raise_error() 文件“E:\Python27\lib\site -packages\enchant__init__.py", line 551, in _raise_error raise eclass(default) enchant.errors.Error: Unspecified Error

from __future__ import division import csv import re from string import punctuation import enchant

faithwords = ['church', 'christ', 'faith']

dictionary = enchant.Dict("en_US")

with open('2011ShortAnswers.csv', 'rb') as csvfile: data = csv.reader(csvfile, delimiter=",")

writer = csv.writer(open('2011output.csv', 'wb'))

for row in data:

    faithcounter = 0
    grammercounter = 0

    row3 = row[3]
    row3 = row3.lower().replace('  ', ' ')
    row4 = row[4]
    row4 = row4.lower().replace('  ', ' ')

    essay1_sentence = re.split('.', row3)
    essay2_sentence = re.split('.', row4)
    essay1_sentencelen = len(essay1_sentence)
    essay2_sentencelen = len(essay2_sentence)

    for p in list(punctuation):
        row3 = row3.replace(p, '')
        row4 = row4.replace(p, '')

    essay1 = re.split(' ', row3)
    essay2 = re.split(' ', row4)

    essay1len = len(essay1)
    essay2len = len(essay2)

   num_spel_errs_why = len(essay1) - len(filter(dictionary.check, essay1))
    for word in essay1:
        if dictionary.check(word) is False:
            grammercounter = grammercounter + 1
4

0 回答 0