工程概论--第一次个人编程作业
1.作业要求
这个作业属于哪个课程 | 工程概论 |
---|---|
这个作业要求在哪里 | 个人项目 |
这个作业的目标 | 初步学习github使用,设计查重代码 |
2.需求分析
题目:论文查重
描述如下:
设计一个论文查重算法,给出一个原文文件和一个在这份原文上经过了增删改的抄袭版论文的文件,在答案文件中输出其重复率。
原文示例:今天是星期天,天气晴,今天晚上我要去看电影。
抄袭版示例:今天是周天,天气晴朗,我晚上要去看电影。
要求输入输出采用文件输入输出,规范如下:
从命令行参数给出:论文原文的文件的绝对路径。
从命令行参数给出:抄袭版论文的文件的绝对路径。
从命令行参数给出:输出的答案文件的绝对路径。
我们提供一份样例,课堂上下发,上传到班级群,使用方法是:orig.txt是原文,其他orig_add.txt等均为抄袭版论文。
注意:答案文件中输出的答案为浮点型,精确到小数点后两位
3.开发环境
编译环境: vscode
编译语言:C
4.设计流程
5.核心算法
余弦相似度算法
计算由两个文本生成的向量的余弦,进行判断重复度,越接近1重复度越高
float calculateCos(char *orig, char *orig_add) {
char *words1[MAX_WORDS];
char *words2[MAX_WORDS];
int count1, count2;
count1 = tokenizeText(orig, words1);
count2 = tokenizeText(orig_add, words2);
int wordCount1[MAX_WORDS] = {0};
int wordCount2[MAX_WORDS] = {0};
// 统计每个单词在文本1中出现的次数
for (int i = 0; i < count1; i++) {
for (int j = 0; j < count1; j++) {
if (strcmp(words1[i], words1[j]) == 0) {
wordCount1[i]++;
}
}
}
// 统计每个单词在文本2中出现的次数
for (int i = 0; i < count2; i++) {
for (int j = 0; j < count2; j++) {
if (strcmp(words2[i], words2[j]) == 0) {
wordCount2[i]++;
}
}
}
float dotProduct = 0;
float sumSquares1 = 0;
float sumSquares2 = 0;float calculateCos(char *orig, char *orig_add) {
char *words1[MAX_WORDS];
char *words2[MAX_WORDS];
int count1, count2;
count1 = tokenizeText(orig, words1);
count2 = tokenizeText(orig_add, words2);
int wordCount1[MAX_WORDS] = {0};
int wordCount2[MAX_WORDS] = {0};
// 统计每个单词在文本1中出现的次数
for (int i = 0; i < count1; i++) {
for (int j = 0; j < count1; j++) {
if (strcmp(words1[i], words1[j]) == 0) {
wordCount1[i]++;
}
}
}
// 统计每个单词在文本2中出现的次数
for (int i = 0; i < count2; i++) {
for (int j = 0; j < count2; j++) {
if (strcmp(words2[i], words2[j]) == 0) {
wordCount2[i]++;
}
}
}
float dotProduct = 0;
float sumSquares1 = 0;
float sumSquares2 = 0;
6.异常处理
if (file1 == NULL || file2 == NULL) {
printf("无法打开文件\n");
return 1;
7.PSP表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 10 | 10 |
.Estimate | · 估计这个任务需要多少时间 | 300 | 375 |
Development | 开发 | 200 | 220 |
.Analysis | · 需求分析 (包括学习新技术) | 10 | 5 |
· Design Spec | · 生成设计文档 | 5 | 5 |
· Design Review | · 设计复审 | 20 | 10 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 5 | 5 |
· Design | · 具体设计 | 20 | 15 |
· Coding | · 具体编码 | 30 | 30 |
· Code Review | · 代码复审 | 10 | 10 |
· Test | · 测试(自我测试,修改代码,提交修改) | 10 | 5 |
Reporting | 报告 | 20 | 15 |
· Test Repor | · 测试报告 | 5 | 5 |
· Size Measurement | · 计算工作量 | 5 | 5 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 5 | 5 |
· 合计 | 300 | 345 |