LoginSignup
2
2

More than 5 years have passed since last update.

【OSX】Python3.xでMeCab

Last updated at Posted at 2018-01-03

はじめに

スッキリした記事がなかったのでメモがわりに残しておきます。

インストール

本体のインストール

$ brew install mecab

辞書のインストール

$ brew install mecab-ipadic

バージョン確認

$ mecab -v
mecab of 0.996

mecab-python3のインストール

$ pip install mecab-python3

以上で

import MeCab

が実行可能になります。

使い方

mecab.py
import MeCab

tagger = MeCab.Tagger()

node = tagger.parseToNode('すもももももももものうち')

while node:
    #node.featureで品詞などを含む文字列を返す
    print(node.feature)
    node = node.next
$ python mecab.py
BOS/EOS,*,*,*,*,*,*,*,*
名詞,一般,*,*,*,*,すもも,スモモ,スモモ
助詞,係助詞,*,*,*,*,も,モ,モ
名詞,一般,*,*,*,*,もも,モモ,モモ
助詞,係助詞,*,*,*,*,も,モ,モ
名詞,一般,*,*,*,*,もも,モモ,モモ
助詞,連体化,*,*,*,*,の,ノ,ノ
名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
BOS/EOS,*,*,*,*,*,*,*,*

2
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
2
2