https://github.com/houseme/sensitive
敏感词查找,验证,过滤和替换 🤓 FindAll, Validate, Filter and Replace words.
https://github.com/houseme/sensitive
dirtywords filter go golang keyword sensitive text trie trie-tree word
Last synced: 4 months ago
JSON representation
敏感词查找,验证,过滤和替换 🤓 FindAll, Validate, Filter and Replace words.
- Host: GitHub
- URL: https://github.com/houseme/sensitive
- Owner: houseme
- License: mit
- Created: 2024-06-13T02:49:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-17T00:07:16.000Z (11 months ago)
- Last Synced: 2025-01-23T18:28:15.661Z (6 months ago)
- Topics: dirtywords, filter, go, golang, keyword, sensitive, text, trie, trie-tree, word
- Language: Go
- Homepage:
- Size: 383 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Sensitive
敏感词查找,验证,过滤和替换
FindAll, Validate, Filter and Replace words.
[](https://pkg.go.dev/github.com/houseme/sensitive)
[](https://github.com/houseme/sensitive/actions/workflows/go.yml)
[](https://github.com/houseme/sensitive)
## 特别说明
基于 [sensitive](https://github.com/importcjj/sensitive), 修复了一些问题,增加了一些功能。
#### 用法
```go
package mainimport (
"github.com/houseme/sensitive"
)func main() {
filter := sensitive.New()
_ = filter.LoadWordDict("path/to/dict")
// Do something
}
```#### AddWord
添加敏感词
```go
filter.AddWord("垃圾")
```#### Replace
把词语中的字符替换成指定的字符,这里的字符指的是 rune 字符,比如`*`就是`'*'`。
```go
filter.Replace("这篇文章真的好垃圾", '*')
// output => 这篇文章真的好**
```#### Filter
直接移除词语
```go
filter.Filter("这篇文章真的好垃圾啊")
// output => 这篇文章真的好啊
```#### FindIn
查找并返回第一个敏感词,如果没有则返回`false`
```go
filter.FindIn("这篇文章真的好垃圾")
// output => true, 垃圾
```#### Validate
验证内容是否 ok,如果含有敏感词,则返回`false`和第一个敏感词。
```go
filter.Validate("这篇文章真的好垃圾")
// output => false, 垃圾```
#### FindAll
查找内容中的全部敏感词,以数组返回。
```go
filter.FindAll("这篇文章真的好垃圾")
// output => [垃圾]
```#### LoadNetWordDict
加载网络词库。
```go
filter.LoadNetWordDict("https://raw.githubusercontent.com/houseme/sensitive/main/dict/dict.txt")
```#### UpdateNoisePattern
设置噪音模式,排除噪音字符。
```go
// 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](LICENSE), 100% free and open-source, forever.