diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index c71fbf9..10e9272 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -99,4 +99,10 @@ | 序号 | 变更类型 | 说明 | 时间 | 备注 | |:---|:---|:---|:---|:--| | 1 | A | 新增 Helper 工具类 | 2021-5-12 20:51:58 | | -| 2 | A | 新增动态词库初始化支持 | 2021-5-12 20:51:58 | | \ No newline at end of file +| 2 | A | 新增动态词库初始化支持 | 2021-5-12 20:51:58 | | + +# release_0.0.14 + +| 序号 | 变更类型 | 说明 | 时间 | 备注 | +|:---|:---|:---|:---|:--| +| 1 | A | 开发样式配置特性 | 2021-5-31 20:51:58 | | diff --git a/README.md b/README.md index 211d497..575862a 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,46 @@ List wordList = SensitiveWordHelper.findAll(text); Assert.assertEquals("[sensitiveword@xx.com]", wordList.toString()); ``` +# 特性配置 + +## 说明 + +上面的特性默认都是开启的,有时业务需要灵活定义相关的配置特性。 + +所以 v0.0.14 开放了属性配置。 + +## 配置方法 + +为了让使用更加优雅,统一使用 fluent-api 的方式定义。 + +用户可以使用 `SensitiveWordBs` 进行如下定义: + +```java +SensitiveWordBs wordBs = SensitiveWordBs.newInstance() + .ignoreCase(true) + .ignoreWidth(true) + .ignoreNumStyle(true) + .ignoreChineseStyle(true) + .ignoreEnglishStyle(true) + .ignoreRepeat(true) + .init(); + +final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。"; +Assert.assertTrue(wordBs.contains(text)); +``` +## 配置说明 + +其中各项配置的说明如下: + +| 序号 | 方法 | 说明 | +|:---|:---|:---| +| 1 | ignoreCase | 忽略大小写 | +| 2 | ignoreWidth | 忽略半角圆角 | +| 3 | ignoreNumStyle | 忽略数字的写法 | +| 4 | ignoreChineseStyle | 忽略中文的书写格式 | +| 5 | ignoreEnglishStyle | 忽略英文的书写格式 | +| 6 | ignoreRepeat | 忽略重复词 | + # 用户自定义 ## 敏感词和白名单 diff --git a/pom.xml b/pom.xml index 7ac907e..c2ca142 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.houbb sensitive-word - 0.0.14-SNAPSHOT + 0.0.14 @@ -25,7 +25,7 @@ 1.7 - 0.1.73 + 0.1.129 1.2.0 diff --git a/release.bat b/release.bat index 6bb390e..629c269 100644 --- a/release.bat +++ b/release.bat @@ -10,9 +10,9 @@ ECHO "============================= RELEASE START..." :: 版本号信息(需要手动指定) :::: 旧版本名称 -SET version=0.0.13 +SET version=0.0.14 :::: 新版本名称 -SET newVersion=0.0.14 +SET newVersion=0.0.15 :::: 组织名称 SET groupName=com.github.houbb :::: 项目名称 diff --git a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java index 4aadf1e..75d3aaa 100644 --- a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java +++ b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordBs.java @@ -3,10 +3,11 @@ package com.github.houbb.sensitive.word.bs; import com.github.houbb.heaven.constant.CharConst; import com.github.houbb.heaven.util.common.ArgUtil; import com.github.houbb.heaven.util.util.CollectionUtil; -import com.github.houbb.sensitive.word.api.*; -import com.github.houbb.sensitive.word.exception.SensitiveWordException; +import com.github.houbb.sensitive.word.api.IWordAllow; +import com.github.houbb.sensitive.word.api.IWordContext; +import com.github.houbb.sensitive.word.api.IWordDeny; +import com.github.houbb.sensitive.word.api.IWordMap; import com.github.houbb.sensitive.word.support.allow.WordAllows; -import com.github.houbb.sensitive.word.support.data.SensitiveWordData; import com.github.houbb.sensitive.word.support.deny.WordDenys; import com.github.houbb.sensitive.word.support.map.SensitiveWordMap; @@ -156,6 +157,72 @@ public class SensitiveWordBs { return this; } + /** + * 是否忽略大小写 + * @param ignoreCase 大小写 + * @return this + * @since 0.0.14 + */ + public SensitiveWordBs ignoreCase(boolean ignoreCase) { + this.context.ignoreCase(ignoreCase); + return this; + } + + /** + * 是否忽略半角全角 + * @param ignoreWidth 半角全角 + * @return this + * @since 0.0.14 + */ + public SensitiveWordBs ignoreWidth(boolean ignoreWidth) { + this.context.ignoreWidth(ignoreWidth); + return this; + } + + /** + * 是否忽略数字格式 + * @param ignoreNumStyle 数字格式 + * @return this + * @since 0.0.14 + */ + public SensitiveWordBs ignoreNumStyle(boolean ignoreNumStyle) { + this.context.ignoreNumStyle(ignoreNumStyle); + return this; + } + + /** + * 是否忽略中文样式 + * @param ignoreChineseStyle 中文样式 + * @return this + * @since 0.0.14 + */ + public SensitiveWordBs ignoreChineseStyle(boolean ignoreChineseStyle) { + this.context.ignoreChineseStyle(ignoreChineseStyle); + return this; + } + + /** + * 是否忽略英文样式 + * @param ignoreEnglishStyle 英文样式 + * @return this + * @since 0.0.14 + */ + public SensitiveWordBs ignoreEnglishStyle(boolean ignoreEnglishStyle) { + this.context.ignoreEnglishStyle(ignoreEnglishStyle); + return this; + } + + /** + * 是否忽略重复 + * @param ignoreRepeat 忽略重复 + * @return this + * @since 0.0.14 + */ + public SensitiveWordBs ignoreRepeat(boolean ignoreRepeat) { + this.context.ignoreRepeat(ignoreRepeat); + return this; + } + /** * 构建默认的上下文 * diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsConfigTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsConfigTest.java new file mode 100644 index 0000000..5d42a77 --- /dev/null +++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsConfigTest.java @@ -0,0 +1,32 @@ +package com.github.houbb.sensitive.word.bs; + +import com.github.houbb.sensitive.word.support.allow.WordAllows; +import com.github.houbb.sensitive.word.support.deny.WordDenys; +import org.junit.Assert; +import org.junit.Test; + +/** + *

project: sensitive-word-SensitiveWordBsConfigTest

+ *

create on 2020/1/7 23:43

+ * + * @author Administrator + * @since 0.0.14 + */ +public class SensitiveWordBsConfigTest { + + @Test + public void configTest() { + SensitiveWordBs wordBs = SensitiveWordBs.newInstance() + .ignoreCase(true) + .ignoreWidth(true) + .ignoreNumStyle(true) + .ignoreChineseStyle(true) + .ignoreEnglishStyle(true) + .ignoreRepeat(true) + .init(); + + final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。"; + Assert.assertTrue(wordBs.contains(text)); + } + +}