Skip to content

Instantly share code, notes, and snippets.

@iCoolchar
Created March 6, 2017 07:19
Show Gist options
  • Save iCoolchar/6fc0e9c6913010077eb530dcd62f25bf to your computer and use it in GitHub Desktop.
Save iCoolchar/6fc0e9c6913010077eb530dcd62f25bf to your computer and use it in GitHub Desktop.
jieba example in go
func main() {
serv := bootstrap.Service(make(map[string]bool))
serv.DefaultInit()
//serv.EnableESRedis()
bootstrap.Init(serv)
var seg jiebago.Segmenter
seg.LoadDictionary("/Users/xiuchen/Projects/chitu/html/relevance_share/dict_jieba.txt")
print := func(ch <-chan string) {
for word := range ch {
fmt.Printf(" %s /", word)
}
fmt.Println()
}
fmt.Print("【全模式】:")
print(seg.CutAll("我来到北京清华大学"))
fmt.Print("【精确模式】:")
print(seg.Cut("我来到北京清华大学", false))
fmt.Print("【新词识别】:")
print(seg.Cut("他来到了网易杭研大厦", false))
// Output:
// 【全模式】: 我 / 来到 / 北京 / 清华 / 清华大学 / 华大 / 大学 /
// 【精确模式】: 我 / 来到 / 北京 / 清华大学 /
// 【新词识别】: 他 / 来到 / 了 / 网易 / 杭研 / 大厦 /
// 【搜索引擎模式】: 小明 / 硕士 / 毕业 / 于 / 中国 / 科学 / 学院 / 科学院 / 中国科学院 / 计算 / 计算所 / , / 后 / 在 / 日本 / 京都 / 大学 / 日本京都大学 / 深造 /
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment