##前提・実現したいこと
使用環境
Python 3.7
Calaboratory
MeCab
・形態素解析で['メイ', '恋ダンス', '踊る', 'いる']と出力したい。
Python(Calaboratory)で['メイが恋ダンスを踊っている']のストップワードの除去をしており、上記のように出力したいです。
発生している問題・エラーメッセージ
・[]が出力される。
・'恋'と'ダンス'が分かれて表示される。
該当のソースコード
言語:Python
!apt install aptitude
!aptitude install mecab libmecab-dev mecab-ipadic-utf8 git make curl xz-utils file -y
!pip install mecab-python3==0.7
!git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git
!echo yes | mecab-ipadic-neologd/bin/install-mecab-ipadic-neologd -n
!sed -e "s!/var/lib/mecab/dic/debian!/usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd!g" /etc/mecabrc > /etc/mecabrc.new
!cp /etc/mecabrc /etc/mecabrc.org
!cp /etc/mecabrc.new /etc/mecabrc
import MeCab
tagger = MeCab.Tagger('var/lib/mecab/dic/mecab-ipadic-neologd')
tagger.parse("")
node = tagger.parseToNode('メイが恋ダンスを踊っている')
result = []
while node is not None:
hinshi = node.feature.split(", ")[0]
if hinshi in ["名詞"]:
result.append(node.surface)
elif hinshi in ["動詞", "形容詞"]:
result.append(node.feature.split(", ")[6])
node = node.next
print(result)
試したこと
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/04 01:49
2019/09/04 02:41
2019/09/04 04:34