This commit is contained in:
suguo.yao 2022-10-28 16:22:56 +08:00
parent 8007cdf5cb
commit 623cac96df
4 changed files with 42 additions and 0 deletions

2
go.mod
View File

@ -17,6 +17,7 @@ require (
require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ego/gse v0.70.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
@ -34,6 +35,7 @@ require (
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/vcaesar/cedar v0.20.1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect

View File

@ -7,6 +7,7 @@
#### 项目资料
https://github.com/sea-team/gofound
github.com/go-ego/gse
#### 实例环境构建

View File

@ -1,6 +1,34 @@
package service
import (
"fmt"
"github.com/go-ego/gse"
)
// 分词
func WordCut(keyword string) []string {
return container.Tokenizer.Cut(keyword)
}
var (
seg gse.Segmenter
)
func init() {
s, err := gse.New("zh", "alpha")
if err != nil {
panic(err)
}
// s.LoadDict()
s.LoadDict("zh_s")
seg = s
}
func Cut(w string) []string {
hmm := seg.Cut(w, false)
po := seg.Pos(w, true)
r := seg.TrimPos(po)
fmt.Println(r)
return seg.Trim(hmm)
}

11
service/word_test.go Normal file
View File

@ -0,0 +1,11 @@
package service
import (
"fmt"
"testing"
)
func TestCut(t *testing.T) {
a := Cut("而这些并不是完全重要,更加重要的问题是, 海贝尔曾经提到过,人生就是学校。在那里,与其说好的教师是幸福,不如说好的教师是不幸。")
fmt.Println(a)
}