Watch 40 Star 75

vz / gseGoApache-2.0

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
Go 语言高效分词, 支持英文、中文、日文等 词典用双数组trie(Double-Array Trie)实现, 分词器算法为基于词频的最短路径加动态规划。 支持普通和搜索引擎两种分词模式,支持用户词典、词性标注,可运行JSON RPC服务。 spread retract

Clone or download


Go efficient text segmentation; support english, chinese, japanese and other.

CircleCI Status codecov Build Status Go Report Card GoDoc GitHub release Join the chat at


Dictionary with double array trie (Double-Array Trie) to achieve, Sender algorithm is the shortest path based on word frequency plus dynamic programming, and DAG and HMM algorithm word segmentation.

Support common, search engine, full mode, precise mode and HMM mode multiple word segmentation modes, support user dictionary, POS tagging, run JSON RPC service.

Support HMM cut text use Viterbi algorithm.

Text Segmentation speed single thread 9.2MB/s,goroutines concurrent 26.8MB/s. HMM text segmentation single thread 3.2MB/s. (2core 4threads Macbook Pro).

Install / update

go get -u


go get -u

re gse

To create a new gse application

$ re gse my-gse

re run

To run the application we just created, you can navigate to the application folder and execute:

$ cd my-gse && re run


package main

import (


var (
	text = "你好世界, Hello world."

	seg gse.Segmenter

func cut() {
	hmm := seg.Cut(text, true)
	fmt.Println("hmm cut: ", hmm)

	hmm = seg.CutSearch(text, true)
	fmt.Println("hmm cut: ", hmm)

	hmm = seg.CutAll(text)
	fmt.Println("cut all: ", hmm)

func segCut() {
	// Text Segmentation
	tb := []byte(text)
	fmt.Println(seg.String(tb, true))

	segments := seg.Segment(tb)

	// Handle word segmentation results
	// Support for normal mode and search mode two participle,
	// see the comments in the code ToString function.
	// The search mode is mainly used to provide search engines
	// with as many keywords as possible
	fmt.Println(gse.ToString(segments, true))

func main() {
	// Loading the default dictionary
	// Load the dictionary
	// seg.LoadDict("your gopath"+"/src/")



Look at an custom dictionary example

package main

import (


func main() {
	var seg gse.Segmenter

	text1 := []byte("你好世界, Hello world")
	fmt.Println(seg.String(text1, true))

	segments := seg.Segment(text1)

Look at an Chinese example

Look at an Japanese example



Gse is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), thanks for sego and jieba.

Comments ( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025