"结巴"中文分词的Golang版本
GoJieba是"结巴"中文分词的Golang语言版本。
deps/ 目录中,无需任何 git submodule 初始化,go get / go mod vendor 开箱即用。go get github.com/yanyiwu/gojieba
gojieba 依赖 cgo 和 C++。如果是交叉编译,请确保目标平台的 C/C++ 交叉工具链已经安装,并显式开启 cgo;CGO_ENABLED=0 的纯 Go 交叉编译方式不适用于这个库。
gojieba requires cgo and C++; cross-compilation needs CGO_ENABLED=1 plus a target C/C++ toolchain via CC/CXX.
例如,交叉编译到 Linux amd64 时,需要类似下面这样提供目标平台工具链:
CGO_ENABLED=1 \
CC=x86_64-linux-gnu-gcc \
CXX=x86_64-linux-gnu-g++ \
GOOS=linux \
GOARCH=amd64 \
go build
分词示例
…
我来到北京清华大学
全模式: 我/来到/北京/清华/清华大学/华大/大学
我来到北京清华大学
精确模式: 我/来到/北京/清华大学
比特币
精确模式: 比特/币
比特币
添加词典后,精确模式: 比特币
他来到了网易杭研大厦
新词识别: 他/来到/了/网易/杭研/大厦
小明硕士毕业于中国科学院计算所,后在日本京都大学深造
搜索引擎模式: 小明/硕士/毕业/于/中国/科学/学院/科学院/中国科学院/计算/计算所/,/后/在/日本/京都/大学/日本京都大学/深造
长春市长春药店
词性标注: 长春市/ns,长春/ns,药店/n
区块链
词性标注: 区块链/nz
长江大桥
搜索引擎模式: 长江/大桥/长江大桥
长江大桥
Tokenize: [{长江 0 6} {大桥 6 12} {长江大桥 0 12}]
See Details in gojieba-demo See example in jieba_test, extractor_test
Unittest
go test ./...
Benchmark
go test -bench "Jieba" -test.benchtime 10s
go test -bench "Extractor" -test.benchtime 10s
This project exists thanks to all the people who contribute.
No open issues yet, or sync has not completed.