go-wordsfilter高性能的 Go 敏感詞過(guò)濾器
go-wordsfilter 是一個(gè)高性能的 Go 敏感詞過(guò)濾器,通過(guò)預(yù)先讀取敏感詞源并構(gòu)建樹(shù)狀結(jié)構(gòu)數(shù)據(jù)的方式來(lái)高效地檢測(cè)和替換敏感詞。采用 MIT 開(kāi)源協(xié)議。
下載安裝
go get github.com/syyongx/go-wordsfilter
快速開(kāi)始
import (
"github.com/syyongx/go-wordsfilter"
)
func main() {
texts := []string{
"Miyamoto Musashi",
"妲己",
"アンジェラ",
"?????????????",
}
wf := wordsfilter.New()
// Generate
root := wf.Generate(texts)
// Generate with file
// root := wf.GenerateWithFile(path)
// Contains
c1 := wf.Contains("アン", root)
// c1: false
c2 := wf.Contains("アンジェラ", root)
// c2: true
// Remove
wf.Remove("アンジェラ", root)
c3 := wf.Contains("アンジェラ", root)
// c3: false
// Replace
r1 := wf.Replace("Game ????????????? i like 妲己 heroMiyamotoMusashi", root)
// r1: Game*************ilike**hero***************
}
Apis
New() *WordsFilter Generate(texts []string) map[string]*Node GenerateWithFile(path string) (map[string]*Node, error) Add(text string, root map[string]*Node) Replace(text string, root map[string]*Node) string Contains(text string, root map[string]*Node) bool Remove(text string, root map[string]*Node)
評(píng)論
圖片
表情
