Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
"結巴"中文分詞:做最好的 PHP 中文分詞、中文斷詞組件。 / "Jieba" (Chinese for "to stutter") Chinese text segmentation: built to be the best PHP Chinese word segmentation module.
| Date | Stars |
|---|---|
| 2026-07-24 | 1379 |
| 2026-07-25 | 1378 |
| 2026-07-28 | 1378 |
| 2026-07-30 | 1378 |
| 2026-08-17 | 1377 |
| 2026-08-26 | 1376 |
| 2026-08-28 | 1377 |
| 2026-09-02 | 1378 |
| 2026-09-20 | 1379 |
Today
+1 stars today
This week
+1 stars this week
This month
+2 stars this month
Momentum
0.0
growth rate 0.07%/day
# [jieba-php](http://www.fukuball.com/jieba-php/)
[](http://www.fukuball.com)
[](https://codecov.io/gh/fukuball/jieba-php)
"結巴"中文分詞:做最好的 PHP 中文分詞、中文斷詞組件,原始版本翻譯自 [fxsjy/jieba](https://github.com/fxsjy/jieba),目前已經為一個獨立分支,請有興趣的開發者一起加入開發!若想使用 Python 版本請前往 [fxsjy/jieba](https://github.com/fxsjy/jieba)
現在已經可以支援繁體中文!只要將字典切換為 big 模式即可!
中文斷詞目前使用 LLM 大語言模型會得到更好的斷詞結果,但如果要快速、便宜,這個套件仍然有其用處。
"Jieba" (Chinese for "to stutter") Chinese text segmentation: built to be the best PHP Chinese word segmentation module.
_Scroll down for English documentation._
# 線上展示
- 網站原始碼:[https://github.com/fukuball/jieba-php.fukuball.com](https://github.com/fukuball/jieba-php.fukuball.com)
# Feature
- 支持三種分詞模式:
- 1)默認精確模式,試圖將句子最精確地切開,適合文本分析;
- 2)全模式,把句子中所有的可以成詞的詞語都掃描出來,但是不能解決歧義。(需要充足的字典)
- 3. 搜尋引擎模式,在精確模式的基礎上,對長詞再次切分,提高召回率,適合用於搜尋引擎分詞。
- 支持繁體斷詞
- 支持自定義詞典
- 支持多語言 CJK 文本處理(中文、日文、韓文)
- 支持 TF-IDF 分詞整合和詞性標註
- 支持記憶體管理和快取優化
- 支持自定義詞性標籤
# Usage
- 自動安裝:使用 composer 安裝後,透過 autoload 引用
代碼示例
```php
composer require fukuball/jieba-php
```
代碼示例
```php
require_once "/path/to/your/vendor/autoload.php";
```
- 手動安裝:將 jieba-php 放置適當目錄後,透過 require_once 引用
代碼示例
```php
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";
```
# Algorithm
- 基於 Trie 樹結構實現高效的詞圖掃描,生成句子中漢字所有可能成詞情況所構成的有向無環圖(DAG)
- 採用了動態規劃查找最大概率路徑, 找出基於詞頻的最大切分組合
- 對於未登錄詞,採用了基於漢字成詞能力的 HMM 模型,使用了 Viterbi 算法
- BEMS 的解釋 [https://github.com/fxsjy/jieba/issues/7](https://github.com/fxsjy/jieba/issues/7)
# Interface
- 組件只提供 jieba.cut 方法用於分詞
- cut 方法接受兩個輸入參數: 1) 第一個參數為需要分詞的字符串 2)cut_all 參數用來控制分詞模式
- 待分詞的字符串可以是 utf-8 字符串
- jieba.cut 返回的結構是一個可迭代的 array
# 功能 1):分词
- `cut` 方法接受想個輸入參數: 1) 第一個參數為需要分詞的字符串 2)cut_all 參數用來控制分詞模式
- `cutForSearch` 方法接受一個參數:需要分詞的字符串,該方法適合用於搜索引擎構建倒排索引的分詞,粒度比較細
- 注意:待分詞的字符串是 utf-8 字符串
- `cut` 以及 `cutForSearch` 返回的結構是一個可迭代的 array
代碼示例 (Tutorial)
```php
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;
Jieba::init();
Finalseg::init();
$seg_list = Jieba::cut("怜香惜玉也得要看对象啊!");
var_dump($seg_list);
$seg_list = Jieba::cut("我来到北京清华大学", true);
var_dump($seg_list); #全模式
$seg_list = Jieba::cut("我来到北京清华大学", false);
var_dump($seg_list); #默認精確模式
$seg_list = Jieba::cut("他来到了网易杭研大厦");
var_dump($seg_list);
$seg_list = Jieba::cutForSearch("小明硕士毕业于中国科学院计算所,后在日本京都大学深造"); #搜索引擎模式
var_dump($seg_list);
```
Output:
```php
array(7) {
[0]=>
string(12) "怜香惜玉"
[1]=>
string(3) "也"
[2]=>
string(3) "得"
[3]=>
string(3) "要"
[4]=>
string(3) "看"
[5]=>
string(6) "对象"
[6]=>
string(3) "啊"
}
Full Mode:
array(15) {
[0]=>
string(3) "我"
[1]=>
string(3) "来"
[2]=>
string(6) "来到"
[3]=>
string(3) "到"
[4]=>
string(3) "北"
[5]=>
string(6) "北京"
[6]=>
string(3) "京"
[7]=>
string(3) "清"
[8]=>
string(6) "清华"
[9]=>
string(12) "清华大学"
[10]=>
string(3) "华"
[11]=>
string(6) "华大"
[12]=>
string(3) "大"
[13]=>
string(6) "大学"
[14]=>
string(3) "学"
}
Default Mode:
array(4) {
[0]=>
string(3) "我"
[1]=>
string(6) "来到"
[2]=>
string(6) "北京"
[3]=>
string(12) "清华大学"
}
array(6) {
[0]=>
string(3) "他"
[1]=>
string(6) "来到"
[2]=>
string(3) "了"
[3]=>
string(6) "网易"
[4]=>
string(6) "杭研"
[5]=>
string(6) "大厦"
}
(此處,“杭研“並沒有在詞典中,但是也被 Viterbi 算法識別出來了)
Search Engine Mode:
array(18) {
[0]=>
string(6) "小明"
[1]=>
string(6) "硕士"
[2]=>
string(6) "毕业"
[3]=>
string(3) "于"
[4]=>
string(6) "中国"
[5]=>
string(6)Excerpt of 33,399 characters
Read on GitHub220
10
9
5
5
4
3
3
2
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:44919b964f6bfb1f, topic:nlp, topic:natural-language-processing