1. centos7 기본설정 및 apm 설치
yum install gcc-c++
2. mecab 다운로드/설치
cd /usr/local/src/
https://bitbucket.org/eunjeon/mecab-ko/downloads 최신버전 다운로드
wget https://bitbucket.org/eunjeon/mecab-ko/downloads/mecab-0.996-ko-0.9.2.tar.gz
tar zxvf mecab-0.996-ko-0.9.2.tar.gz
cd mecab-0.996-ko-0.9.2
mkdir /usr/local/mecab
./configure --prefix=/usr/local/mecab
make
make install
3. 한국어 사전 다운로드/설치
cd /usr/local/src/
https://bitbucket.org/eunjeon/mecab-ko-dic/downloads 최신버전 다운로드
wget https://bitbucket.org/eunjeon/mecab-ko-dic/downloads/mecab-ko-dic-2.1.1-20180720.tar.gz
tar zxvf mecab-ko-dic-2.1.1-20180720.tar.gz
cd mecab-ko-dic-2.1.1-20180720
./configure --prefix=/usr/local/mecab/dic --with-mecab-config=/usr/local/mecab/bin/mecab-config --with-dicdir=/usr/local/mecab/dic --libexecdir=/usr/local/mecab/libexec/mecab
make
make install
4. mecab 정상작동 확인
cd /usr/local/medib/bin
./mecab -d /usr/local/mecab/dic
아버지가방에들어가신다
5. php-mecab 다운로드/설치
cd /usr/local/src/
wget https://github.com/rsky/php-mecab/archive/master.zip
unzip master.zip
cd php-mecab-master/mecab/
phpize
./configure --with-php-config=/usr/bin/php-config --with-mecab=/usr/local/mecab/bin/mecab-config
make
== /usr/local/src/php-mecab-master/mecab/mecab5.c:452: error: ‘PHP_FE_END’ undeclared here (not in a function) 오류 발생시 ==
해당 파일 적당한 위치애 아래 3줄 추가 후 make
#ifndef ZEND_FE_END
#define ZEND_FE_END {NULL, NULL, NULL, 0, 0}
#endif
====================================================
make test
make install
ll /usr/lib64/php/modules/ 폴더에 mecab.so 파일 있는지 확인
echo "extension=mecab.so" > /etc/php.d/mecab.ini
6. apache 재시작
apachectl restart
7. 샘플소스
---------------------------------------------------------
<?php
//$mecab = new \MeCab\Tagger(['-d', '/usr/local/mecab/dic']); // php5.4+
$mecab_dic_conf = array('-d', '/usr/local/mecab/dic'); // php5.3
$mecab = new \MeCab\Tagger($mecab_dic_conf); // php5.3
$lines = explode("\n", $parse_data);
$data = array();
for($i=0;$i<sizeof($lines);$i++){
$row = explode("\t",$lines[$i]);
if(in_array(substr($row[1],0,3), array('NNP','NNG'))) {
$data[] =$row[0];
}
}
$fin = array_count_values($data);
asort($fin);
print_r($fin);
---------------------------------------------------------
8. 사용자 단어 추가 방법
cd /usr/local/src/mecab-ko-dic-2.1.1-20180720
./user-dic 폴더에 csv 파일을 만들어서 내용 추가
./tools/add-userdic.sh
make clean
make
make install
# 아래 오류 발생시
----------------------------------------------------------
/usr/local/src/mecab-ko-dic-2.1.1-20180720/tools/add-userdic.sh: line 25: /usr/local/libexec/mecab/mecab-dict-index: No such file or directory
---------------------------------------------------------
/usr/local/src/mecab-ko-dic-2.1.1-20180720/tools/add-userdic.sh 파일을 열어서 MECAB_EXEC_PATH 변경
---------------------------------------------------------
/usr/local/libexec/mecab => /usr/local/mecab/libexec/mecab
---------------------------------------------------------
# 참고
https://konlpy-ko.readthedocs.io/ko/v0.4.3/morph/
https://github.com/rsky/php-mecab
https://github.com/nihongodera/php-mecab-documentation
https://github.com/Wandu/Mecab
http://eunjeon.blogspot.com/
https://docs.google.com/spreadsheets/d/1-9blXKjtjeKZqsf4NzHeYJCrr49-nXeRF6D80udfcwY/edit#gid=0
https://kugancity.tistory.com/category/프로그래밍/자연어처리?page=3
'기타 개발관련' 카테고리의 다른 글
IIS + PHP 에서 오라클 연동 설치 (0) | 2017.10.29 |
---|---|
PHP + MSSQL 연결 (0) | 2017.02.15 |
IIS7 에서 와일드카드 SSL 443 포트에 적용하기 - Secure Binding (0) | 2016.04.01 |
telnet 에서 smtp 테스트 메일발송 (0) | 2016.02.05 |
가장 저렴한 SSL인증서. comodo positive ssl 인증서 (0) | 2016.01.27 |