package main
import (
"fmt"
"github.com/go-ego/gse"
"github.com/go-ego/gse/hmm/pos"
)
var (
text = "Hello world, Helloworld. Winter is coming! 你好世界. 你好"
new = gse.New("zh,testdata/test_dict3.txt", "alpha")
seg gse.Segmenter
posSeg pos.Segmenter
)
func cut() {
hmm := new.Cut(text, true)
fmt.Println("cut use hmm: ", hmm)
hmm = new.CutSearch(text, true)
fmt.Println("cut search use hmm: ", hmm)
hmm = new.CutAll(text)
fmt.Println("cut all: ", hmm)
}
func main() {
cut()
//segCut()
}
func posAndTrim(cut []string) {
//cut = seg.Trim(cut)
//fmt.Println("cut all: ", cut)
//
//pos.WithGse(seg)
//po := posSeg.Cut(text, true)
//fmt.Println("pos: ", po)
//
//po = posSeg.TrimWithPos(po, "zg")
//fmt.Println("trim pos: ", po)
}
func cutPos() {
fmt.Println(seg.String(text, true))
fmt.Println(seg.Slice(text, true))
po := seg.Pos(text, true)
fmt.Println("pos: ", po)
po = seg.TrimPos(po)
fmt.Println("trim pos: ", po)
}
func segCut() {
// Loading the default dictionary
seg.LoadDict()
// Load the dictionary
// seg.LoadDict("your gopath"+"/src/github.com/go-ego/gse/data/dict/dictionary.txt")
// Text Segmentation
tb := []byte(text)
fmt.Println(seg.String(text, 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))
}
go分词库
于 2021-10-11 10:41:57 首次发布