Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Last active December 18, 2018 05:30
Show Gist options
  • Save YoshihitoAso/9048005 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/9048005 to your computer and use it in GitHub Desktop.
[Python][Mecab]ubuntu環境にmecabをインストールする方法

Ubuntu環境にMecabをインストールする方法

インストール手順

$ sudo apt-get install mecab libmecab-dev mecab-ipadic
$ sudo aptitude install mecab-ipadic-utf8
$ sudo apt-get install python-mecab

SAMPLE

mecab_sample.py

# coding: utf-8
import sys
import MeCab

m = MeCab.Tagger ("-Ochasen")

print ("私の名前はボブです。")
print m.parse("私の名前はボブです。")

↓↓実行結果↓↓

私の名前はボブです。
私      ワタシ  私      名詞-代名詞-一般
の      ノ      の      助詞-連体化
名前    ナマエ  名前    名詞-一般
は      ハ      は      助詞-係助詞
ボブ    ボブ    ボブ    名詞-固有名詞-人名-名
です    デス    です    助動詞  特殊・デス      基本形
。      。      。      記号-句点
EOS
@shekharkoirala
Copy link

is the answer available ?

@shekharkoirala
Copy link

Download , mecab-ipdaic-neologd dictionary

git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git
cd mecab-ipadic-neologd
./bin/install-mecab-ipadic-neologd -n
echo mecab-config --dicdir"/mecab-ipadic-neologd"

/usr/local/lib/mecab/dic/mecab-ipadic-neologd

Other than this is confirmation of not proper path of dictionary.
mecab -D
Here is my error , the dict is in another path.
Error: param.cpp(69) [ifs] no such file or directory: /usr/local/lib/mecab/dic/ipadic/dicrc

But this is working :
echo "8月3日に放送された「中居正広の金曜日のスマイルたちへ」(TBS系)で、1日たった5分でぽっこりおなかを解消するというダイエット方法を紹介。キンタロー。のダイエットにも密着。" | mecab -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd

Reason is , the path is working.
So Final step :
locate mecabrc
dicdir = /usr/local/lib/mecab/dic/mecab-ipadic-neologd

To every file found, replace the value of dicdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment