8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MeCab で surface が想定通りの結果にならないバグ

8
Posted at

事象

MeCab で surface(表層形)が正しい表示にならない。

注意

surface が 取得できないバグ とは別件のバグです。こちらについては下記の記事を参考にしてください。

再現した環境

  • Anaconda Python 3.6.5
  • MeCab 0.996
  • mecab-python3 0.996.1
  • 辞書は mecab-ipadic-NEologd を使用

再現方法

次のようなコードを書いて実行します。

import MeCab


tagger = MeCab.Tagger('-d /usr/lib/mecab/dic/mecab-ipadic-neologd')
tagger.parse('')

node = tagger.parseToNode('メイが恋ダンスを踊っている。')
result = []

while node:
    surface = node.surface
    feature = node.feature.split(',')

    print(surface, feature)

    node = node.next
実行結果
メイが恋ダンスを踊っている。 ['BOS/EOS', '*', '*', '*', '*', '*', '*', '*', '*']
メイが恋ダンスを踊っている。 ['名詞', '固有名詞', '人名', '一般', '*', '*', 'M.A.Y', 'メイ', 'メイ']
が恋ダンスを踊っている。 ['助詞', '格助詞', '一般', '*', '*', '*', 'が', 'ガ', 'ガ']
恋ダンスを踊っている。 ['名詞', '固有名詞', '一般', '*', '*', '*', '恋ダンス', 'コイダンス', 'コイダンス']
を踊っている。 ['助詞', '格助詞', '一般', '*', '*', '*', 'を', 'ヲ', 'ヲ']
踊っている。 ['動詞', '自立', '*', '*', '五段・ラ行', '連用タ接続', '踊る', 'オドッ', 'オドッ']
ている。 ['助詞', '接続助詞', '*', '*', '*', '*', 'て', 'テ', 'テ']
いる。 ['動詞', '非自立', '*', '*', '一段', '基本形', 'いる', 'イル', 'イル']['記号', '句点', '*', '*', '*', '*', '。', '。', '。']
 ['BOS/EOS', '*', '*', '*', '*', '*', '*', '*', '*']
[]

解決方法

すでに issue #19 で解決されているので GitHub から最新のソースコードを取得してインストールします。

$ pipenv install -e git+https://github.com/SamuraiT/mecab-python3#egg=mecab-python3

インストール後に再度実行すれば正しく表示されました。

実行結果
メイ ['名詞', '固有名詞', '人名', '一般', '*', '*', 'M.A.Y', 'メイ', 'メイ']['助詞', '格助詞', '一般', '*', '*', '*', 'が', 'ガ', 'ガ']
恋ダンス ['名詞', '固有名詞', '一般', '*', '*', '*', '恋ダンス', 'コイダンス', 'コイダンス']['助詞', '格助詞', '一般', '*', '*', '*', 'を', 'ヲ', 'ヲ']
踊っ ['動詞', '自立', '*', '*', '五段・ラ行', '連用タ接続', '踊る', 'オドッ', 'オドッ']['助詞', '接続助詞', '*', '*', '*', '*', 'て', 'テ', 'テ']
いる ['動詞', '非自立', '*', '*', '一段', '基本形', 'いる', 'イル', 'イル']['記号', '句点', '*', '*', '*', '*', '。', '。', '。']
 ['BOS/EOS', '*', '*', '*', '*', '*', '*', '*', '*']
[]

mecab-python3 0.996.2 がリリースされれば PyPI からインストールしてもこの問題は解消されていると思います。

8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?