From b66663fc6033686b3a8b20226ac0866ee3ef8c24 Mon Sep 17 00:00:00 2001 From: iceinto Date: Fri, 15 Dec 2017 16:58:03 +0800 Subject: [PATCH] =?UTF-8?q?<=E6=B7=BB=E5=8A=A0><=E6=A1=88=E4=BE=8B>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/gpy/main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ demo/gse/main.go | 28 ++++++++++++++++++++++++++++ demo/riot/main.go | 38 ++++++++++++++++++++++++++++++++++++++ demo/robotgo/main.go | 12 ++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 demo/gpy/main.go create mode 100644 demo/gse/main.go create mode 100644 demo/riot/main.go create mode 100644 demo/robotgo/main.go diff --git a/demo/gpy/main.go b/demo/gpy/main.go new file mode 100644 index 0000000..d1c6251 --- /dev/null +++ b/demo/gpy/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + + "github.com/go-ego/gpy" +) + +func main() { + hans := "中国人" + + // 默认 + a := gpy.NewArgs() + fmt.Println(gpy.Pinyin(hans, a)) + // [[zhong] [guo] [ren]] + + // 包含声调 + a.Style = gpy.Tone + fmt.Println(gpy.Pinyin(hans, a)) + // [[zhōng] [guó] [rén]] + + // 声调用数字表示 + a.Style = gpy.Tone2 + fmt.Println(gpy.Pinyin(hans, a)) + // [[zho1ng] [guo2] [re2n]] + + // 开启多音字模式 + a = gpy.NewArgs() + a.Heteronym = true + fmt.Println(gpy.Pinyin(hans, a)) + // [[zhong zhong] [guo] [ren]] + a.Style = gpy.Tone2 + fmt.Println(gpy.Pinyin(hans, a)) + // [[zho1ng zho4ng] [guo2] [re2n]] + + fmt.Println(gpy.LazyPinyin(hans, gpy.NewArgs())) + // [zhong guo ren] + + fmt.Println(gpy.Convert(hans, nil)) + // [[zhong] [guo] [ren]] + + fmt.Println(gpy.LazyConvert(hans, nil)) + // [zhong guo ren] +} \ No newline at end of file diff --git a/demo/gse/main.go b/demo/gse/main.go new file mode 100644 index 0000000..75479e6 --- /dev/null +++ b/demo/gse/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "flag" + "fmt" + "log" + + "github.com/go-ego/gse" +) + +var ( + text = flag.String("text", "中国互联网历史上最大的一笔并购案", "要分词的文本") +) + +func main() { + flag.Parse() + + var seg gse.Segmenter + // seg.LoadDict("../data/dict/dictionary.txt") + seg.LoadDict() + + segments := seg.Segment([]byte(*text)) + fmt.Println(gse.ToString(segments, true)) + + text2 := []byte("深圳地标建筑, 深圳地王大厦") + segs := seg.Segment(text2) + log.Println(gse.ToString(segs, false)) +} \ No newline at end of file diff --git a/demo/riot/main.go b/demo/riot/main.go new file mode 100644 index 0000000..46338d8 --- /dev/null +++ b/demo/riot/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "log" + + "github.com/go-ego/riot" + "github.com/go-ego/riot/types" +) + +var ( + // searcher 是协程安全的 + searcher = riot.Engine{} +) + +func main() { + // 初始化 + searcher.Init(types.EngineOpts{ + Using: 3, + SegmenterDict: "zh", + // SegmenterDict: "your gopath"+"/src/github.com/go-ego/riot/data/dict/dictionary.txt", + }) + defer searcher.Close() + + text := "此次百度收购将成中国互联网最大并购" + text1 := "百度宣布拟全资收购91无线业务" + text2 := "百度是中国最大的搜索引擎" + + // 将文档加入索引,docId 从1开始 + searcher.IndexDoc(1, types.DocIndexData{Content: text}) + searcher.IndexDoc(2, types.DocIndexData{Content: text1}, false) + searcher.IndexDoc(3, types.DocIndexData{Content: text2}, true) + + // 等待索引刷新完毕 + searcher.FlushIndex() + + // 搜索输出格式见 types.SearchResp 结构体 + log.Print(searcher.Search(types.SearchReq{Text:"百度中国"})) +} \ No newline at end of file diff --git a/demo/robotgo/main.go b/demo/robotgo/main.go new file mode 100644 index 0000000..1a24b0d --- /dev/null +++ b/demo/robotgo/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "github.com/go-vgo/robotgo" +) + +// 可以做什么要考自己思考 +func main() { + robotgo.ScrollMouse(10, "up") + robotgo.MouseClick("left", true) + robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0) +} \ No newline at end of file