go-common/vendor/github.com/go-ego/gse
2019-04-22 18:49:16 +08:00
..
BUILD.bazel Create & Init Project... 2019-04-22 18:49:16 +08:00
circle.yml Create & Init Project... 2019-04-22 18:49:16 +08:00
CONTRIBUTING.md Create & Init Project... 2019-04-22 18:49:16 +08:00
dictionary.go Create & Init Project... 2019-04-22 18:49:16 +08:00
Gopkg.lock Create & Init Project... 2019-04-22 18:49:16 +08:00
Gopkg.toml Create & Init Project... 2019-04-22 18:49:16 +08:00
LICENSE Create & Init Project... 2019-04-22 18:49:16 +08:00
README_zh.md Create & Init Project... 2019-04-22 18:49:16 +08:00
README.md Create & Init Project... 2019-04-22 18:49:16 +08:00
seg.go Create & Init Project... 2019-04-22 18:49:16 +08:00
segmenter.go Create & Init Project... 2019-04-22 18:49:16 +08:00
test_utils.go Create & Init Project... 2019-04-22 18:49:16 +08:00
token.go Create & Init Project... 2019-04-22 18:49:16 +08:00
utils.go Create & Init Project... 2019-04-22 18:49:16 +08:00

gse

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

CircleCI Status codecov Build Status Go Report Card GoDoc Release Join the chat at https://gitter.im/go-ego/ego

简体中文

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

Support common and search engine two participle mode, support user dictionary, POS tagging, run JSON RPC service.

Text Segmentation speed single thread 9MB/sgoroutines concurrent 42MB/s (8 nuclear Macbook Pro).

Install / update

go get -u github.com/go-ego/gse

Build-tools

go get -u github.com/go-ego/re 

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

Use

package main

import (
	"fmt"

	"github.com/go-ego/gse"
)

func main() {
	// Load the dictionary
	var seg gse.Segmenter
	// Loading the default dictionary
	seg.LoadDict()
	// seg.LoadDict("your gopath"+"/src/github.com/go-ego/gse/data/dict/dictionary.txt")

	// Text Segmentation
	text := []byte("你好世界, Hello world.")
	fmt.Println(segmenter.String(text, true)) 

	segments := segmenter.Segment(text)
  
	// 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)) 
}

Look at an custom dictionary example

package main

import (
	"fmt"

	"github.com/go-ego/gse"
)

func main() {
	var seg gse.Segmenter
	seg.LoadDict("zh,testdata/test_dict.txt,testdata/test_dict1.txt")

	text1 := []byte("你好世界, Hello world")

	segments := seg.Segment(text1)
	fmt.Println(gse.ToString(segments))
}

Look at an Chinese example

Look at an Japanese example

License

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