I had to do morphological analysis, so today I installed the morphological analysis engine mecab and made it available from php. Here’s the procedure. I got stuck especially with the php_mecab part.
During “make check”
===================
1 of 3 tests failed
===================
make[2]: *** [check-TESTS] Error 1
make[2]: Leaving directory `/usr/local/src/mecab-0.98/tests'
make[1]: *** [check-am] Error 2
make[1]: Leaving directory `/usr/local/src/mecab-0.98/tests'
make: *** [check-recursive] Error 1
I got such an error, but it seems to be okay to not worry about it.
cd /usr/local/src
wget http://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz
tar zxfv mecab-ipadic-2.7.0-20070801.tar.gz
cd mecab-ipadic-2.7.0-20070801
./configure --with-charset=utf8
make
make install
After installing up to this point, you can use the mecab command like this.
% mecab
高知市内でコーチしないで
高知 名詞,固有名詞,地域,一般,*,*,高知,コウチ,コーチ
市内 名詞,一般,*,*,*,*,市内,シナイ,シナイ
で 助詞,格助詞,一般,*,*,*,で,デ,デ
コーチ 名詞,一般,*,*,*,*,*
し 動詞,自立,*,*,サ変・スル,未然形,する,シ,シ
ない 助動詞,*,*,*,特殊・ナイ,連用デ接続,ない,ナイ,ナイ
で 助詞,接続助詞,*,*,*,*,で,デ,デ
EOS
I got an error during make in my environment. How to use MeCab Extension on Sakura Internet’s rental server
↑This page has a detailed explanation. If you directly edit mecab.c as described there, make will succeed.
After that, just use it from php. dl(‘mecab.so’) was rejected, so add it to php.ini
[mecab] extension="mecab.so"
like this and it’s OK.