Skip to content

Commit

Permalink
deps: update rose
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Apr 16, 2023
1 parent f2a33ff commit 0a5963b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/flowerime/goutil v0.2.2
github.com/flowerime/rose v1.0.0
github.com/flowerime/rose v1.1.1-0.20230416092638-a709f57d8826
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/spf13/cobra v1.7.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/flowerime/goutil v0.2.2 h1:teAE8BSB+PI0wCX+4n5W7ErTWTHThac98JjQ2LZN0h8=
github.com/flowerime/goutil v0.2.2/go.mod h1:UFcJNB+mJSFg5OhAgc3Ct0Wy8narM8cEmoWVnMECDhk=
github.com/flowerime/rose v1.0.0 h1:7xaPJ9ZAe+x0c1zal92pvm7fpz2KESNpJKNdIMTHKVM=
github.com/flowerime/rose v1.0.0/go.mod h1:yr+41kRPzPWmXPwNskkG1LEoA6fv2hKY5Hoa+jGT57w=
github.com/flowerime/rose v1.1.1-0.20230416092638-a709f57d8826 h1:YF3RzPI5rmkP3jVsHDeGfRD2q6PFB2YvYiBK+5pTiNM=
github.com/flowerime/rose v1.1.1-0.20230416092638-a709f57d8826/go.mod h1:yr+41kRPzPWmXPwNskkG1LEoA6fv2hKY5Hoa+jGT57w=
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs=
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
Expand Down
36 changes: 17 additions & 19 deletions internal/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,32 @@ type Config struct {
SortByWordLen bool // 按照词长重新排序
}

func (c *Config) Gen() rose.Table {
var t rose.Table
func (c *Config) Gen() rose.WubiTable {
var wl rose.WordLibrary
var ct rose.CodeTable

// 极速赛码表格式
if c.Format == "jisu" {
t = c.ReadJisu()
return t
}

d := rose.Parse(c.Path, c.Format)
t = d.GetTable()
// 极点格式不需要处理候选位置
if c.Format != "jidian" {
d.GenPos()
wl = c.ReadJisu()
ct = wl.ToCodeTable()
} else {
d := rose.Parse(c.Path, c.Format)
ct = d.ToCodeTable()
}
wt := ct.ToWubiTable()

for i := range t {
if t[i].Pos <= 0 {
t[i].Pos = 1
for i := range wt {
if wt[i].Pos <= 0 {
wt[i].Pos = 1
}
t[i].Code = c.addSuffix(t[i].Code, t[i].Pos)
wt[i].Code = c.addSuffix(wt[i].Code, wt[i].Pos)
}
if c.SortByWordLen {
sort.SliceStable(t, func(i, j int) bool {
return len([]rune(t[i].Word)) > len([]rune(t[j].Word))
sort.SliceStable(wt, func(i, j int) bool {
return len([]rune(wt[i].Word)) > len([]rune(wt[j].Word))
})
}

return t
return wt
}

// 加上选重键
Expand Down
11 changes: 6 additions & 5 deletions internal/gen/jisu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"github.com/flowerime/rose/pkg/rose"
)

func (c *Config) ReadJisu() rose.Table {
ret := make(rose.Table, 0, 1e5)
func (c *Config) ReadJisu() rose.WordLibrary {
ret := make(rose.WordLibrary, 0, 1e5)
rd, err := util.Read(c.Path)
if err != nil {
panic(err)
}

scan := bufio.NewScanner(rd)

for scan.Scan() {
Expand All @@ -25,14 +26,14 @@ func (c *Config) ReadJisu() rose.Table {
code := wc[1]
// 带空格 a_ aa_
if len(code)-1 > 0 && code[len(code)-1] == '_' {
ret = append(ret, &rose.TableEntry{wc[0], code, 1})
ret = append(ret, &rose.WubiEntry{wc[0], code, 1})
continue
}

code, suf := FindSuffixInteger(code)
// 不带数字 akdb ksdw
if suf == "" {
ret = append(ret, &rose.TableEntry{wc[0], code, 1})
ret = append(ret, &rose.WubiEntry{wc[0], code, 1})
continue
}

Expand All @@ -45,7 +46,7 @@ func (c *Config) ReadJisu() rose.Table {
code += string(c.SelectKeys[pos-1])
}
// fmt.Println(wc[0], code, pos)
ret = append(ret, &rose.TableEntry{wc[0], code, pos})
ret = append(ret, &rose.WubiEntry{wc[0], code, pos})
}
return ret
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gen/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// 输出赛码表
func Write(t rose.Table, path string) {
func Write(t rose.WubiTable, path string) {
var buf bytes.Buffer
buf.Grow(len(t))
for i := range t {
Expand Down

0 comments on commit 0a5963b

Please sign in to comment.