Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huichen/sego
Go中文分词
https://github.com/huichen/sego
Last synced: about 4 hours ago
JSON representation
Go中文分词
- Host: GitHub
- URL: https://github.com/huichen/sego
- Owner: huichen
- License: other
- Created: 2013-07-19T23:02:06.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-11-16T02:13:58.000Z (about 2 years ago)
- Last Synced: 2024-11-29T02:05:55.212Z (14 days ago)
- Language: Go
- Homepage:
- Size: 3.5 MB
- Stars: 1,813
- Watchers: 109
- Forks: 354
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
- go-awesome - sego - Go to Chinese word segmentation (Open source library / Search Recommendations)
README
sego
====Go中文分词
词典用双数组trie(Double-Array Trie)实现,
分词器算法为基于词频的最短路径加动态规划。支持普通和搜索引擎两种分词模式,支持用户词典、词性标注,可运行JSON RPC服务。
分词速度单线程9MB/s,goroutines并发42MB/s(8核Macbook Pro)。
# 安装/更新
```
go get -u github.com/huichen/sego
```# 使用
```go
package mainimport (
"fmt"
"github.com/huichen/sego"
)func main() {
// 载入词典
var segmenter sego.Segmenter
segmenter.LoadDictionary("github.com/huichen/sego/data/dictionary.txt")// 分词
text := []byte("中华人民共和国中央人民政府")
segments := segmenter.Segment(text)
// 处理分词结果
// 支持普通模式和搜索模式两种分词,见代码中SegmentsToString函数的注释。
fmt.Println(sego.SegmentsToString(segments, false))
}
```