Comments (4)
可以的,你可以设置下noise的正则表达式,比如加入空格\s
,这样就会在处理前将空格先全部移除
但是,Replace
和FindAll
的话是不会自动移除noise的,所以还要先filter.RemoveNoise("这 句 话 应 被 屏 蔽")
才能达到你要的效果
filter := New()
filter.AddWord("这句话应被屏蔽")
filter.UpdateNoisePattern(`\s`)
s := filter.RemoveNoise("这 句 话 应 被 屏 蔽")
actual := filter.Replace(s, '*')
from sensitive.
不好意思,我例子给错了,是希望结果中的正常语句仍然含有空格,因为可能用户的一句话中,有些是需要屏蔽的,有些不需要被屏蔽,新的例子如下
package wordpackage_test
import (
"github.com/importcjj/sensitive"
"testing"
)
// 范例
func TestFilterExample(t *testing.T) {
filter := sensitive.New()
filter.AddWord("这句话应被屏蔽")
actual := filter.Replace("这 句 话 不 需 要 屏 蔽。这 句 话 应 被 屏 蔽", '*')
expect := "这 句 话 不 需 要 屏 蔽。*******"
if actual != expect {
t.Error("屏蔽失败,结果为", actual)
}
}
filter.RemoveNoise会把语句中正常部分的noise也删掉,所以要达到例子中的效果的话,估计要自己改代码实现一遍,所以想问问看能否给出支持呢?
from sensitive.
这种没办法,正常的句子也不会这样吧
from sensitive.
有时会有这种情况,比如,有的用户喜欢用空格聊天:"早上碰见一个变态 吓死我了 还好我跑得快"
假设屏蔽词为:”变态“
采用filter.RemoveNoise
过滤掉之后会变成,“早上碰见一个**吓死我了还好我跑得快",这类用户不是故意用过滤字,但是语句中的正常部分也会过滤掉了
这个规则可能比较特殊,那只能考虑自己来实现了
感谢答复
from sensitive.
Related Issues (13)
- 语句末尾字符会被错误的替换 HOT 4
- 麻烦一下作者提供一下删除敏感字的函数接口 HOT 1
- A more serious readme is required HOT 1
- 如何释放一个Trim树,重新载入 HOT 1
- 支持英文吗? HOT 3
- 只能替换字符,能替换字符串吗? HOT 1
- LoadNetWordDict加载网络敏感词出错? HOT 3
- xx.info ,xx和info都会被判为敏感词 。其它网址类似
- Hi
- 关键词过滤问题 HOT 9
- LoadWordDict无法加载文件 HOT 21
- 不能删除已生成的树的节点吗 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sensitive.