jiebai中文分词

文档

https://github.com/fxsjy/jieba
https://github.com/fukuball/jieba-php

php使用jiebai

#安装
composer require fukuball/jieba-php:dev-master

如果提示
Uncaught ErrorException: preg_match(): JIT compilation failed: no more memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:
修改php.ini pcre.jit=0

ini_set('memory_limit', '1024M');

require_once "/path/to/your/vendor/multi-array/MultiArray.php";
require_once "/path/to/your/vendor/multi-array/Factory/MultiArrayFactory.php";
require_once "/path/to/your/class/Jieba.php";
require_once "/path/to/your/class/Finalseg.php";
use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Finalseg;
use Fukuball\Jieba\JiebaAnalyse
Jieba::init();
Finalseg::init();

$seg_list = Jieba::cut("怜香惜玉也得要看对象啊!");
#分词
var_dump($seg_list);
array(7) {
  [0]=>
  string(12) "怜香惜玉"
  [1]=>
  string(3) "也"
  [2]=>
  string(3) "得"
  [3]=>
  string(3) "要"
  [4]=>
  string(3) "看"
  [5]=>
  string(6) "对象"
  [6]=>
  string(3) "啊"
}
#关键词提取
$seg_list = JiebaAnalyse::extractTags("怜香惜玉也得要看对象啊!");
var_dump($seg_list);
["怜香惜玉","对象"]

可以转载,但必须说明出处

发表评论