使用cjieba(結巴分詞庫)實現php擴展中文分詞-支持php5, php7

做者git地址:https://github.com/jonnywang/...php

編譯安裝git

git clone https://github.com/jonnywang/jz.git  (php7)
git clone https://github.com/jonnywang/phpjieba.git (php5)
cd jz/cjieba
make
cd ..
phpize
./configure --enable-jieba
make
make install
配置php.ini
extension=jz.so 
jz.enable_jieba=1
jz.dict_path=/Users/xingqiba/data/softs/jz/cjieba/dict    #指向jz庫dict目錄

使用github

<?php

$result = jz_jieba('小明碩士畢業於中國科學院計算所,後在日本京都大學深造');
print_r($result);

$result = jz_jieba('小明碩士畢業於中國科學院計算所,後在日本京都大學深造', true, 6);
print_r($result);

效果php7

Array
(
    [0] => 小明
    [1] => 碩士
    [2] => 畢業
    [3] => 於
    [4] => 中國
    [5] => 科學
    [6] => 學院
    [7] => 科學院
    [8] => 中國科學院
    [9] => 計算
    [10] => 計算所
    [11] => ,
    [12] => 後
    [13] => 在
    [14] => 日本
    [15] => 京都
    [16] => 大學
    [17] => 日本京都大學
    [18] => 深造
)
Array
(
    [0] => 計算所
    [1] => 小明
    [2] => 京都大學
    [3] => 深造
    [4] => 碩士
    [5] => 中國科學院
)

歡迎您加入咱們的專屬QQ討論羣組① 233415606 ② 233415756code

相關文章
相關標籤/搜索