I am trying to produce a counter that will tell me how many words are wrong in an essay. I want to add one to counter if check is returned false. Here is what I have EDIT: Essay is a list of words. I took an essay, took out punctuation, made all the letters lower case and then made a list of each individual word. I now want to write a loop that checks each word to see if is proper. It is not, I want a counter that will return how many words are wrong
I have searched around, but can't figure out how to apply stuff to this. I haven't found what will work
The errors I get I run the num_spell_error line ** (python.exe:7804): CRITICAL **: enchant_dict_check: assertion `g_utf8_validate(word, len, NULL)' failed Traceback (most recent call last): File "", line 1, in File "E:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 538, in runfile execfile(filename, namespace) File "C:/Documents and Settings/stephen_beckham/.spyder2/admissions.py", line 49, in num_spel_errs_why = len(whybaylor) - len(filter(dictionary.check, whybaylor)) File "E:\Python27\lib\site-packages\enchant__init__.py", line 577, in check self._raise_error() File "E:\Python27\lib\site-packages\enchant__init__.py", line 551, in _raise_error raise eclass(default) enchant.errors.Error: Unspecified Error
The error I get when I try the for word loop
** (python.exe:7804): CRITICAL **: enchant_dict_check: assertion `g_utf8_validate(word, len, NULL)' failed Traceback (most recent call last): File "", line 1, in File "E:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 538, in runfile execfile(filename, namespace) File "C:/Documents and Settings/stephen_beckham/.spyder2/admissions.py", line 51, in if dictionary.check(word) is False: File "E:\Python27\lib\site-packages\enchant__init__.py", line 577, in check self._raise_error() File "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