0

ファイルを読み取り、PorterStemmerを使用してファイルのテキストの語幹トークンを保存しようとしたところ、このエラーが発生しました。

    tokens=preprocessTokens(line)
    File "/home/fl/git/KNN/preprocessDoc.py", line 20, in preprocessTokens
line=line+' '+ps.stem(w)
    File "/usr/local/lib/python2.7/dist-packages/nltk/stem/porter.py", line 664, in stem
    stem = self._step1a(stem)
    File "/usr/local/lib/python2.7/dist-packages/nltk/stem/porter.py", line 289, in _step1a
   if word.endswith('ies') and len(word) == 4:
   UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)

それを解決するには、これらの2行をコードに追加してから無視します

reload(sys)  
sys.setdefaultencoding('ISO-8859-15')

しかし、一部のファイルで次のエラーが発生しました。次に、エンコーディングを 'utf-8'I に変更しようとしましたが、同じエラーが発生しました。

tokens=preprocessTokens(line.encode('ascii',errors='ignore'))
  File "/home/fl/git/KNN/preprocessDoc.py", line 20, in preprocessTokens
    line=line+' '+ps.stem(w)
  File "/usr/local/lib/python2.7/dist-packages/nltk/stem/porter.py", line 665, in stem
    stem = self._step1b(stem)
  File "/usr/local/lib/python2.7/dist-packages/nltk/stem/porter.py", line 376, in _step1b
    lambda stem: (self._measure(stem) == 1 and
  File "/usr/local/lib/python2.7/dist-packages/nltk/stem/porter.py", line 258, in _apply_rule_list
    if suffix == '*d' and self._ends_double_consonant(word):
  File "/usr/local/lib/python2.7/dist-packages/nltk/stem/porter.py", line 214, in _ends_double_consonant
    word[-1] == word[-2] and
IndexError: string index out of range
4

1 に答える 1