前提
MeCabを用いて名詞をリストに格納して出力したいと考えています。しかし,エラーがでてうまくいきません.エラーから推測すると,おそらく,"-Ochasen"に原因がありそうでしたのでこれを"-chansen"に変えて実行しました.そうすると,エラーメッセージは出ませんでしたが,何も出力されませんでした.
この件について,わかる方お教え頂ければ幸いです.
実現したいこと
- 形態素解析を行った後,名詞のみをリストで出力.
- 出てきた名詞をカウントする.
期待する出力例.
[テニス,テニス,サッカー,野球,ゴルフ,テニス,剣道,サッカー,バレー]
テニス:3
サッカー:2
・
・
・
発生している問題・エラーメッセージ
Failed initializing MeCab. Please see the README for possible solutions: https://github.com/SamuraiT/mecab-python3#common-issues If you are still having trouble, please file an issue here, and include the ERROR DETAILS below: https://github.com/SamuraiT/mecab-python3/issues issueを英語で書く必要はありません。 ------------------- ERROR DETAILS ------------------------ arguments: -Ochasen error message: [!tmp.empty()] unknown format type [chasen] ---------------------------------------------------------- File "C:\Users\subaru narahashi\graduation_research\mecab.py", line 42, in <module> main() File "C:\Users\subaru narahashi\graduation_research\mecab.py", line 21, in main mecab = MeCab.Tagger("-Ochasen") File "C:\Users\subaru narahashi\anaconda3\lib\site-packages\MeCab\__init__.py", line 124, in __init__ super(Tagger, self).__init__(args) RuntimeError
該当のソースコード
python
1import sys 2import MeCab 3import requests 4import urllib 5import re 6import json 7import pandas as pd 8from collections import Counter 9 10 11 12def main(): 13 # ファイル読み込み 14 # cmd, infile = sys.argv 15 with open('test.tex', "r", encoding = 'utf-8') as data: 16 documents = [document.strip() for document in data] 17 18 19 20 # パース 21 mecab = MeCab.Tagger("-chasen") 22 parse = mecab.parse(str(documents)) 23 lines = parse.split('\n') 24 items = (re.split('[\t,]', line) for line in lines) 25 26 #print(list(items)) 27 28 # 名詞をリストに格納 29 words = [item[0] 30 for item in items 31 if (item[0] not in ('EOS', '', 't', 'ー') and 32 item[1] == '名詞' and item[2] == '一般')] 33 34 35 # 頻度順に出力 36 counter = Counter(words) 37 for word, count in counter.most_common(): 38 print(f"{word}: {count}") 39 40 41if __name__ == "__main__": 42 main() 43
試したこと
-Ochasenを=chasenに変更
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
エラーメッセージに unknown format type [chasen] と表示されています。また、
Failed initializing MeCab. Please see the README for possible solutions:
https://github.com/SamuraiT/mecab-python3#common-issues
とあって、そのページを眺めてみますと以下の項目があります。
Using Unsupported Output Modes like -Ochasen
https://github.com/SamuraiT/mecab-python3#using-unsupported-output-modes-like--ochasen
Chasen output is not a built-in feature of MeCab, you must specify it in your dicrc or mecabrc.
辞書に何を使っているか? に依存する話ですのでそのあたりの情報が必要です。

回答2件
あなたの回答
tips
プレビュー