프로그래밍/Php

파이썬 한국어 KoNlPy 설치 및 사용법 (한글형태소 분석기)

소행성왕자 2018. 9. 10. 14:25

파이썬 한국어 KoNlPy 설치 및 사용법 (한글형태소 분석기)




Centos7 konlpy install


: Install dependencies


1
2
3
4
5
yum install gcc-c++
yum install java-1.7.0-openjdk-devel
yum install python-devel
 
pip3.6 install JPype1-py3
cs




: Install KoNLPy


1
pip3.6 install  konlpy  
cs

  



1
2
3
4
5
6
7
8
vi konlpy_test.py
from konlpy.tag import Komoran
komoran = Komoran()
print(komoran.morphs(u'우왕 코모란도 오픈소스가 되었어요'))
print(komoran.nouns(u'오픈소스에 관심 많은 멋진 개발자님들!'))
print(komoran.pos(u'한글형태소분석기 코모란 테스트 중 입니다.'))
 
python3.6 konlpy_test.py 
cs




: Centos7 php7 에서 사용가능하도록 설치


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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.1.1-20180720.tar.gz
tar zxfv mecab-ko-dic-2.1.1-20180720.tar.gz
cd mecab-ko-dic-2.1.1-20180720/
./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

php -m | grep mecab 

vi /etc/php.ini 추가
extension = mecab.so
 
systemctl restart httpd.service
cs



1
2
3
4
5
<?php
 
$mecab = new MeCab\Tagger();
 
echo $mecab->parse('장난아니게 빠르게 나오는데요. 명사를 찾아야되는데요');
cs