新闻中心

EEPW首页 > 手机与无线通信 > 设计应用 > 基于Java的脏字过滤器设计

基于Java的脏字过滤器设计

作者:时间:2012-09-20来源:网络收藏

//字库中关键词个数
}
} else {
//提示用户按回车键
System.out.println(你还没有输入回
车键信息);
}
}
} catch (IOException e) {
e.printStackTrace();
}

//输出查询结果
if (ans != null) {
System.out.println(字库中关键词个数:+ cnt);//字库中关键词个数
System.out.println(脏字库内容如下:+ ans);
} else {
System.out.println(没有可以匹配的信息);
//输出脏字库中的内容
}
}

本文引用地址://m.amcfsurvey.com/article/153895.htm

//得到指定路径文件中的内容
private static String getcontent(String filepath) {
String all = ;
File file = new File(filepath);
try {
if (!file.isFile()) {
System.out.println(文件路径不对,请修改路径);
} else {
File readfile = new File(filepath);
BufferedReader br = new BufferedReader(new FileReader(readfile));
String ss = br.readLine();
while (ss != null) {
all = all + ss;
//all中存放读取的文件内容信息
ss = br.readLine();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return all;
}

//在待测文件中匹配脏字出现的次数
private static int searchkeyword(String[] str, int cnt, String filepath){
int number = 0;
String s = ;
s = getcontent(filepath);
for (int i = 0; i cnt; i++) {
if (s.indexOf(str[i]) > -1) {
number++;
}
}
return number;
}
至此,完成了脏字软件代码的编写工作,接下来可以进行run操作,即可以得到待测文件库中的待测文件包含脏字次数及出处等相关信息的结果。

3 实验结果分析

脏字库的存放路径:D:脏字典file.txt;脏字库文件中的内容略。

待测文件库的存放路径:D:脏字待测文件库;文件库中存放了三个文件,分别为:test1.txt、test2.txt、test3.txt。

运行该软件后,得出的检测结果如图2所示。

由图可以看到把待测文件中脏字及脏词组出现的次数全部显示出来,结果与实际情况完全一致。
本文的脏字软件,已在myeclipse环境下通过语言实现,并对整个过滤器软件进行了测试,测试结果显示该完全可以达到对网页文件中的脏字进行过滤,还能指出这些脏字的数目及其出处。为网络管理员的管理带来方便,并给网络管理方面的编程人员提供了一个良好的开发平台。


上一页 1 2 下一页

关键词: 设计 过滤器 Java 基于

评论


相关推荐

技术专区

关闭