第一次个人编程作业(多算法集成与个人优化)
Requirements
题目:论文查重
 设计一个论文查重算法,给出一个原文文件和一个在这份原文上经过了增删改的抄袭版论文的文件,在答案文件中输出其重复率。
- 原文示例:今天是星期天,天气晴,今天晚上我要去看电影。
 - 抄袭版示例:今天是周天,天气晴朗,我晚上要去看电影。
 
要求输入输出采用文件输入输出,规范如下:
- 从命令行参数给出:论文原文的文件的绝对路径。
 - 从命令行参数给出:抄袭版论文的文件的绝对路径。
 - 从命令行参数给出:输出的答案文件的绝对路径。
 
注意:答案文件中输出的答案为浮点型,精确到小数点后两位
Introduction
| Checker | Time↓ | Accuracy↑ | MEM_COST↓ | 
|---|---|---|---|
| Cosine | 0.47±0.05s | 54.77% | 249.83MB | 
| Jaccard | 0.46±0.02s | 37.50% | 247.69MB | 
| Levenshtein | 0.48±0.2s | 69.77% | 247.80MB | 
| Minhash | 0.46±0.1s | 33.59% | 247.84MB | 
| Simhash | 0.47±0.3s | 34.38% | 248.04MB | 
| Custom | |||
Installation
建议使用anaconda创建Python>=3.9 的虚拟环境.
git clone https://github.com/VjiaLi/202121331021.git
cd 202121331021
pip install -r requirements.txt
但是如果仅仅只是想要完成作业:
git clone https://github.com/VjiaLi/202121331021.git
cd 202121331021/methods
Ctrl+C
Ctrl+V
My Idea
通常来讲,由于欧式距离具有平方与开方的复杂操作,计算开销必然比余弦距离大,但是余弦距离不考虑向量的绝对大小,只关注方向,因此对于某些应用场景可能不够精确,我们需要在这之间有所取舍,所以,我设置了一个超参数去权衡二者之间的关系。
- 数据预处理
 
使用 jieba 去除停用词。
自定义函数提取文本关键字。
- 计算公式
 
\[Similarity =(1 - \alpha)\cdot \text{Cosine} + \alpha \cdot (1 \div{(\text{Euclidean} + 1)})
\]
NOTES: 该优化更注重的是精确度,可能会在计算开销上有所损失
How To Use
Deafalt
使用默认的算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path
Cosine
使用余弦距离算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path --check-method cosine
Jaccard
使用Jaccard算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path --check-method jaccard
Levenshtein
使用Levenshtein算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path --check-method levenshtein
Minhash
使用Minhash算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path --check-method minhash
Simhash
使用Minhash算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path --check-method simhash
Custom
使用自定义算法完成$ python main.py --orig-path your_path --orig-add-path your_path --output your_path --check-method custom
程序流程
异常处理
文件地址输入异常
try:
  ...
except FileNotFoundError as e:
  print(f"文件未找到:{e.filename}")
except IOError as e:
  print(f"文件读写错误:{e}")
except Exception as e:
  print(f"发生未知错误:{e}") 
除零异常
try:
  sim = cosine_similarity(sample)
  return sim[1][0]
except Exception as e:
  print(e)
  return 0.0
性能分析
 NOTES: 主要时间开销在于numpy向量计算,可从该方面入手优化
PSP 表格记录
| PSP2.1 | Personal Software Process Stages | 预估耗时(min) | 实际耗时(min) | 
|---|---|---|---|
| Planning | 计划 | 10 | 5 | 
| Estimate | 估计这个任务需要多少时间 | 5 | 5 | 
| Development | 开发 | 10 | 10 | 
| Analysis | 需求分析 (包括学习新技术) | 5 | 5 | 
| Design Spec | 生成设计文档 | 5 | 3 | 
| Design Review | 设计复审 | 10 | 2 | 
| Coding Standard | 代码规范 | 5 | 5 | 
| Design | 具体设计 | 5 | 5 | 
| Coding | 具体编码 | 10 | 8 | 
| Code Review | 代码复审 | 5 | 5 | 
| Test | 测试 | 5 | 5 | 
| Reporting | 报告 | 10 | 10 | 
| Test Repor | 测试报告 | 5 | 5 | 
| Size Measurement | 计算工作量 | 5 | 5 | 
| Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 5 | 5 | 
| 合计 | 95 | 80 | 
                    
                
                
            
        
浙公网安备 33010602011771号