Installing and using stemming (PHP)

Installation environment: Centos7 default, PHP7

yum install wget curl openssl-devel git -y

yum install gcc-c++ java-1.7.0-openjdk-devel python-devel -y

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
tar xf Python-3.*
cd Python-3.*
./configure
make # Build
make altinstall

pip3.6 install JPype1-py3
pip3.6 install konlpy

cd ..
wget https://bitbucket.org/eunjeon/mecab-ko/downloads/mecab-0.996-ko-0.9.2.tar.gz
tar zxfv mecab-0.996-ko-0.9.2.tar.gz
cd mecab-0.996-ko-0.9.2
./configure
make
make install

cd ..
wget https://bitbucket.org/eunjeon/mecab-ko-dic/downloads/mecab-ko-dic-2.0.1-20150920.tar.gz
tar zxfv mecab-ko-dic-2.0.1-20150920.tar.gz
cd mecab-ko-dic-2.0.1-20150920
./autogen.sh
./configure
make
make install

cd /usr/local/src/
git clone https://github.com/rsky/php-mecab.git
cd /usr/local/src/php-mecab/mecab
phpize
./configure --with-php-config=/usr/bin/php-config --with-mecab=/usr/local/bin/mecab-config
make
make test
make install

cp /usr/local/src/php-mecab/mecab/modules/mecab.so /usr/lib64/php/modules/mecab.so

echo "extension = mecab.so" > /etc/php.d/mecab.ini
systemctl restart httpd.service

In PHP, you can do it like this:

<?

$mecab = new MeCabTagger();

echo $mecab->parse('안녕하세요? 반갑습니다.');

?>

Reference
http://qiita.com/yudaifuijta0121/items/1787d70b9cfca3e43d12
http://eunjeon.blogspot.kr/
https://bitbucket.org/eunjeon/mecab-ko-dic
https://github.com/rsky/php-mecab

arrow