在github上的api叫ToolGood.Words
链接:https://github.com/toolgood/ToolGood.Words/tree/master/java/toolgood.words
1.导入pom依赖
<dependency>
<groupId>io.github.toolgood</groupId>
<artifactId>toolgood-words</artifactId>
<version>3.0.3.1</version>
</dependency>
2、代码处理屏蔽词库
/**
* 做屏蔽词判断和处理
* @param chatMessages
* @return
*/
public String toolgoodWords(String chatMessages){
String path = Thread.currentThread().getContextClassLoader().getResource("屏蔽词所在目录").getPath();
List<String> list= Utils.readTxt(path);
StringSearch search=new StringSearch();
search.SetKeywords(list);
//屏蔽词改为**
String sensiChatMessages=search.Replace(chatMessages,'*');
//判断是否有屏蔽词
boolean boolChatMessages=search.ContainsAny(chatMessages);
return sensiChatMessages;
}
3、屏蔽词库
github链接:https://github.com/toolgood/ToolGood.Words/tree/master/java/toolgood.words