antlinker / go-dirtyfilter Goto Github PK
View Code? Open in Web Editor NEWGolang基于DFA算法实现的敏感词过滤
License: Apache License 2.0
Golang基于DFA算法实现的敏感词过滤
License: Apache License 2.0
比如关键词包含 "ass",那associate也会被过滤,显然这个不是所预期的。
package main
import (
"fmt"
"github.com/antlinker/go-dirtyfilter"
"github.com/antlinker/go-dirtyfilter/store"
)
var (
filterText = `我是需要过滤的内容,内容为:**文@@件,需要过滤。。。hello`
)
func main() {
memStore, err := store.NewMemoryStore(store.MemoryConfig{
DataSource: []string{"哈哈"},
})
if err != nil {
panic(err)
}
filterManage := filter.NewDirtyManager(memStore)
result, err := filterManage.Filter().Replace(filterText, '*')
if err != nil {
panic(err)
}
fmt.Println(result)
}
这段代码,应该是原样输出,实际输出是空字符串
func (nf *nodeFilter) Replace(text string, delim rune) (string, error) {
uchars := []rune(text)
idexs := nf.doIndexes(uchars)
if len(idexs) == 0 {
// return "", nil
// 合法内容,原样输出
return text, nil
}
for i := 0; i < len(idexs); i++ {
uchars[idexs[i]] = rune(delim)
}
return string(uchars), nil
}
是不是修改一下Replace函数,在未找到屏蔽词的时候,原样输出
Replace一般也需要过滤一些特殊字符吧,为什么没有这个参数?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.