一、gitcode链接
gitcode链接: https://gitcode.net/m0_63558298/3121005193k
二、作业基本描述
这个作业属于哪个课程 | 广工2023软件工程课程社区 |
---|---|
这个作业要求在哪里 | 第一次个人编程作业 |
这个作业的目标 | 实现论文查重的编码 |
其他参考文献 | 使用simhash以及海明距离判断内容相似程度 |
三、PSP表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 10 | 20 |
Estimate | 估计这个任务需要多少时间 | 1280 | 1540 |
Development | 开发 | 240 | 300 |
Analysis | 需求分析 (包括学习新技术) | 240 | 240 |
Design Spec | 生成设计文档 | 60 | 50 |
Design Review | 设计复审 | 40 | 30 |
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 40 | 40 |
Design | 具体设计 | 300 | 420 |
Coding | 具体编码 | 180 | 240 |
Code Review | 代码复审 | 30 | 20 |
Test | 测试(自我测试,修改代码,提交修改) | 30 | 60 |
Test Repor | 测试报告 | 30 | 60 |
Size Measurement | 计算工作量 | 40 | 40 |
Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 40 | 20 |
合计 | 1280 | 1540 |
四、算法的设计及实现过程
1、整体流程
本项目是使用simhash以及海明距离判断内容相似程度 ,以实现文本的查重,包括五个主要过程:分词、Hash、加权、合并、降维。
2、类
- MainPaperCheck:main 方法所在的类,进行cmd的调用
- HammingUtils:计算海明距离的类
- SimHashUtils:计算 SimHash 值的类
- TxtIOUtils:读写 txt 文件的工具类
- ShortStringException:处理文本内容过短的异常类
- test包:单元测试类
五、性能改进
由各个性能测试图可以得出,单个测试都没有超过5s的,符合要求,性能良好,并不需要改进。
消耗最大的是调用的一个外部的包。
六、单元测试展示
- 单元测试
@Test
public void origAndAllTest() {
String[] str = new String[6];
str[0] = TxtIOUtils.readTxt("C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\orig.txt");
str[1] = TxtIOUtils.readTxt("C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\orig_0.8_add.txt");
str[2] = TxtIOUtils.readTxt("C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\orig_0.8_del.txt");
str[3] = TxtIOUtils.readTxt("C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\orig_0.8_dis_1.txt");
str[4] = TxtIOUtils.readTxt("C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\orig_0.8_dis_10.txt");
str[5] = TxtIOUtils.readTxt("C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\orig_0.8_dis_15.txt");
String ansFileName = "C:\\Users\\16401\\Desktop\\text\\PaperCheck\\测试文本\\ans.txt";
for (int i = 0; i <= 5; i++) {
double ans = HammingUtils.getSimilarity(SimHashUtils.getSimHash(str[0]), SimHashUtils.getSimHash(str[i]));
TxtIOUtils.writeTxt(ans, ansFileName);
}
}
- cmd输入输出
- 覆盖率
七、异常处理说明
当文本长度过短时,HanLp无法取得关键字,需要抛出异常。
try{
if(str.length() < 200) throw new ShortStringException("文本过短!");
}catch (ShortStringException e){
e.printStackTrace();
return null;
}