Skip to content

Commit

Permalink
<添加><案例><搜索、分词、拼音>
Browse files Browse the repository at this point in the history
  • Loading branch information
iceopen committed Dec 15, 2017
1 parent 80a9f44 commit b66663f
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
44 changes: 44 additions & 0 deletions demo/gpy/main.go
Original file line number Diff line number Diff line change
@@ -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]
}
28 changes: 28 additions & 0 deletions demo/gse/main.go
Original file line number Diff line number Diff line change
@@ -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))
}
38 changes: 38 additions & 0 deletions demo/riot/main.go
Original file line number Diff line number Diff line change
@@ -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:"百度中国"}))
}
12 changes: 12 additions & 0 deletions demo/robotgo/main.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit b66663f

Please sign in to comment.