2
考虑到与gzip压缩文件的文件夹我想创建一个语料库语料库:NLTK - 的gzip压缩文件
下失败
from nltk.corpus import PlaintextCorpusReader
wordlists = PlaintextCorpusReader('.', '.*')
wordlists.words('a.txt.gz')
的错误信息是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.6/site-packages/nltk/collections.py", line 225, in __repr__
for elt in self:
File "/anaconda3/lib/python3.6/site-packages/nltk/corpus/reader/util.py", line 296, in iterate_from
tokens = self.read_block(self._stream)
File "/anaconda3/lib/python3.6/site-packages/nltk/corpus/reader/plaintext.py", line 122, in _read_word_block
words.extend(self._word_tokenizer.tokenize(stream.readline()))
File "/anaconda3/lib/python3.6/site-packages/nltk/data.py", line 1142, in readline
new_chars = self._read(readsize)
File "/anaconda3/lib/python3.6/site-packages/nltk/data.py", line 1374, in _read
chars, bytes_decoded = self._incr_decode(bytes)
File "/anaconda3/lib/python3.6/site-packages/nltk/data.py", line 1405, in _incr_decode
return self.decode(bytes, 'strict')
File "/anaconda3/lib/python3.6/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
是什么正确的方法来做到这一点?
我使用Python 3.6与NLTK 3.2.2
是解压缩文件的一个选项?这会让生活变得更容易。 – alexis
不可以。我想让它们以gzip格式保存空间。 –