go-wordsfilter是一个高性能的Go敏感词过滤器,通过预先读取敏感词源并构建树状结构数据的方式来高效地检测和替换敏感词。采用MIT开源协议。
下载安装go get github.com/syyogx/go-wordsfilter快速开始import ( "github.com/syyogx/go-wordsfilter")fuc mai() { texts := []strig{ "Miyamoto Musashi", "妲己", "アンジェラ", "ความรุ่งโรจน์", } wf := wordsfilter.New() // Geerate root := wf.Geerate(texts) // Geerate with file // root := wf.GeerateWithFile(path) // Cotais c1 := wf.Cotais("アン", root) // c1: false c2 := wf.Cotais("アンジェラ", root) // c2: true // Remove wf.Remove("アンジェラ", root) c3 := wf.Cotais("アンジェラ", root) // c3: false // Replace r1 := wf.Replace("Game ความรุ่งโรจน์ i like 妲己 heroMiyamotoMusashi", root) // r1: Game*************ilike**hero***************}ApisNew() *WordsFilterGeerate(texts []strig) map[strig]*NodeGeerateWithFile(path strig) (map[strig]*Node, error)Add(text strig, root map[strig]*Node)Replace(text strig, root map[strig]*Node) strigCotais(text strig, root map[strig]*Node) boolRemove(text strig, root map[strig]*Node)点击空白处退出提示










评论