forked from x/icebergs
opt alpha
This commit is contained in:
parent
ecf929ea16
commit
8fc84e4f0b
6
go.sum
6
go.sum
@ -0,0 +1,6 @@
|
|||||||
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||||
|
shylinux.com/x/toolkits v0.3.7 h1:n23EroEYnSNGbgkJAnTIV+rBI8aBpHyJnHk3+didf0k=
|
||||||
|
shylinux.com/x/toolkits v0.3.7/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
6
logs.go
6
logs.go
@ -144,11 +144,7 @@ func (m *Message) FormatCost() string {
|
|||||||
return kit.FmtTime(kit.Int64(time.Since(m.time)))
|
return kit.FmtTime(kit.Int64(time.Since(m.time)))
|
||||||
}
|
}
|
||||||
func (m *Message) FormatSize() string {
|
func (m *Message) FormatSize() string {
|
||||||
if len(m.meta[MSG_APPEND]) == 0 {
|
return kit.Format("%dx%d %v", m.Length(), len(m.meta[MSG_APPEND]), kit.Simple(m.meta[MSG_APPEND]))
|
||||||
return kit.Format("%dx%d %s", 0, 0, "[]")
|
|
||||||
} else {
|
|
||||||
return kit.Format("%dx%d %v", len(m.meta[m.meta[MSG_APPEND][0]]), len(m.meta[MSG_APPEND]), kit.Simple(m.meta[MSG_APPEND]))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
func (m *Message) FormatMeta() string {
|
func (m *Message) FormatMeta() string {
|
||||||
return kit.Format(m.meta)
|
return kit.Format(m.meta)
|
||||||
|
@ -21,18 +21,14 @@ func _alpha_find(m *ice.Message, method, word string) {
|
|||||||
switch word = strings.TrimSpace(word); method {
|
switch word = strings.TrimSpace(word); method {
|
||||||
case LINE:
|
case LINE:
|
||||||
case WORD:
|
case WORD:
|
||||||
word = "," + word + "$"
|
word = "^" + word + ","
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索词汇
|
// 搜索词汇
|
||||||
msg := m.Cmd(cli.SYSTEM, "grep", "-rh", word, m.Conf(ALPHA, kit.Keym(kit.MDB_STORE)))
|
msg := m.Cmd(cli.SYSTEM, "grep", "-rh", word, m.Config(kit.MDB_STORE))
|
||||||
msg.CSV(msg.Result(), kit.Simple(m.Confv(ALPHA, kit.META_FIELD))...).Table(func(index int, value map[string]string, head []string) {
|
msg.CSV(msg.Result(), kit.Split(m.Config(kit.MDB_FIELD))...).Table(func(index int, value map[string]string, head []string) {
|
||||||
if value[WORD] == "" {
|
m.PushSearch(ice.CMD, ALPHA, kit.MDB_TYPE, method, kit.MDB_NAME, value[WORD], kit.MDB_TEXT, value["translation"], value)
|
||||||
return
|
|
||||||
}
|
|
||||||
m.PushSearch("cmd", ALPHA, kit.MDB_TYPE, method, kit.MDB_NAME, value[WORD], kit.MDB_TEXT, value["translation"], value)
|
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
func _alpha_load(m *ice.Message, file, name string) {
|
func _alpha_load(m *ice.Message, file, name string) {
|
||||||
// 清空数据
|
// 清空数据
|
||||||
@ -42,11 +38,11 @@ func _alpha_load(m *ice.Message, file, name string) {
|
|||||||
|
|
||||||
// 缓存配置
|
// 缓存配置
|
||||||
m.Conf(ALPHA, kit.Keys(name, kit.MDB_META), kit.Dict(
|
m.Conf(ALPHA, kit.Keys(name, kit.MDB_META), kit.Dict(
|
||||||
|
kit.MDB_FIELD, meta[kit.MDB_FIELD],
|
||||||
kit.MDB_STORE, meta[kit.MDB_STORE],
|
kit.MDB_STORE, meta[kit.MDB_STORE],
|
||||||
kit.MDB_FSIZE, meta[kit.MDB_FSIZE],
|
kit.MDB_FSIZE, meta[kit.MDB_FSIZE],
|
||||||
kit.MDB_LIMIT, meta[kit.MDB_LIMIT],
|
kit.MDB_LIMIT, meta[kit.MDB_LIMIT],
|
||||||
kit.MDB_LEAST, meta[kit.MDB_LEAST],
|
kit.MDB_LEAST, meta[kit.MDB_LEAST],
|
||||||
kit.MDB_FIELD, meta[kit.MDB_FIELD],
|
|
||||||
))
|
))
|
||||||
|
|
||||||
m.Cmd(mdb.IMPORT, ALPHA, name, kit.MDB_LIST, file)
|
m.Cmd(mdb.IMPORT, ALPHA, name, kit.MDB_LIST, file)
|
||||||
@ -54,7 +50,7 @@ func _alpha_load(m *ice.Message, file, name string) {
|
|||||||
// 保存词库
|
// 保存词库
|
||||||
m.Conf(ALPHA, kit.Keys(name, kit.Keym(kit.MDB_LIMIT)), 0)
|
m.Conf(ALPHA, kit.Keys(name, kit.Keym(kit.MDB_LIMIT)), 0)
|
||||||
m.Conf(ALPHA, kit.Keys(name, kit.Keym(kit.MDB_LEAST)), 0)
|
m.Conf(ALPHA, kit.Keys(name, kit.Keym(kit.MDB_LEAST)), 0)
|
||||||
m.Echo("%s: %d", name, m.Grow(ALPHA, name, kit.Dict(WORD, " ")))
|
m.Echo("%s: %d", name, m.Grow(ALPHA, name, kit.Dict(WORD, ice.SP)))
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -64,51 +60,38 @@ const (
|
|||||||
|
|
||||||
const ALPHA = "alpha"
|
const ALPHA = "alpha"
|
||||||
|
|
||||||
var Index = &ice.Context{Name: ALPHA, Help: "英汉词典",
|
var Index = &ice.Context{Name: ALPHA, Help: "英汉词典", Configs: map[string]*ice.Config{
|
||||||
Configs: map[string]*ice.Config{
|
ALPHA: {Name: ALPHA, Help: "英汉词典", Value: kit.Data(
|
||||||
ALPHA: {Name: ALPHA, Help: "英汉词典", Value: kit.Data(
|
kit.SSH_REPOS, "word-dict", kit.MDB_FIELD, "word,translation,definition",
|
||||||
kit.MDB_LIMIT, "50000", kit.MDB_LEAST, "1000",
|
kit.MDB_STORE, path.Join(ice.USR_LOCAL_EXPORT, ALPHA), kit.MDB_FSIZE, "300000",
|
||||||
kit.MDB_STORE, path.Join(ice.USR_LOCAL_EXPORT, ALPHA), kit.MDB_FSIZE, "2000000",
|
kit.MDB_LIMIT, "50000", kit.MDB_LEAST, "1000",
|
||||||
kit.SSH_REPOS, "word-dict", kit.MDB_FIELD, []interface{}{
|
)},
|
||||||
"audio", "bnc", "collins", "definition", "detail", "exchange", "frq", "id", "oxford", "phonetic", "pos", "tag", "time", "translation", "word",
|
}, Commands: map[string]*ice.Command{
|
||||||
},
|
ALPHA: {Name: "alpha method=word,line word auto import", Help: "英汉", Action: map[string]*ice.Action{
|
||||||
)},
|
mdb.IMPORT: {Name: "import file=usr/word-dict/ecdict name=ecdict", Help: "加载词库", Hand: func(m *ice.Message, arg ...string) {
|
||||||
"_cache": {Name: "_cache", Value: kit.Data(kit.MDB_SHORT, "mw")},
|
_alpha_load(m, m.Option(kit.MDB_FILE), kit.Select(path.Base(m.Option(kit.MDB_FILE)), m.Option(kit.MDB_NAME)))
|
||||||
},
|
|
||||||
Commands: map[string]*ice.Command{
|
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
m.Load()
|
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, ALPHA, m.Prefix(ALPHA))
|
|
||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }},
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if arg[0] == ALPHA {
|
||||||
ALPHA: {Name: "alpha method=word,line word auto _cache", Help: "英汉", Action: map[string]*ice.Action{
|
_alpha_find(m, kit.Select(WORD, arg, 2), arg[1])
|
||||||
mdb.IMPORT: {Name: "import file=usr/word-dict/ecdict name", Help: "加载词库", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_alpha_load(m, m.Option(kit.MDB_FILE), kit.Select(path.Base(m.Option(kit.MDB_FILE)), m.Option(kit.MDB_NAME)))
|
|
||||||
}},
|
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
if arg[0] == ALPHA {
|
|
||||||
_alpha_find(m, kit.Select(WORD, arg, 2), arg[1])
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
"_cache": {Name: "_cache", Help: "缓存", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.OptionFields("time,id,word,translation,definition")
|
|
||||||
m.Cmdy(mdb.SELECT, m.Prefix("_cache"), "", mdb.HASH)
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if len(arg) < 2 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer m.StatusTimeCount()
|
|
||||||
m.OptionFields("id,word,translation,definition")
|
|
||||||
if m.Cmdy(mdb.SELECT, m.Prefix("_cache"), "", mdb.HASH, "mw", arg[0]+arg[1]); len(m.Appendv("id")) > 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _alpha_find(m, arg[0], arg[1]); len(m.Appendv("id")) > 0 {
|
|
||||||
m.Cmd(mdb.INSERT, m.Prefix("_cache"), "", mdb.HASH, "mw", arg[0]+arg[1], m.AppendSimple())
|
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
},
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
}
|
if len(arg) < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer m.StatusTimeCountTotal(m.Config(kit.MDB_COUNT))
|
||||||
|
if arg[0] == WORD {
|
||||||
|
if msg := m.Cmd(CACHE, arg[1]); msg.Length() > 0 {
|
||||||
|
m.Copy(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.OptionFields(m.Config(kit.MDB_FIELD))
|
||||||
|
if _alpha_find(m, arg[0], arg[1]); arg[0] == WORD && m.Length() > 0 {
|
||||||
|
m.Cmd(CACHE, mdb.CREATE, m.AppendSimple())
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
func init() { wiki.Index.Register(Index, nil) }
|
func init() { wiki.Index.Register(Index, nil) }
|
||||||
|
23
misc/alpha/cache.go
Normal file
23
misc/alpha/cache.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package alpha
|
||||||
|
|
||||||
|
import (
|
||||||
|
ice "shylinux.com/x/icebergs"
|
||||||
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
|
kit "shylinux.com/x/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
const CACHE = "cache"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
|
CACHE: {Name: "cache", Help: "缓存", Value: kit.Data(
|
||||||
|
kit.MDB_SHORT, "word", kit.MDB_FIELD, "time,word,translation,definition",
|
||||||
|
)},
|
||||||
|
}, Commands: map[string]*ice.Command{
|
||||||
|
CACHE: {Name: "cache word auto", Help: "缓存", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
|
mdb.CREATE: {Name: "create word translation definition", Help: "创建"},
|
||||||
|
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
mdb.HashSelect(m, arg...)
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
}
|
@ -106,10 +106,10 @@ func (m *Message) StatusTime(arg ...interface{}) {
|
|||||||
m.Status(kit.MDB_TIME, m.Time(), arg, kit.MDB_COST, m.FormatCost())
|
m.Status(kit.MDB_TIME, m.Time(), arg, kit.MDB_COST, m.FormatCost())
|
||||||
}
|
}
|
||||||
func (m *Message) StatusTimeCount(arg ...interface{}) {
|
func (m *Message) StatusTimeCount(arg ...interface{}) {
|
||||||
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, m.FormatSize(), arg, kit.MDB_COST, m.FormatCost())
|
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, kit.Split(m.FormatSize())[0], arg, kit.MDB_COST, m.FormatCost())
|
||||||
}
|
}
|
||||||
func (m *Message) StatusTimeCountTotal(arg ...interface{}) {
|
func (m *Message) StatusTimeCountTotal(arg ...interface{}) {
|
||||||
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, m.FormatSize(), kit.MDB_TOTAL, arg, kit.MDB_COST, m.FormatCost())
|
m.Status(kit.MDB_TIME, m.Time(), kit.MDB_COUNT, kit.Split(m.FormatSize())[0], kit.MDB_TOTAL, arg, kit.MDB_COST, m.FormatCost())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration [progress]]]
|
func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration [progress]]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user