もはや10年位前のインストール方法ですが…。
MeCabを動かすまで
MeCabをインストール
http://taku910.github.io/mecab/#download から、mecab-0.996.tar.gzをダウンロードして、自分のホームディレクトリの下にインストール。
$ ./configure --with-charset=utf8 --prefix=/Users/yourAccount/local
$ make
$ make install
/Users/yourAccount/local/binにパスを通す
export PATH=$HOME/local/bin:$PATH
.bash_profileに書いておけばOK
辞書のインストール
MeCabはソースからインストールしたのに、辞書はUniDicのバイナリを使うという…
https://osdn.jp/projects/unidic/releases/58338 から、unidic-mecab-2.1.2_bin.zipをダウンロードし、適当な場所に展開する。
.mecabrcの作成
cp ~/local/etc/mecabrc ~/.mecabrc
.mecabrc内のdicdirに、UniDic辞書を展開したパスを指定する
;
; Configuration file of MeCab
;
; $Id: mecabrc.in,v 1.3 2006/05/29 15:36:08 taku-ku Exp $;
;
dicdir = /Users/yourAccount/foo/bar/unidic-mecab-2.1.2_bin
; userdic = /home/foo/bar/user.dic
; output-format-type = wakati
; input-buffer-size = 8192
; node-format = %m\n
; bos-format = %S\n
; eos-format = EOS\n
MeCab試し
$ mecab -Owakati
MeCabとPerlバインディングをインストール
と入力すると、
MeCab と Perl バインディング を インストール
と、形態素ごとにスペースが入って出力されます。
Perlで形態素解析をするまで
Perlバインディングのインストール
MeCab本体と同じく、 http://taku910.github.io/mecab/#download の「perl/ruby/python/java バインディング」のダウンロードをクリックすると、Google driveにつながるので、mecab-perl-0.996.tar.gzをダウンロード。適当なディレクトリに展開。
$ perl Makefile.pl PREFIX=/Users/yourAccount/local
make
make install
使ってみる
use lib '/Users/yourAccount/local/lib/perl5/site_perl/5.18.2/darwin-thread-multi-2level';
use MeCab;
use strict;
my $m = new MeCab::Tagger ("-Owakati");
my $w = $m->parse ("分かち書きのテストです。");
print $w;
$ perl test.pl
分かち書き の テスト です 。
とりあえず動かせるけど…
homebrewを使うなど、もっといいインストール方法はあると思いますが、自分のやりやすい方法ということで、備忘録でした…。