From 855659a864bd98999cf472e0c20e5c8c194b0d6a Mon Sep 17 00:00:00 2001 From: bbhou <1557740299@qq.com> Date: Thu, 25 Dec 2025 00:46:58 +0800 Subject: [PATCH] [Feature] add for new --- CHANGE_LOG.md | 8 ++++++- README.md | 3 ++- pom.xml | 2 +- release.bat | 4 ++-- .../sensitive/word/bs/SensitiveWordBs.java | 2 +- .../resultcondition/WordResultConditions.java | 9 ++++++++ .../word/bs/SensitiveWordBsTest.java | 22 +++++++++++++++++++ 7 files changed, 44 insertions(+), 6 deletions(-) diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index 8ef766c..fe3d6a2 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -482,4 +482,10 @@ | 序号 | 变更类型 | 说明 | 时间 | 备注 | |:---|:-----|----------------|:------------------|:--------| -| 1 | O | opencc4j 简化繁简体 | 2025-9-6 16:22:24 | 优化性能+内存 | \ No newline at end of file +| 1 | O | opencc4j 简化繁简体 | 2025-9-6 16:22:24 | 优化性能+内存 | + +# release_0.29.4 + +| 序号 | 变更类型 | 说明 | 时间 | 备注 | +|:---|:-----|------------|:--------------------|:-----------| +| 1 | O | 默认改为英文全词匹配 | 2025-12-25 00:37:52 | 更加符合实际使用场景 | \ No newline at end of file diff --git a/README.md b/README.md index 820da7d..b3536b8 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ v0.24.0 开始内置支持对敏感词的分类细化,不过工作量比较大 com.github.houbb sensitive-word - 0.29.2 + 0.29.4 ``` @@ -767,6 +767,7 @@ WordResultConditions 工具类可以获取匹配策略 | 实现 | 说明 | 支持版本 | |:-------------------------------------------|:--------------------|:--------| +| defaults | 默认策略 | v0.29.4 | | alwaysTrue | 恒为真 | | | englishWordMatch | 英文单词全词匹配 | v0.13.0 | | englishWordNumMatch | 英文单词/数字全词匹配 | v0.20.0 | diff --git a/pom.xml b/pom.xml index 64ff298..1f3fb37 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.houbb sensitive-word - 0.29.3 + 0.29.4 diff --git a/release.bat b/release.bat index 7d2660b..9ba7979 100644 --- a/release.bat +++ b/release.bat @@ -10,9 +10,9 @@ ECHO "============================= RELEASE START..." :: 版本号信息(需要手动指定) :::: 旧版本名称 -SET version=0.28.0 +SET version=0.29.4 :::: 新版本名称 -SET newVersion=0.29.0 +SET newVersion=0.29.4 :::: 组织名称 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 f09c77e..a7b3091 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 @@ -189,7 +189,7 @@ public class SensitiveWordBs implements ISensitiveWordDestroy { * 敏感词结果匹配策略 * @since 0.13.0 */ - private IWordResultCondition wordResultCondition = WordResultConditions.alwaysTrue(); + private IWordResultCondition wordResultCondition = WordResultConditions.defaults(); /** * 单词检测策略 diff --git a/src/main/java/com/github/houbb/sensitive/word/support/resultcondition/WordResultConditions.java b/src/main/java/com/github/houbb/sensitive/word/support/resultcondition/WordResultConditions.java index 00742a5..9cae043 100644 --- a/src/main/java/com/github/houbb/sensitive/word/support/resultcondition/WordResultConditions.java +++ b/src/main/java/com/github/houbb/sensitive/word/support/resultcondition/WordResultConditions.java @@ -14,6 +14,15 @@ import java.util.List; */ public final class WordResultConditions { + /** + * 默认策略 + * @return 结果 + * @since 0.29.4 + */ + public static IWordResultCondition defaults() { + return englishWordMatch(); + } + /** * 恒为真 * @return 结果 diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java index f17dda8..52a0104 100644 --- a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java +++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java @@ -1,11 +1,15 @@ package com.github.houbb.sensitive.word.bs; +import com.github.houbb.sensitive.word.api.IWordDeny; import com.github.houbb.sensitive.word.support.allow.WordAllows; import com.github.houbb.sensitive.word.support.deny.WordDenys; import com.github.houbb.sensitive.word.support.replace.WordReplaces; +import com.github.houbb.sensitive.word.support.resultcondition.WordResultConditions; import org.junit.Assert; import org.junit.Test; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -114,4 +118,22 @@ public class SensitiveWordBsTest { Assert.assertTrue(wordBs.contains(text)); } + /** + * 是否包含 + * @since 0.29.4 + */ + @Test + public void wordMatchTest() { + IWordDeny wordDeny = new IWordDeny() { + @Override + public List deny() { + return Arrays.asList("av"); + } + }; + final String text = "have a nice day"; + + Assert.assertFalse(SensitiveWordBs.newInstance().wordDeny(wordDeny).init().contains(text)); + Assert.assertTrue(SensitiveWordBs.newInstance().wordDeny(wordDeny).wordResultCondition(WordResultConditions.alwaysTrue()).init().contains(text)); + } + }