Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Jiebago 的性能优化版, 支持从 io.Reader 加载字典

License

NotificationsYou must be signed in to change notification settings

fumiama/jieba

Repository files navigation

GoDoc

结巴分词 是由@fxsjy 使用 Python 编写的中文分词组件,本仓库是结巴分词的 Golang 语言实现,修改于jiebago,大幅优化了速度与性能,增加了从io.Reader加载字典等功能。

使用

go get -d github.com/fumiama/jieba

示例

package mainimport (        "fmt"        "github.com/fumiama/jieba")func main() {seg, err := LoadDictionaryAt("dict.txt")if err != nil {panic(err)}fmt.Print("【全模式】:")fmt.Println(seg.CutAll("我来到北京清华大学"))fmt.Print("【精确模式】:")fmt.Println(seg.Cut("我来到北京清华大学", false))fmt.Print("【新词识别】:")fmt.Println(seg.Cut("他来到了网易杭研大厦", true))fmt.Print("【搜索引擎模式】:")fmt.Println(seg.CutForSearch("小明硕士毕业于中国科学院计算所,后在日本京都大学深造", true))}

输出结果:

【全模式】:[我 来到 北京 清华 清华大学 华大 大学]【精确模式】:[我 来到 北京 清华大学]【新词识别】:[他 来到 了 网易 杭研 大厦]【搜索引擎模式】:[小明 硕士 毕业 于 中国 科学 学院 科学院 中国科学院 计算 计算所 , 后 在 日本 京都 大学 日本京都大学 深造]

更多信息请参考文档

分词速度

goos:darwingoarch:amd64pkg:github.com/fumiama/jiebacpu:Intel(R)Core(TM)i5-8265UCPU @1.60GHzBenchmarkCutNoHMM-85010122889ns/op4.67MB/s24492B/op148allocs/opBenchmarkCut-84747325152ns/op4.25MB/s31310B/op185allocs/opBenchmarkCutAll-88176014286ns/op7.49MB/s22746B/op75allocs/opBenchmarkCutForSearchNoHMM-84900924371ns/op4.39MB/s26421B/op157allocs/opBenchmarkCutForSearch-84464326597ns/op4.02MB/s33224B/op194allocs/opPASSokgithub.com/fumiama/jieba8.769s

对比原仓库速度

goos:darwingoarch:amd64pkg:cpu:Intel(R)Core(TM)i5-8265UCPU @1.60GHzBenchmarkCutNoHMM-82123756105ns/op1.91MB/s11514B/op133allocs/opBenchmarkCut-81760468463ns/op1.56MB/s13480B/op200allocs/opBenchmarkCutAll-82462049472ns/op2.16MB/s7724B/op116allocs/opBenchmarkCutForSearchNoHMM-81780366158ns/op1.62MB/s11766B/op143allocs/opBenchmarkCutForSearch-81489579056ns/op1.35MB/s13772B/op210allocs/opPASSok11.911s

[8]ページ先頭

©2009-2025 Movatter.jp