资源简介
fafb53a84c697f74f53ba9cdfb39bd29.rar

代码片段和文件信息
package com.chenssy.keyword;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* @Description: 敏感词过滤
* @Project:test
* @Author : chenming
* @Date : 2014年4月20日 下午4:17:15
* @version 1.0
*/
public class SensitivewordFilter {
@SuppressWarnings(“rawtypes“)
private Map sensitiveWordMap = null;
public static int minMatchTYpe = 1; //最小匹配规则
public static int maxMatchType = 2; //最大匹配规则
/**
* 构造函数,初始化敏感词库
*/
public SensitivewordFilter(){
sensitiveWordMap = new SensitiveWordInit().initKeyWord();
}
/**
* 判断文字是否包含敏感字符
* @author chenming
* @date 2014年4月20日 下午4:28:30
* @param txt 文字
* @param matchType 匹配规则 1:最小匹配规则,2:最大匹配规则
* @return 若包含返回true,否则返回false
* @version 1.0
*/
public boolean isContaintSensitiveWord(String txtint matchType){
boolean flag = false;
for(int i = 0 ; i < txt.length() ; i++){
int matchFlag = this.CheckSensitiveWord(txt i matchType); //判断是否包含敏感字符
if(matchFlag > 0){ //大于0存在,返回true
flag = true;
}
}
return flag;
}
/**
* 获取文字中的敏感词
* @author chenming
* @date 2014年4月20日 下午5:10:52
* @param txt 文字
* @param matchType 匹配规则 1:最小匹配规则,2:最大匹配规则
* @return
* @version 1.0
*/
public Set getSensitiveWord(String txt int matchType){
Set sensitiveWordList = new HashSet();
for(int i = 0 ; i < txt.length() ; i++){
int length = CheckSensitiveWord(txt i matchType); //判断是否包含敏感字符
if(length > 0){ //存在加入list中
sensitiveWordList.add(txt.substring(i i+length));
i = i + length - 1; //减1的原因,是因为for会自增
}
}
return sensitiveWordList;
}
/**
* 替换敏感字字符
* @author chenming
* @date 2014年4月20日 下午5:12:07
* @param txt
* @param matchType
* @param replaceChar 替换字符,默认*
* @version 1.0
*/
public String replaceSensitiveWord(String txtint matchTypeString replaceChar){
String resultTxt = txt;
Set set = getSensitiveWord(txt matchType); //获取所有的敏感词
Iterator iterator = set.iterator();
String word = null;
String replaceString = null;
while (iterator.hasNext()) {
word = iterator.next();
replaceString = getReplaceChars(replaceChar word.length());
resultTxt = resultTxt.replaceAll(word replaceString);
}
return resultTxt;
}
/**
* 获取替换字符串
* @author chenming
* @date 2014年4月20日 下午5:21:19
* @param replaceChar
* @param length
* @return
* @version 1.0
*/
private String getReplaceChars(String replaceCharint length){
String resultReplace = replaceChar;
for(int i = 1 ; i < length ; i++){
resultReplace += replaceChar;
}
return resultReplace;
}
/**
* 检查文字中是否包含敏感字符,检查规则如下:
* @author chenming
* @date 2014年4月20日 下午4:31:03
* @param txt
* @param beginIndex
* @param matchType
* @return,如果存在,则返回敏感词字符的长度,不存在返回0
* @version 1.0
*/
@Suppres
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5173 2014-05-25 14:47 filter\SensitivewordFilter.java
文件 4006 2014-05-25 14:47 filter\SensitiveWordInit.java
文件 176089 2018-09-11 14:09 filter\tb_filter.sql
目录 0 2018-09-11 15:08 filter
----------- --------- ---------- ----- ----
185268 4
相关资源
- GNU/Linux系统开发者需要从桌面突破
- Concurrency in Go(EarlyRelease) 无水印p
- cfx中ccl语言使用手册
- 单元测试一条龙1.50final
- 金丰300T级进冲床电气控制原理图1
- DSP实验(10次实验有详细步骤)
- HP Compaq 8200 Elite 系列商用台式机
- 2019年软考高级下半年信息系统项目管
- Assembly Language for x86 Processors (7th Ed
- Mule基础教程中文版
- 易语言凡哥记事本V1源码易语言凡哥记
- 易语言码表文本加解密模块源码
- DIR2病毒源代码(汇编语言编写)
- ADC0809的采样控制电路的实现.doc
- CRichEditView显示行号的代码
- STM8S代码例程
- 上海交大计算机图形学课程视频31集
- Source Insight 4.0.0080破解文件 替换lic
- Apk加固Demo
- VMware Workstation Pro 15 注册机
- HumanDet(公交车系统模式识别)
- 基于89C51的智能台灯
- 计算机数值分析.rar
- 水晶排课 11.53 破解版
- 51智能排课系统大课表版v5.1.3中文免费
- 用友U8新引入帐套后固定资产模块出错
- Beginning STM32: Developing with FreeRTOS libo
- 土木工程毕业设计(得了95分)
- 土木工程毕业设计 -大连理工大学
- 八重州 7800电路图 高清版
评论
共有 条评论