Skip to content

Commit

Permalink
Update gse to newest and test code
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Sep 4, 2021
1 parent 8694678 commit 7ef7739
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func benchmark_PhrasePinyin(b *testing.B, s string) {
}
}

var seg = gse.New()
var seg, _ = gse.New()

func benchmark_PhrasePinyin_Seg(b *testing.B, s string) {
b.StopTimer()
Expand Down
2 changes: 1 addition & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
}()
fmt.Println("gpy phrase2:", phrase.Paragraph(test))

seg := gse.New("zh, dict.txt")
seg, _ := gse.New("zh, dict.txt")
phrase.DictAdd["都会区"] = "dū huì qū"
fmt.Println("gpy phrase:", phrase.Paragraph(test, seg))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/go-ego/gpy
go 1.13

require (
github.com/go-ego/gse v0.67.0
github.com/go-ego/gse v0.69.2
github.com/mattn/go-isatty v0.0.13
github.com/vcaesar/tt v0.11.0
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/go-ego/cedar v0.10.2 h1:0AQkBNfHAzuUn306v0ydMXAawHoIdxiYwN1+2XvFySw=
github.com/go-ego/cedar v0.10.2/go.mod h1:OlEbpcRpzwp69CoCXPJTmrOzELoGAmFDgW3hdWrHHc0=
github.com/go-ego/gse v0.67.0 h1:N0g6rerI7lRhABQaszfcSfXBfvuZV9uwd5oCj7CUWzQ=
github.com/go-ego/gse v0.67.0/go.mod h1:AbOXXmI3rgUG/Rb3e9xtk6xDjSLj6KpBHoctONT58ns=
github.com/go-ego/gse v0.69.2 h1:2S6oXsun1YSPVuo4f2YeJPonpoIgRNjt7n3rB4Rq6/s=
github.com/go-ego/gse v0.69.2/go.mod h1:AbOXXmI3rgUG/Rb3e9xtk6xDjSLj6KpBHoctONT58ns=
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/vcaesar/tt v0.11.0 h1:obQecjgbnAxxC6OYGY6yDvhGRW2PR5wD8Ma2uJH3WGA=
Expand Down
27 changes: 16 additions & 11 deletions phrase/paragraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ func BenchmarkParagraph(b *testing.B) {

func TestParagraph(t *testing.T) {
expects := map[string]string{
"西雅图太空针, The Space Nedle": "xi ya tu tai kong zhen, The Space Nedle",
"旧金山湾金门大桥": "jiu jin shan wan jin men da qiao",
"纽约帝国大厦, 纽约时代广场": "niu yue di guo da sha, niu yue shi dai guang chang",
"伦敦泰晤士河, 大笨钟": "lun dun tai wu shi he, da ben zhong",
"东京都, 东京晴空塔": "dong jing du, dong jing qing kong ta",
"洛杉矶好莱坞": "luo shan ji hao lai wu",
"巴黎埃菲尔铁塔": "ba li ai fei er tie ta",
"上海外滩, 陆家嘴上海中心": "shang hai wai tan, lu jia zui shang hai zhong xin",
"北京八达岭长城": "bei jing ba da ling chang cheng",
"西雅图太空针, The Space Nedle": "xi ya tu tai kong zhen, The Space Nedle",
"旧金山湾金门大桥": "jiu jin shan wan jin men da qiao",
"纽约帝国大厦, 纽约时代广场": "niu yue di guo da sha, niu yue shi dai guang chang",
"多伦多加拿大国家电视塔, the CN Tower, 尼亚加拉大瀑布": "duo lun duo jia na da guo jia dian shi ta, the CN Tower, ni ya jia la da pu bu",
"伦敦泰晤士河, 大笨钟": "lun dun tai wu shi he, da ben zhong",
"雅典帕特农神庙": "ya dian pa te nong shen miao",
"东京都, 东京晴空塔": "dong jing du, dong jing qing kong ta",
"洛杉矶好莱坞": "luo shan ji hao lai wu",
"巴黎埃菲尔铁塔": "ba li ai fei er tie ta",
"上海外滩, 陆家嘴上海中心大厦": "shang hai wai tan, lu jia zui shang hai zhong xin da sha",
"北京八达岭长城": "bei jing ba da ling chang cheng",
"香港维多利亚港": "xiang gang wei duo li ya gang",
"悉尼歌剧院": "xi ni ge ju yuan",
}

seg := gse.New("zh, ../examples/dict.txt")
seg, err := gse.New("zh, ../examples/dict.txt")
tt.Nil(t, err)
for source, expect := range expects {
actual := Paragraph(source, seg)
if expect != actual {
Expand All @@ -39,7 +44,7 @@ func TestParagraph(t *testing.T) {
}

func TestPinyin(t *testing.T) {
seg := gse.New("zh, ../examples/dict.txt")
seg, _ := gse.New("zh, ../examples/dict.txt")
WithGse(seg)

text := "西雅图都会区, 西雅图太空针"
Expand Down
2 changes: 1 addition & 1 deletion phrase/phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func cutWords(s string, segs ...gse.Segmenter) []string {
}

if !loaded {
seg = gse.New()
seg, _ = gse.New()
loaded = true
}
return seg.CutAll(s)
Expand Down

0 comments on commit 7ef7739

Please sign in to comment.