package com.net.test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
/** 敏感词集合
* {法={isEnd=0, 轮={isEnd=1}}, 中={isEnd=0, 国={isEnd=0, 人={isEnd=1}, 男={isEnd=0, 人={isEnd=1}}}}}
* */
private HashMap keysMap = new HashMap();
/**
* 添加敏感词
* @param keywords
*/
public void addKeywords(List<String> keywords) {
for (int i = 0; i < keywords.size(); i++) {
String key = keywords.get(i).trim();
HashMap nowhash = keysMap;//初始从最外层遍历
for (int j = 0; j < key.length(); j++) {
char word = key.charAt(j);
Object wordMap = nowhash.get(word);
if (wordMap != null) {
nowhash = (HashMap) wordMap;
} else {
HashMap<String, String> newWordHash = new HashMap<String, String>();
newWordHash.put("isEnd", "0");
nowhash.put(word, newWordHash);
nowhash = newWordHash;
}
if (j == key.length() - 1) {
nowhash.put("isEnd", "1");
}
}
}
}
/**
* 检查一个字符串从begin位置起开始是否有keyword符合,
* 如果没有,则返回0
* 如果有符合的keyword值,继续遍历,直至遇到isEnd = 1,返回匹配的keyword的长度,
*/
private int checkKeyWords(String txt, int begin) {
HashMap nowhash = keysMap;
int res = 0;
for (int i = begin; i < txt.length(); i++) {
char word = txt.charAt(i);
Object wordMap = nowhash.get(word);//得到该字符对应的HashMap
if (wordMap == null) {
return 0;//如果该字符没有对应的HashMap,return 0
}
res++;//如果该字符对应的HashMap不为null,说明匹配到了一个字符,+1
nowhash = (HashMap) wordMap;//将遍历的HashMap指向该字符对应的HashMap
if (((String) nowhash.get("isEnd")).equals("1")) {//如果该字符为敏感词的结束字符,直接返回
return res;
} else {
continue;
}
}
return res;
}
/**
* 判断txt中是否有关键字
*/
public boolean isContentKeyWords(String txt) {
for (int i = 0; i < txt.length(); i++) {
int len = checkKeyWords(txt, i);
if (len > 0) {
return true;
}
}
return false;
}
/**
* 返回txt中关键字的列表
*/
public List<String> getTxtKeyWords(String txt) {
List<String> list = new ArrayList<String>();
int l = txt.length();
for (int i = 0; i < l;) {
int len = checkKeyWords(txt, i);
if (len > 0) {
String tt = txt.substring(i, i + len);
list.add(tt);
i += len;
} else {
i++;
}
}
return list;
}
/**
* 初始化敏感词列表
* */
public void initfiltercode() {
List<String> keywords = new ArrayList<String>();
keywords.add("中国人:1");
keywords.add("中国男人:1");
keywords.add("法轮:1");
this.addKeywords(keywords);
}
public static void main(String[] args) throws IOException {
/*Test filter = new Test();
filter.initfiltercode();
String txt = "反倒是 法轮热舞功,中国人";
boolean boo = filter.isContentKeyWords(txt);
System.out.println(boo);
List<String> set = filter.getTxtKeyWords(txt);
System.out.println(txt+"中包含的敏感词如下:" + set);*/
List list = new ArrayList();
list.add("中国人");
list.add("中国男人");
list.add("法轮");
list.add("反共");
Map dataMap = new HashMap();
dataMap.put("data", list);
dataMap.put("sign", "1");
System.out.println(dataMap);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于openfir的javaweb版本的聊天
共649个文件
svn-base:407个
gif:103个
bmp:99个
需积分: 5 8 下载量 5 浏览量
2015-11-17
17:28:55
上传
评论
收藏 5.98MB RAR 举报
温馨提示
基于openfire的javaweb版本的客服聊天工具,里面的jar和js都齐全只需要修改自己的openfire服务器名字即可,深入的功能需要自己动手开发和搭建。
资源推荐
资源详情
资源评论
收起资源包目录
基于openfir的javaweb版本的聊天 (649个子文件)
all-wcprops 65KB
all-wcprops 2KB
66fixed.bmp 2KB
12fixed.bmp 2KB
74fixed.bmp 2KB
67fixed.bmp 2KB
7fixed.bmp 2KB
47fixed.bmp 2KB
18fixed.bmp 2KB
34fixed.bmp 2KB
45fixed.bmp 2KB
2fixed.bmp 2KB
16fixed.bmp 2KB
72fixed.bmp 2KB
93fixed.bmp 2KB
39fixed.bmp 2KB
31fixed.bmp 2KB
70fixed.bmp 2KB
42fixed.bmp 2KB
76fixed.bmp 2KB
6fixed.bmp 2KB
63fixed.bmp 2KB
3fixed.bmp 2KB
88fixed.bmp 2KB
53fixed.bmp 2KB
10fixed.bmp 2KB
95fixed.bmp 2KB
87fixed.bmp 2KB
4fixed.bmp 2KB
9fixed.bmp 2KB
64fixed.bmp 2KB
5fixed.bmp 2KB
28fixed.bmp 2KB
48fixed.bmp 2KB
82fixed.bmp 2KB
38fixed.bmp 2KB
13fixed.bmp 2KB
61fixed.bmp 2KB
22fixed.bmp 2KB
73fixed.bmp 2KB
8fixed.bmp 2KB
69fixed.bmp 2KB
50fixed.bmp 2KB
19fixed.bmp 2KB
56fixed.bmp 2KB
1fixed.bmp 2KB
51fixed.bmp 2KB
41fixed.bmp 2KB
98fixed.bmp 2KB
75fixed.bmp 2KB
84fixed.bmp 2KB
27fixed.bmp 2KB
20fixed.bmp 2KB
40fixed.bmp 2KB
44fixed.bmp 2KB
96fixed.bmp 2KB
30fixed.bmp 2KB
35fixed.bmp 2KB
65fixed.bmp 2KB
21fixed.bmp 2KB
17fixed.bmp 2KB
62fixed.bmp 2KB
26fixed.bmp 2KB
86fixed.bmp 2KB
37fixed.bmp 2KB
49fixed.bmp 2KB
23fixed.bmp 2KB
25fixed.bmp 2KB
0fixed.bmp 2KB
32fixed.bmp 2KB
58fixed.bmp 2KB
80fixed.bmp 2KB
59fixed.bmp 2KB
43fixed.bmp 2KB
15fixed.bmp 2KB
89fixed.bmp 2KB
11fixed.bmp 2KB
90fixed.bmp 2KB
36fixed.bmp 2KB
57fixed.bmp 2KB
79fixed.bmp 2KB
91fixed.bmp 2KB
33fixed.bmp 2KB
71fixed.bmp 2KB
81fixed.bmp 2KB
92fixed.bmp 2KB
85fixed.bmp 2KB
60fixed.bmp 2KB
14fixed.bmp 2KB
77fixed.bmp 2KB
54fixed.bmp 2KB
68fixed.bmp 2KB
83fixed.bmp 2KB
97fixed.bmp 2KB
78fixed.bmp 2KB
55fixed.bmp 2KB
94fixed.bmp 2KB
46fixed.bmp 2KB
29fixed.bmp 2KB
52fixed.bmp 2KB
共 649 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
litiangang1989
- 粉丝: 2
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功