형태소 분석 설치 및 사용(PHP)

형태소 분석 설치 및 사용(PHP)

설치환경 : Centos7 기본, 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

guest
0 Comments
Inline Feedbacks
View all comments