最主要最主要的文本在此:
链接: https://pan.baidu.com/s/163mWeLecBdV1tA1WstXnuw?pwd=yyds 提取码: yyds 复制这段内容后打开百度网盘手机App,操作更方便哦
工具类代码:就是解析文本进行过滤处理
package com.sense.framework.util;
import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* 敏感词汇过滤替换为*
* 说明:部分代码来源于互联网
*/
@Slf4j
public class WordFilterUtil {
private final static String WORDS = "WORDS";
private final static String REPLACE_CHAR = "*";
private static HashMap sensitiveWordMap;
/**
* 最小匹配规则
*/
private static int minMatchTYpe = 1;
/**
* 最大匹配规则
*/
private static int maxMatchType = 2;
/**
* 敏感词汇过滤替换为* *
*
* @param text 待检测文字
* @return 替换后文字
*/
public static String replaceWords(String text) {
if (StringUtils.isBlank(text)) {
return text;
}
//缓存获取敏感词汇原记录
List<String> words = get(WORDS);
if (CollUtil.isEmpty(words)) {
//读取敏感词汇文件,存入缓存
words = readWordsFile();
put(WORDS, words);
}
if (CollUtil.isEmpty(words)