第二次作业——论文查重

第二次作业3121001738

这个作业属于哪个课程 https://edu.cnblogs.com/campus/gdgy/SoftwareEngineering2024-dualdegree
这个作业要求在哪里 https://edu.cnblogs.com/campus/gdgy/SoftwareEngineering2024-dualdegree/homework/13147
这个作业的目标 设计一个论文查重算法,给出一个原文文件和一个在这份原文上经过了增删改的抄袭版论文的文件,在答案文件中输出其重复率。
其他参考文献 余弦算法,jieba库

git仓库链接

PSP表格

PSP2.1 Personal Software Process Stages 预计耗时(分钟) 实际耗时(分钟)
planning 计划 20 35
· Estimate · 估计这个任务需要多少时间 650 750
Development 开发 60 90
· Analysis · 需求分析 (包括学习新技术) 200 250
· Design Spec · 生成设计文档 30 30
· Design Review · 设计复审 20 25
· Coding Standard · 代码规范 (为目前的开发制定合适的规范) 20 35
· Design · 具体设计 30 60
· Coding · 具体编码 80 100
· Code Review · 代码复审 10 20
· Test · 测试(自我测试,修改代码,提交修改) 45 60
Reporting 报告 20 35
· Test Repor · 测试报告 10 15
· Size Measurement · 计算工作量 5 10
· Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 10 20
· 合计 645 785

代码设计

  • 使用了sys接口来读文件,写文件
import sys
original_file_path = sys.argv[1]
plagiarized_file_path = sys.argv[2]
output_file_path = sys.argv[3]
  • 使用了jieba库来分词
def extract_keywords(text):
    words = jieba.cut(text)
    keywords = [word for word in words if word not in stop_words]
    return " ".join(keywords)
  • 计算余弦相似度
def calculate_cosine_similarity(text1, text2):
    vectorizer = CountVectorizer().fit_transform([text1, text2])
    vectors = vectorizer.toarray()
    return cosine_similarity(vectors[0].reshape(1, -1), vectors[1].reshape(1, -1))[0][0]

性能分析

代码比较简单,时间大部分在命令行输入上,可以考虑一下内置文本可能会更高效一点

异常处理

if len(sys.argv) != 4:
        print("Usage: python main.py <original_text_file> <plagiarized_text_file> <output_file>")
        sys.exit(1)
    else:
        print("输入错误")
posted @ 2024-03-18 22:57  3121001738  阅读(7)  评论(0编辑  收藏  举报