0

エッセイでいくつの単語が間違っているかを教えてくれるカウンターを作成しようとしています. チェックがfalseを返した場合にカウンターに1つ追加したい。これが私が持っているものです 編集:エッセイは単語のリストです。私はエッセイを取り、句読点を取り除き、すべての文字を小文字にしてから、個々の単語のリストを作成しました. ここで、各単語をチェックして適切かどうかを確認するループを書きたいと思います。そうではありません。いくつの単語が間違っているかを返すカウンターが必要です

私は周りを検索しましたが、これに何かを適用する方法がわかりません。うまくいくものを見つけていない

エラー num_spell_error 行を実行します ** (python.exe:7804): CRITICAL **: enchant_dict_check: assertion `g_utf8_validate(word, len, NULL)' failed Traceback (most recent call last): File "", line 1、ファイル「E:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py」の 538 行目、実行ファイル execfile(ファイル名、名前空間) ファイル「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 行目、 check self._raise_error() ファイル "E:\Python27\lib\site-packages\enchant__init__.py"、551 行目、_raise_error raise eclass(default) enchant.errors.Error: Unspecified Error

for word ループを試したときに発生するエラー

** (python.exe:7804): クリティカル **: 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"、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"、551 行目、_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