1. 安装:
    composer require fukuball/jieba-php
  2. 使用:
    <?php
    // 1. 引入包
    require_once "vendor/autoload.php";
    // 2. 使用命名空间
    use Fukuball\Jieba\Jieba;
    use Fukuball\Jieba\Finalseg;
    // 3. 设置内存大小
    ini_set('memory_limit', '1024M');
    // 4. 初始化对象
    Jieba::init();
    Finalseg::init();
    // 5. 使用分词
    $seg_list = Jieba::cutForSearch("小明硕士毕业于中国科学院计算所,后在日本京都大学深造Xiao Ming graduated from the Institute of Computing, Chinese Academy of Sciences, and later studied at Kyoto University, Japan.");
    // 6. 输出
    var_dump($seg_list);
  3. 输出:
    array(39) {
    [0]=>
    string(3) "小"
    [1]=>
    string(3) "明"
    [2]=>
    string(6) "硕士"
    [3]=>
    string(6) "毕业"
    [4]=>
    string(3) "于"
    [5]=>
    string(6) "中国"
    [6]=>
    string(6) "科学"
    [7]=>
    string(6) "学院"
    [8]=>
    string(9) "科学院"
    [9]=>
    string(15) "中国科学院"
    [10]=>
    string(6) "计算"
    [11]=>
    string(9) "计算所"
    [12]=>
    string(3) ","
    [13]=>
    string(3) "后"
    [14]=>
    string(3) "在"
    [15]=>
    string(6) "日本"
    [16]=>
    string(6) "京都"
    [17]=>
    string(6) "大学"
    [18]=>
    string(18) "日本京都大学"
    [19]=>
    string(6) "深造"
    [20]=>
    string(4) "Xiao"
    [21]=>
    string(4) "Ming"
    [22]=>
    string(9) "graduated"
    [23]=>
    string(4) "from"
    [24]=>
    string(3) "the"
    [25]=>
    string(9) "Institute"
    [26]=>
    string(2) "of"
    [27]=>
    string(9) "Computing"
    [28]=>
    string(7) "Chinese"
    [29]=>
    string(7) "Academy"
    [30]=>
    string(2) "of"
    [31]=>
    string(8) "Sciences"
    [32]=>
    string(3) "and"
    [33]=>
    string(5) "later"
    [34]=>
    string(7) "studied"
    [35]=>
    string(2) "at"
    [36]=>
    string(5) "Kyoto"
    [37]=>
    string(10) "University"
    [38]=>
    string(6) "Japan."
    }
文档更新时间: 2020-10-23 09:26   作者:lee