0
ファイルを読み込み、ファイルのテキストのステムトークンを格納するためにPorterStemmerを使用しようとしましたが、このエラーが発生しました。ポーターステマーとPythonでエンコーディングをする方法を手に入れよう
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'に変更しようとしましたが、同じエラーが発生しました。
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