敏感词过滤方案汇总以及高效工具sensitive-word
导入pom文件
c
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>sensitive-word</artifactId>
<version>0.12.0</version>
</dependency>
接下来我们编写相关测试类,来测试对应方法
c
final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前";
//判断是否包含敏感词
boolean result = SensitiveWordHelper.contains(text);
System.out.println(result);
//返回第一个敏感词
String word = SensitiveWordHelper.findFirst(text);
System.out.println(word);
//返回所有敏感词
List<String> wordList = SensitiveWordHelper.findAll(text);
System.out.println(wordList);
//默认的替换策略
String replace = SensitiveWordHelper.replace(text);
System.out.println(replace);
//指定替换内容
String replace1 = SensitiveWordHelper.replace(text, '0');
System.out.println(replace1);