形態分析(PHP)の設置と使用

形態分析(PHP)の設置と使用

インストール環境:CENTOS7 BASIC、PHP7

yum install gcc-c++ java-1.7.0-openjdk-devel python-devel zlib-devel openssl openssl-devel git -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
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

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

PHPでは、以下に示すように使用できます。

<?
 $ mecab = new mecabtagger();
 echo $ mecab-> parse( 'こんにちは?お会いできてうれしい');
 ?>

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

Leave a Reply

이메일 주소는 공개되지 않습니다. (* 질문, 건의사항 등은 "질문게시판"을 이용해주세요)