Giter VIP home page Giter VIP logo

Comments (4)

importcjj avatar importcjj commented on August 12, 2024

可以的,你可以设置下noise的正则表达式,比如加入空格\s,这样就会在处理前将空格先全部移除

但是,ReplaceFindAll的话是不会自动移除noise的,所以还要先filter.RemoveNoise("这 句 话 应 被 屏 蔽")才能达到你要的效果

	filter := New()
	filter.AddWord("这句话应被屏蔽")
	filter.UpdateNoisePattern(`\s`)

	s := filter.RemoveNoise("这 句 话 应 被 屏 蔽")
	actual := filter.Replace(s, '*')

from sensitive.

ankisme avatar ankisme commented on August 12, 2024

不好意思,我例子给错了,是希望结果中的正常语句仍然含有空格,因为可能用户的一句话中,有些是需要屏蔽的,有些不需要被屏蔽,新的例子如下

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.

importcjj avatar importcjj commented on August 12, 2024

这种没办法,正常的句子也不会这样吧

from sensitive.

ankisme avatar ankisme commented on August 12, 2024

有时会有这种情况,比如,有的用户喜欢用空格聊天:"早上碰见一个变态 吓死我了 还好我跑得快"

假设屏蔽词为:”变态“

采用filter.RemoveNoise过滤掉之后会变成,“早上碰见一个**吓死我了还好我跑得快",这类用户不是故意用过滤字,但是语句中的正常部分也会过滤掉了

这个规则可能比较特殊,那只能考虑自己来实现了

感谢答复

from sensitive.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.