mirror of
https://github.com/houbb/sensitive-word.git
synced 2026-03-22 00:17:35 +08:00
[Feature] add for new
This commit is contained in:
@@ -483,3 +483,9 @@
|
||||
| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|
||||
|:---|:-----|----------------|:------------------|:--------|
|
||||
| 1 | O | opencc4j 简化繁简体 | 2025-9-6 16:22:24 | 优化性能+内存 |
|
||||
|
||||
# release_0.29.4
|
||||
|
||||
| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|
||||
|:---|:-----|------------|:--------------------|:-----------|
|
||||
| 1 | O | 默认改为英文全词匹配 | 2025-12-25 00:37:52 | 更加符合实际使用场景 |
|
||||
@@ -110,7 +110,7 @@ v0.24.0 开始内置支持对敏感词的分类细化,不过工作量比较大
|
||||
<dependency>
|
||||
<groupId>com.github.houbb</groupId>
|
||||
<artifactId>sensitive-word</artifactId>
|
||||
<version>0.29.2</version>
|
||||
<version>0.29.4</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -767,6 +767,7 @@ WordResultConditions 工具类可以获取匹配策略
|
||||
|
||||
| 实现 | 说明 | 支持版本 |
|
||||
|:-------------------------------------------|:--------------------|:--------|
|
||||
| defaults | 默认策略 | v0.29.4 |
|
||||
| alwaysTrue | 恒为真 | |
|
||||
| englishWordMatch | 英文单词全词匹配 | v0.13.0 |
|
||||
| englishWordNumMatch | 英文单词/数字全词匹配 | v0.20.0 |
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.github.houbb</groupId>
|
||||
<artifactId>sensitive-word</artifactId>
|
||||
<version>0.29.3</version>
|
||||
<version>0.29.4</version>
|
||||
|
||||
<properties>
|
||||
<!--============================== All Plugins START ==============================-->
|
||||
|
||||
@@ -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
|
||||
:::: 项目名称
|
||||
|
||||
@@ -189,7 +189,7 @@ public class SensitiveWordBs implements ISensitiveWordDestroy {
|
||||
* 敏感词结果匹配策略
|
||||
* @since 0.13.0
|
||||
*/
|
||||
private IWordResultCondition wordResultCondition = WordResultConditions.alwaysTrue();
|
||||
private IWordResultCondition wordResultCondition = WordResultConditions.defaults();
|
||||
|
||||
/**
|
||||
* 单词检测策略
|
||||
|
||||
@@ -14,6 +14,15 @@ import java.util.List;
|
||||
*/
|
||||
public final class WordResultConditions {
|
||||
|
||||
/**
|
||||
* 默认策略
|
||||
* @return 结果
|
||||
* @since 0.29.4
|
||||
*/
|
||||
public static IWordResultCondition defaults() {
|
||||
return englishWordMatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 恒为真
|
||||
* @return 结果
|
||||
|
||||
@@ -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<String> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user