Skip to content

敏感词查找,验证,过滤和替换 🤓 FindAll, Validate, Filter and Replace words.

License

Notifications You must be signed in to change notification settings

houseme/sensitive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

de6f3fe · Aug 17, 2024

History

52 Commits
Aug 17, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Aug 16, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024

Repository files navigation

Sensitive

敏感词查找,验证,过滤和替换

FindAll, Validate, Filter and Replace words.

Go Reference sensitive CI License GitHub go.mod Go version (branch)

特别说明

基于 sensitive, 修复了一些问题,增加了一些功能。

用法

package main

import (
    "github.com/houseme/sensitive"
)

func main() {
    filter := sensitive.New()
    _ = filter.LoadWordDict("path/to/dict")
    // Do something
}

AddWord

添加敏感词

filter.AddWord("垃圾")

Replace

把词语中的字符替换成指定的字符,这里的字符指的是 rune 字符,比如*就是'*'

filter.Replace("这篇文章真的好垃圾", '*')
// output => 这篇文章真的好**

Filter

直接移除词语

filter.Filter("这篇文章真的好垃圾啊")
// output => 这篇文章真的好啊

FindIn

查找并返回第一个敏感词,如果没有则返回false

filter.FindIn("这篇文章真的好垃圾")
// output => true, 垃圾

Validate

验证内容是否 ok,如果含有敏感词,则返回false和第一个敏感词。

filter.Validate("这篇文章真的好垃圾")
// output => false, 垃圾

FindAll

查找内容中的全部敏感词,以数组返回。

filter.FindAll("这篇文章真的好垃圾")
// output => [垃圾]

LoadNetWordDict

加载网络词库。

filter.LoadNetWordDict("https://raw.githubusercontent.com/houseme/sensitive/main/dict/dict.txt")

UpdateNoisePattern

设置噪音模式,排除噪音字符。

// failed
filter.FindIn("这篇文章真的好垃 x 圾") // false
filter.UpdateNoisePattern(`x`)
// success
filter.FindIn("这篇文章真的好垃 x 圾") // true, 垃圾
filter.Validate("这篇文章真的好垃 x 圾") // False, 垃圾

License

Sensitive is licensed under the MIT License, 100% free and open-source, forever.