前提・実現したいこと
複数の文書ファイルから名詞の単語のみを抽出し、以下の出力例のようにnumpy配列に格納するプログラムを考えているのですが頓挫している状態です。御助力をお願い致します。
文書ファイルは青空文庫から拾い、言語はPython、単語は分かち書きです。
出力例
([’名詞 名詞 名詞’, #文書1
’名詞 名詞’, #文書2
’名詞 名詞 名詞 名詞’]) #文書3
補足情報(FW/ツールのバージョンなど)
python
1import mecab 2import re 3import numpy as np 4 5with open(path) as f: 6 data = f.read() 7 8mecab = MeCab.Tagger() 9parse = mecab.parse(data) 10lines = parse.split('\n') 11items = (re.split('[\t,]', line) for line in lines) 12 13words = [item[0] 14 for item in items 15 if (item[0] not in ('EOS', '', 't', 'ー') and 16 item[1] == '名詞' and item[2] == '一般')] 17 18noun = np.array([]) 19 20for word in words: 21 noun = np.append(noun, word) 22 23noun = np.append(noun, np.array(noun), axis=0) 24print(noun)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/19 16:00
2019/05/19 16:02 編集
2019/05/19 16:04