尝试使用Python中的PyEnchant为拼写错误的单词编写计数器

时间:2013-10-24 16:00:59

标签: python pyenchant

我正在尝试制作一个计数器,它会告诉我一篇文章中有多少单词出错。如果check返回false,我想添加一个到counter。这就是我所拥有的 编辑:论文是一个单词列表。我拿了一篇文章,拿出标点符号,将所有字母小写,然后列出每个单词。我现在想写一个循环来检查每个单词,看看是否合适。事实并非如此,我想要一个能够返回多少单词错误的计数器

我已经四处寻找,但无法弄清楚如何应用这些东西。我还没有找到可行的方法

我得到的错误我运行num_spell_error行 **(python.exe:7804):CRITICAL **:enchant_dict_check:断言`g_utf8_validate(word,len,NULL)'失败 Traceback(最近一次调用最后一次):   文件“”,第1行,in   在运行文件中的文件“E:\ Python27 \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py”,第538行     execfile(文件名,命名空间)   文件“C:/ Documents and Settings / stephen_beckham / .spyder2 / admissions.py”,第49行,in     num_spel_errs_why = len(whybaylor) - len(filter(dictionary.check,whybaylor))   文件“E:\ Python27 \ lib \ site-packages \ enchant__init __。py”,第577行,正在检查中     self._raise_error()   _raise_error中的文件“E:\ Python27 \ lib \ site-packages \ enchant__init __。py”,第551行     提升eclass(默认) enchant.errors.Error:未指定的错误

我尝试使用单词循环时出现的错误

**(python.exe:7804):CRITICAL **:enchant_dict_check:断言`g_utf8_validate(word,len,NULL)'失败 Traceback(最近一次调用最后一次):   文件“”,第1行,in   在运行文件中的文件“E:\ Python27 \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py”,第538行     execfile(文件名,命名空间)   文件“C:/ Documents and Settings / stephen_beckham / .spyder2 / admissions.py”,第51行,in     如果dictionary.check(word)为False:   文件“E:\ Python27 \ lib \ site-packages \ enchant__init __。py”,第577行,正在检查中     self._raise_error()   _raise_error中的文件“E:\ Python27 \ lib \ site-packages \ enchant__init __。py”,第551行     提升eclass(默认) enchant.errors.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

0 个答案:

没有答案