0
こんにちは私はBBCのフォルダ内の各サブフォルダが含まれている。この 読むファイルが
のようなBBCのフォルダに存在するファイルのテキストファイル
このコードは、フォルダ内のファイルにアクセスすることができますがあり
class MySentences(object):
def __init__(self, dirname):
self.dirname = dirname
def __iter__(self):
for fname in os.listdir(self.dirname):
for line in open(os.path.join(self.dirname, fname)):
yield line.split()
sentences = MySentences('C:/Users/JAYASHREE/Documents/NLP/bbc-fulltext/bbc/business')
しかし、私は各サブフォルダからファイルにアクセスしたいと思います。これを行うと次のエラーが発生します
sentences = MySentences('C:/Users/JAYASHREE/Documents/NLP/bbc-fulltext/bbc')
IOError Traceback (most recent call last)
<ipython-input-29-26fb31de4fec> in <module>()
1 sentences = MySentences('C:/Users/JAYASHREE/Documents/NLP/bbc-fulltext/bbc') # a memory-friendly iterator
----> 2 model = gensim.models.Word2Vec(sentences)
C:\Users\JAYASHREE\Anaconda2\lib\site-packages\gensim-2.3.0-py2.7-win-amd64.egg\gensim\models\word2vec.pyc in __init__(self, sentences, size, alpha, window, min_count, max_vocab_size, sample, seed, workers, min_alpha, sg, hs, negative, cbow_mean, hashfxn, iter, null_word, trim_rule, sorted_vocab, batch_words, compute_loss)
501 if isinstance(sentences, GeneratorType):
502 raise TypeError("You can't pass a generator as the sentences argument. Try an iterator.")
--> 503 self.build_vocab(sentences, trim_rule=trim_rule)
504 self.train(sentences, total_examples=self.corpus_count, epochs=self.iter,
505 start_alpha=self.alpha, end_alpha=self.min_alpha)
C:\Users\JAYASHREE\Anaconda2\lib\site-packages\gensim-2.3.0-py2.7-win-amd64.egg\gensim\models\word2vec.pyc in build_vocab(self, sentences, keep_raw_vocab, trim_rule, progress_per, update)
575
576 """
--> 577 self.scan_vocab(sentences, progress_per=progress_per, trim_rule=trim_rule) # initial survey
578 self.scale_vocab(keep_raw_vocab=keep_raw_vocab, trim_rule=trim_rule, update=update) # trim by min_count & precalculate downsampling
579 self.finalize_vocab(update=update) # build tables & arrays
C:\Users\JAYASHREE\Anaconda2\lib\site-packages\gensim-2.3.0-py2.7-win-amd64.egg\gensim\models\word2vec.pyc in scan_vocab(self, sentences, progress_per, trim_rule)
587 vocab = defaultdict(int)
588 checked_string_types = 0
--> 589 for sentence_no, sentence in enumerate(sentences):
590 if not checked_string_types:
591 if isinstance(sentence, string_types):
<ipython-input-28-48533b12127a> in __iter__(self)
5 def __iter__(self):
6 for fname in os.listdir(self.dirname):
----> 7 for line in open(os.path.join(self.dirname, fname)):
8 yield line.split()
IOError: [Errno 13] Permission denied: 'C:/Users/JAYASHREE/Documents/NLP/bbc-fulltext/bbc\\business'
は親切にあなたが直接フォルダに)あなたが開い呼び出ししようとしているため(例外IOError権限拒否をトリガしているように見える私はあなたの例では、コード
便利です –