第一次个人编程作业
这个作业属于哪个课程 | 软件工程 |
---|---|
这个作业要求在哪里 | 作业要求 |
这个作业的目标 | 论文查重算法设计 + 单元测试 +性能测试+ PSP表格 + Git管理 |
-
作业代码链接(JAVA)
GitHub地址
-
最短编辑距离原理
-
计算模块接口的设计与实现过程
整体流程
通过命令行接收原文和抄袭文本、结果输出文本的路径
对两个输入文本的内容进行处理(CheckSimilarity类、StringFilter类)
计算出两个输入文本内容的相似度并输出到输出文本(GetSimilarity类)
流程图
类之间 方法之间的关系
主要方法
主要的类
命令行运行结果
(orig_0.8_add和orig_0.8_del)
最小编辑距离算法
-
计算模块接口部分改进
计算模块性能上所花费的时间
改进前
改进后
改进思路
去掉文本中的标点符号,提高查重的准确率
性能分析图
改进前
改进前准确率
改进后
改进后准确率
程序中消耗最大的函数
-
计算模块部分单元测试展示
public class CheckSimilarityTest { @Before public void setUp() throws Exception { System.out.println("CheckSimilarityTest测试开始"); } @After public void tearDown() throws Exception { System.out.println("CheckSimilarityTest测试结束"); } /** * 测试 文本为空 * src/empty.txt */ @Test public void checkSimilarity_Empty() { CheckSimilarity c1=new CheckSimilarity(); try { c1.checkSimilarity(new File("src/empty.txt"),new File("src/orig.txt"),new File("src/result_empty")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败,文本为空"); Assert.fail(); } } /** * 测试 输入文本路径不存在或错误 * rc/orig_non_existent.txt */ @Test public void checkSimilarity_Non_Existent() { CheckSimilarity c2=new CheckSimilarity(); try { c2.checkSimilarity(new File("src/orig_non_existent.txt"),new File("src/orig.txt"),new File("src/result_non_existent")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败,文本路径不存在"); Assert.fail(); } } /** * 测试 输入的两个查重文本为相同文本 * orig.txt */ @Test public void checkSimilarity_Same(){ CheckSimilarity c3=new CheckSimilarity(); try { c3.checkSimilarity(new File("src/orig.txt"),new File("src/orig.txt"),new File("src/result_same")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig.txt和orig_0.8_add.txt(添加) */ @Test public void checkSimilarity_Add(){ CheckSimilarity c4=new CheckSimilarity(); try { c4.checkSimilarity(new File("src/orig.txt"),new File("src/orig_0.8_add.txt"),new File("src/result_add")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig.txt和orig_0.8_del.txt(删减) */ @Test public void checkSimilarity_Delete(){ CheckSimilarity c5=new CheckSimilarity(); try { c5.checkSimilarity(new File("src/orig.txt"),new File("src/orig_0.8_del.txt"),new File("src/result_delete")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig.txt和orig_0.8_dis_1.txt */ @Test public void checkSimilarity_dis_1(){ CheckSimilarity c6=new CheckSimilarity(); try { c6.checkSimilarity(new File("src/orig.txt"),new File("src/orig_0.8_dis_1.txt"),new File("src/result_dis_1")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig.txt和orig_0.8_dis_10.txt */ @Test public void checkSimilarity_dis_10(){ CheckSimilarity c6=new CheckSimilarity(); try { c6.checkSimilarity(new File("src/orig.txt"),new File("src/orig_0.8_dis_10.txt"),new File("src/result_dis_10")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig.txt和orig_0.8_dis_15.txt */ @Test public void checkSimilarity_dis_15(){ CheckSimilarity c7=new CheckSimilarity(); try { c7.checkSimilarity(new File("src/orig.txt"),new File("src/orig_0.8_dis_15.txt"),new File("src/result_dis_15")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig_0.8_add.txt和orig_0.8_del.txt */ @Test public void checkSimilarity_dis_add_del(){ CheckSimilarity c8=new CheckSimilarity(); try { c8.checkSimilarity(new File("src/orig_0.8_add.txt"),new File("src/orig_0.8_del.txt"),new File("src/result_add_del")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig_0.8_dis_1.txt和orig_0.8_dis_15.txt */ @Test public void checkSimilarity_dis_1_15(){ CheckSimilarity c9=new CheckSimilarity(); try { c9.checkSimilarity(new File("src/orig_0.8_dis_1.txt"),new File("src/orig_0.8_dis_15.txt"),new File("src/result_dis_1_15")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } /** * 测试 * orig_0.8_add.txt和orig_0.8_dis_1.txt */ @Test public void checkSimilarity_dis_add_dis_1(){ CheckSimilarity c10=new CheckSimilarity(); try { c10.checkSimilarity(new File("src/orig_0.8_add.txt"),new File("src/orig_0.8_dis_1.txt"),new File("src/result_dis_add_dis")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); } } }
-
计算模块部分异常处理说明
1、I/O异常处理
try (FileWriter writer = new FileWriter(file3)) { writer.write(String.format("%.2f",gS1)+"%"); //System.out.println("成功"); } catch (Exception e) { e.printStackTrace(); }
try { c3.checkSimilarity(new File("src/orig.txt"),new File("src/orig.txt"),new File("src/result_same")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败"); Assert.fail(); }
try { c2.checkSimilarity(new File("src/orig_non_existent.txt"),new File("src/orig.txt"),new File("src/result_non_existent")); } catch (IOException e) { e.printStackTrace(); System.out.println("测试失败,文本路径不存在"); Assert.fail(); }
由try/catch捕获异常
2、参数异常检查
while((Str = f1.readLine()) != null){//将文本转化为String Str1.append(Str).append("\r\n"); } while ((Str = f2.readLine())!=null){ Str2.append(Str).append("\r\n"); }
检查null或参数缺失
-
PSP表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 30 |
·Estimate | ·估计这个任务需要多少时间 | 600 | 800 |
Development | 开发 | 60 | 45 |
·Analysis | 需求分析(包括学习新技术) | 60 | 100 |
·Design Spec | ·生成设计文档 | 40 | 30 |
·Design Review | ·设计复审 | 30 | 30 |
·Coding Standard | ·代码规范(为目前的开发制定合适的规范) | 20 | 20 |
·Design | ·具体设计 | 120 | 100 |
·Coding | ·具体编码 | 300 | 330 |
·Code Review | ·代码复审 | 20 | 20 |
·Test | ·测试(自我测试,修改代码,提交修改) | 100 | 120 |
Reorting | 报告 | 90 | 90 |
·Test Report | ·测试报告 | 60 | 30 |
·Size Measurement | ·计算工作量 | 60 | 90 |
·Postmortem&Process Improvement Plan | ·事后总结,并提出过程改进计划 | 90 | 180 |
合并1680 | 2015 |