• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

tttttjc798

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

工程概论作业二——论文查重

Github链接:https://github.com/tttttjc/tttttjc/tree/main/202121331068

作业要求

这个作业属于哪个课程 工程概论
这个作业要求在哪里 作业要求
这个作业的目标 学习项目搭建,学习GitHub的运用,学习设计论文查重代码

需求分析

题目:论文查重

描述如下:

设计一个论文查重算法,给出一个原文文件和一个在这份原文上经过了增删改的抄袭版论文的文件,在答案文件中输出其重复率。

原文示例:今天是星期天,天气晴,今天晚上我要去看电影。
抄袭版示例:今天是周天,天气晴朗,我晚上要去看电影。
要求输入输出采用文件输入输出,规范如下:

从命令行参数给出:论文原文的文件的绝对路径。
从命令行参数给出:抄袭版论文的文件的绝对路径。
从命令行参数给出:输出的答案文件的绝对路径。
我们提供一份样例,课堂上下发,上传到班级群,使用方法是:orig.txt是原文,其他orig_add.txt等均为抄袭版论文。

注意:答案文件中输出的答案为浮点型,精确到小数点后两位

算法设计

1.读取文本

def read_text(path):
str = ''
file = open(path, 'r', encoding='UTF-8') #打开文件,以 UTF-8 编码方式处理
line = file.readline()
while line:
str += line
line = file.readline()
//读取文件的一行,然后将“指针”移动到\n的后面
file.close()
return str

2.文本清洗和分词

def text_clean(str):
pattern = re.compile(u"[^a-zA-Z0-9\u4e00-\u9fa5]")
str = pattern.sub("",str)
//文本清洗。定义正则表达式匹配模式,其中^匹配字符串的开头,保留a-z、A-Z、0-9和汉字
new = []
new = [i for i in jieba.cut(str, cut_all=False) if i != ''] //进行分词。cut_all=False精确
return new

3.通过余弦计算两个向量的相似度

对于两个向量 a,b可以用其夹角余弦表示其近似的程度(公式如下):

两个向量夹角余弦值就是两个向量的余弦相似度
def cos(new1,new2):
word_set = set(new1).union(set(new2))
word_dict = dict()
i = 0
for word in word_set:
word_dict[word] = i
i += 1
text1_cut_index = [word_dict[word] for word in new1]
text2_cut_index = [word_dict[word] for word in new2]
text1_cut_index = [0]len(word_dict)
text2_cut_index = [0]
len(word_dict)
for word in new1:
text1_cut_index[word_dict[word]] += 1
for word in new2:
text2_cut_index[word_dict[word]] += 1
sum = 0
sq1 = 0
sq2 = 0
for i in range(len(text1_cut_index)):
sum += text1_cut_index[i] * text2_cut_index[i]
sq1 += pow(text1_cut_index[i], 2)
sq2 += pow(text2_cut_index[i], 2)
try:
cos_result = round(float(sum) / (math.sqrt(sq1) * math.sqrt(sq2)), 2)
except ZeroDivisionError:
cos_result = 0.0
return cos_result

开发环境

python

流程设计

单元测试模块

PSP表格记录

PSP2.1 Personal Software Process Stages 预估耗时(min) 实际耗时(min)
Planning 计划 100 100
Estimate 估计这个任务需要多少时间 20 20
Development 开发 320 320
Analysis 需求分析 (包括学习新技术) 180 180
Design Spec 生成设计文档 10 10
Design Review 设计复审 10 10
Coding Standard 代码规范 30 30
Design 具体设计 30 30
Coding 具体编码 180 190
Code Review 代码复审 15 15
Test 测试 20 20
Reporting 报告 40 40
Test Repor 测试报告 10 10
Size Measurement 计算工作量 10 10
Postmortem & Process Improvement Plan 事后总结, 并提出过程改进计划 5 5
合计 980 990

posted on 2023-09-20 19:37  tttttjc把爱留在798  阅读(67)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3