Skip to content

golang实现DFA算法的敏感词查找、过滤替换、敏感词匹配检测 godoc:https://godoc.org/github.com/feiin/sensitivewords

License

Notifications You must be signed in to change notification settings

feiin/sensitivewords

Repository files navigation

SensitiveWords

golang实现DFA算法的敏感词查找、过滤替换、敏感词匹配检测

用法

package main

import (
	"fmt"

	"github.com/feiin/sensitivewords"
)

func main() {
    sensitive := sensitivewords.New()
    /*
     * keywords.txt:
     * 尼玛
     * 哈哈
     */
    sensitive.LoadFromFile("./keywords.txt") 
    
	sensitive.AddWord("测试")
	sensitive.AddWords("+q", "+v")

	s, keyword := sensitive.Find("测试啊+q/+v,尼玛,哈哈")
	fmt.Printf("Find:%v, %v\n", s, keyword) //true,测试
	s, results := sensitive.FindAll("测试啊+q/+v,尼玛,哈哈")
	fmt.Printf("FindAll:%v, %v\n", s, results) //true, [测试 +q +v 尼玛 哈哈哈]
	s, results = sensitive.FindAny("测试啊+q/+v,尼玛,哈哈", 3)
	fmt.Printf("FindAny:%v, %v\n", s, results) //true, [测试 +q +v]

	s = sensitive.Check("测试啊+q/+v,尼玛,哈哈")
	fmt.Printf("Check: %v\n", s) //true

	str := sensitive.Filter("测试啊+q/+v,尼玛,哈哈")
	fmt.Printf("Filter:%v\n", str) //**啊**/**,**,**
}

About

golang实现DFA算法的敏感词查找、过滤替换、敏感词匹配检测 godoc:https://godoc.org/github.com/feiin/sensitivewords

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages