Mecabをソースからインストールする

UTF-8専用にして軽いのを作るぞ。

ダウンロード

http://mecab.sourceforge.jp/src/にアクセス。下記の3つをダウンロード。
辞書は11.5MBと少々重たい。

解凍する

# tar -zxvf mecab-0.93.tar.gz
# tar -zxvf mecab-ipadic-2.7.0-20060707.tar.gz
# tar -zxvf mecab-perl-0.93.tar.gz

ipadicの解凍時に、所有者の書き換えができない、とエラーがでるがスルー。

Mecabのインストール

# cd /data/mecab-0.93

Cコンパイラーが見つからないとエラー。

# ./configure --enable-utf8-only
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets $(MAKE)... yes
checking for working aclocal-1.4... missing
checking for working autoconf... missing
checking for working automake-1.4... missing
checking for working autoheader... missing
checking for working makeinfo... missing
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

いろいろとインストール。

# apt-get install autoconf automake gcc

autoheaderとaclocalも入る。makeinfoはなかった。
しかしこれでもエラーはなくならず。
Cコンパイラの出力ファイル名に原因があるとのこと。
configure.logを見ると、下記のような記述。

/usr/bin/ld: crt1.o: No such file: No such file or directory

libc6-devを入れるといいらしい。

# apt-get install libc6-dev

コンパイルは走ったが途中でエラー。
今度は,g++がない、とのこと。

# apt-get install g++

インストール後、ようやく成功。

# ./configure --enable-utf8-only
# make
# make install

mecab-ipadicのインストール

# cd /data/mecab-ipadic-2.7.0-20060707
# ./configure --with-charset=utf8
# make
# make install

あっさり終了。
ちょっと動作確認。

# echo "この橋渡るべからず" | mecab
この 連体詞,*,*,*,*,*,この,コノ,コノ
橋 名詞,一般,*,*,*,*,橋,ハシ,ハシ
渡る 動詞,自立,*,*,五段・ラ行,基本形,渡る,ワタル,ワタル
べから 助動詞,*,*,*,文語・ベシ,未然形,べし,ベカラ,ベカラ
ず 助動詞,*,*,*,特殊・ヌ,連用ニ接続,ぬ,ズ,ズ
EOS

mecab-perlのインストール

# cd /data/mecab-perl-0.93
# perl Makefile.PL
# make
# make install

動作確認

  • test.pl

use utf8;
use MeCab;
$m = new MeCab::Tagger("") || die $!;
print $m->parse("この橋渡るべからず");

これは動く。が、

$m = new MeCab::Tagger("-Oxml") || die $!;

だと、

# perl test.pl
RuntimeError tagger.cpp(146) [writer_.open(param)] writer.cpp(62)
[! std::string(param.getProfileString(nfk.c_str())).empty()] unknown format type [xml]
...propagated at est.pl line 3.

XML形式なんて知らない、と言われてしまう。
これがなかったら生きていけない(大げさ

XML形式の出力フォーマットを入手する

0.80にはあるのに,最新版にはないとは。
もう一度apt-getでmecabとipadicを入れる。

# cat /usr/share/mecab/dic/ipadic/dicrc | nkf -w | less

表示。なお、0.93とはipadicの場所が異なる。

; XML
bos-format-xml = \n
node-format-xml = \s\s%m\n
eos-format-xml =
\n

これを,下記に追記。

/usr/local/lib/mecab/dic/ipadic/dicrc

完了

そして実行。

# perl test.pl

この

渡る
べから

長かった。