Technical notes‎ > ‎

Using Mecab

posted May 11, 2016, 12:07 AM by Le Tuan Anh   [ updated Sep 25, 2017, 2:59 AM ]

Install Mecab

Download these files

  • mecab-0.996
  • mecab-ipadic-2.7.0-20070801

Make (Source: https://sites.google.com/site/casualconc/utility-programs/install-mecab-ruby---detail)

Note: Make sure that you have installed the gcc-c++ package.

sudo dnf install -y gcc-c++

cd mecab-0.996
./configure --with-charset=utf-8
make
make check
sudo make install

cd mecab-ipadic-2.7.0-20070801
./configure --with-charset=utf-8
make
sudo make install

# mecab-python3
sudo pip install mecab-python3
# for python 2
sudo pip install mecab-python

# (See this as well: http://d.hatena.ne.jp/addition/20130405/1365089276)
# Basically, you should edit the file
/etc/ld.so.conf
# and its content should look like this

include ld.so.conf.d/*.conf
/usr/local/lib
# and then run this command:
sudo ldconfig

# Alternatively, you can add mecab's lib folder to LD_LIBRARY_PATH to tell Python where to find the SO file.
# E.g. Add this to your .bashrc file
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/username/local/mecab/lib

# There are two important executable files for mecab which are mecab-config and mecab.
# These two files can be found in mecab installation folder (by default they are at /usr/bin/mecab and /usr/bin/mecab-config)

Using Mecab

# show help
mecab -h

# analyse a file
mecab sentences.txt

# analyse a sentence
mecab "私は猫が大好きだな。"

# tokenization a sentence
mecab -O wakati "私は猫が大好きだな。"

MeCab-python

Read more here: http://aidiary.hatenablog.com/entry/20101121/1290339360)

mecab = MeCab.Tagger("-O wakati")
print(mecab.parse('私は猫が大好きだな。'))

With JACY/ACE


echo "アブラを売る。" | mecab -O wakati | ace -g jacy.dat -1Tf


In case you don't have permission, download the file mecab-all.tar.gz below, and run install_local.sh to run it locally. The complete script can be found in the download section below.

ċ
Le Tuan Anh,
May 17, 2016, 3:20 AM
ċ
mecab-0.996.tar.gz
(1366k)
Le Tuan Anh,
May 11, 2016, 12:45 AM
ċ
mecab-all.tar.gz
(13370k)
Le Tuan Anh,
May 17, 2016, 3:20 AM
ċ
mecab-ipadic-2.7.0-20070801.tar.gz
(11922k)
Le Tuan Anh,
May 11, 2016, 12:46 AM
ċ
mecab-python-0.996.tar.gz
(40k)
Le Tuan Anh,
May 11, 2016, 12:46 AM
Comments