Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Index = &ctx.Context{Name: "lex", Help: "词法中心", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{}, Commands: map[string]*ctx.Command{ "train": &ctx.Command{Name: "train seed [hash [page]", Help: "添加词法规则", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { page, hash := 1, 1 if len(arg) > 2 { page = lex.index("npage", arg[2]) m.Assert(page < m.Capi("nlang"), "词法集合过多") } if len(arg) > 1 { hash = lex.index("nhash", arg[1]) } if lex.mat[page] == nil { lex.mat[page] = map[byte]*State{} } m.Result(0, lex.train(page, hash, []byte(arg[0]))) lex.seed = append(lex.seed, &Seed{page, hash, arg[0]}) lex.Cap("stream", fmt.Sprintf("%d,%s,%s", lex.Capi("nseed", 1), lex.Cap("npage"), lex.Cap("nhash"))) } }}, "parse": &ctx.Command{Name: "parse line [page]", Help: "解析单词", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { page := 1 if len(arg) > 1 { page = lex.index("npage", arg[1]) } hash, rest, word := lex.parse(m, page, []byte(arg[0])) m.Result(0, hash, string(rest), string(word)) } }}, "split": &ctx.Command{Name: "split line page void help", Help: "分割语句", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { page := 1 if len(arg) > 1 { page = lex.index("npage", arg[1]) } void := 2 if len(arg) > 2 { void = lex.index("npage", arg[2]) } help := 2 if len(arg) > 3 { help = lex.index("npage", arg[3]) } rest := []byte(arg[0]) _, _, rest = lex.parse(m, help, []byte(rest)) _, _, rest = lex.parse(m, void, []byte(rest)) hash, word, rest := lex.parse(m, page, []byte(rest)) m.Add("result", fmt.Sprintf("%d", hash), string(word), string(rest)) } }}, "info": &ctx.Command{Name: "info", Help: "显示缓存", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { for i, v := range lex.seed { m.Echo("seed: %d %v\n", i, v) } for i, v := range lex.page { m.Echo("page: %s %d\n", i, v) } for i, v := range lex.hash { m.Echo("hash: %s %d\n", i, v) } for i, v := range lex.state { m.Echo("node: %v %v\n", i, v) } for i, v := range lex.mat { for k, v := range v { m.Echo("node: %v %v %v\n", i, k, v) } } } }}, "check": &ctx.Command{Name: "check page void word...", Help: "解析语句, page: 语法集合, void: 空白语法集合, word: 语句", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if lex, ok := m.Target().Server.(*LEX); m.Assert(ok) { set := map[*State]bool{} nreal := 0 for _, v := range lex.state { nreal++ set[v] = true } nnode := 0 for i, v := range lex.mat { for j, x := range v { if x == nil && int(j) < m.Capi("nlang") { continue } nnode++ if _, ok := set[x]; !ok { m.Log("fuck", "not in %d %d %v %p", i, j, x, x) } } } m.Log("fuck", "node: %d real: %d", nnode, nreal) } }}, }, }
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.