千龙网站建设,网站系统下载不了文件,wordpress 时尚主题,网站 建设 计划敏感词过滤功能实现
1.GitHub上下载敏感词文件 2.将敏感词文件放在resources目录下 在业务中可以将文本中的敏感词写入数据库便于管理。 3.提供实现类demo 代码编写思路如下#xff1a;1.将敏感词加载到list中#xff0c;2.添加到StringSearch中#xff0c;3.校验#x…敏感词过滤功能实现
1.GitHub上下载敏感词文件 2.将敏感词文件放在resources目录下 在业务中可以将文本中的敏感词写入数据库便于管理。 3.提供实现类demo 代码编写思路如下1.将敏感词加载到list中2.添加到StringSearch中3.校验判断文本是否属于敏感词汇。
import toolgood.words.StringSearch;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;public class TestWords {public static void main(String[] args) {String filePath src/main/resources/sensi_words.txt;try(BufferedReader reader new BufferedReader(new FileReader(filePath))) {String line;ListString list new ArrayList();StringSearch search new StringSearch();while ((line reader.readLine()) ! null){if (!list.contains(line)){list.add(line);}}search.SetKeywords(list);String[] words new String[]{草,草他妈,你是狗,你是做过鸡嘛,干你妈,煞笔,你是shabi,我有点呆};for (int i 0; i words.length; i) {boolean res search.ContainsAny(words[i]);System.out.println(res true ? words[i]:敏感词: words[i]:非敏感词);}System.out.println(---------------------------);for (int i 0; i words.length; i) {//脱敏处理boolean res search.ContainsAny(words[i]);System.out.println(res true ? search.Replace(words[i],*) : words[i]);}} catch (FileNotFoundException e) {throw new RuntimeException(e);} catch (IOException e) {throw new RuntimeException(e);}}
}4.输出结果展示 注意输出结果中敏感词已经进行*号处理