优秀的结对队友:乐忠豪html
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 90 | 150 |
· Estimate | · 估计这个任务须要多少时间 | 90 | 150 |
Development | 开发 | 780 | 740 |
· Analysis | · 需求分析 (包括学习新技术) | 200 | 240 |
· Design Spec | · 生成设计文档 | 0 | 0 |
· Design Review | · 设计复审 | 10 | 20 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 0 | 0 |
· Design | · 具体设计 | 60 | 90 |
· Coding | · 具体编码 | 360 | 180 |
· Code Review | · 代码复审 | 30 | 60 |
· Test | · 测试(自我测试,修改代码,提交修改) | 120 | 150 |
Reporting | 报告 | 25 | 40 |
· Test Repor | · 测试报告 | 0 | 0 |
· Size Measurement | · 计算工做量 | 5 | 10 |
· Postmortem & Process Improvement Plan | · 过后总结, 并提出过程改进计划 | 20 | 30 |
合计 | 895 | 930 |
首先先对论文列表网页爬取每篇论文的网址python
def getWebInfo(url):#获取网页中的内容 try: r = requests.get(url) r.raise_for_status() r.encoding = r.apparent_encoding except: print("request error") demo = r.text soup = BeautifulSoup(demo,"html.parser") return soup url = "http://openaccess.thecvf.com/CVPR2018.py" soup = getWebInfo(url) papersInfo = soup.find_all('dt')#每篇论文的网址造成的list
而后对每一篇论文的网页爬取相对应信息并进行正则表达式去除网页标签最后得到标题和摘要并写入到文件中git
def getPaperInfo(paperLink):#获取论文主页的内容 url = "http://openaccess.thecvf.com/" + paperLink soup = getWebInfo(url) re_h=re.compile('</?\w+[^>]*>')#HTML标签 #利用正则表达式去除网页内容中的标签 title =re_h.sub('', str(soup.find('div',id="papertitle"))).strip() abstract = re_h.sub('',str(soup.find('div',id="abstract"))).strip() author = re_h.sub('',str(soup.find('i'))).strip().split(', ') return title,abstract,author with open(filename,'w',encoding='utf-8') as outfile: for paperInfo in papersInfo: title,abstract,author = getPaperInfo(paperInfo.find('a').get('href')) outfile.write(str(i)+'\r\n') i = i+1 outfile.write('Title: '+title+'\r\n') outfile.write('Abstract: '+abstract+'\r\n\r\n\r\n')
结构图以下:github
组织结构:根据需求实现4个功能(词频统计、行数统计、单词数统计、字符数统计),共4个头文件分别实现。函数接口以下:正则表达式
int CountWords(char *filename) //统计单词数 int CountLines(char *filename) //统计行数 int CountChars(char *filename) //统计字符数 void CountWf(char *filename, ofstream &fout,char* outfile,int topNum,int itemLenth,int weight_Pid) //词频统计,topNum为输出的词项数目,itemLenth为词项长度,weight_Pid为标题权重开关
//为了节省篇幅仅展现部分代码 void CountWF(char *filename, ofstream &fout,char* outfile,int topNum,int itemLenth,int weigth_Pid) { int num = 0; K = topNum; ifstream in(filename); // 打开文件 if (!in) { cerr << "没法打开输入文件" << endl; exit(0); } char readLine[100000]; string tempLine; list<string> listString; while (in.getline(readLine, 100000))//逐行处理文件 { tempLine = readLine;//存储当前行的字符串 if (tempLine.length()<6) //论文序号 { b.clear(); continue; } else if (readLine[0] == 'T'&&readLine[1] == 'i'&&readLine[2] == 't'&&readLine[3] == 'l'&&readLine[4] == 'e')//Title字段 { Count(tempLine, itemLenth, 7,weigth_Pid); } else if (readLine[0] == 'A'&&readLine[1] == 'b'&&readLine[2] == 's'&&readLine[3] == 't'&&readLine[4] == 'r'&&readLine[5] == 'a'&&readLine[6] == 'c'&&readLine[7] == 't')//Abstract字段 { Count(tempLine, itemLenth, 10, weigth_Pid); } else if(readLine) { Count(tempLine, itemLenth, 0,weigth_Pid); } } if (essay.size() < K)K = essay.size(); vector < map<string, int> ::iterator> top(K, essay.begin()); topK(essay, top, fout,outfile);//堆排序算法 } //队列使用 list<string> b('\0'); list<string>::iterator it1; if (char_Count >= 4) //如果合法单词,则记录 { char words[100] = { "\0" }; //单词存储 for (int k = i; k < i + count; k++) { words[k - i] = tempLine[k]; } string s = words;//单词存入字符串中 b.push_back(s); //推入队列尾 s = "\0"; if (b.size() == MaxNum)//队列满 { int nowNum = MaxNum;//当前队列长度 for (it1 = b.begin(); it1 != b.end(); it1++) { s.append(*it1); nowNum--; if (nowNum != 0)s.append(" "); } if(head==7&&weight_Pid==1)essay[s]+=10;//记录词组/单词 else essay[s]++; b.pop_front(); //队首出队列 s = "\0"; } i += count - 1; } else if (count > 0 && count < 4) //若遇到不合法单词状况队列 { b.clear(); i += count - 1; } else continue; } if (head == 7)b.clear(); //如果Title字段结束时状况队列
词项/单词 词频统计流程图
算法
在getPaperInfo函数中加入以下代码app
author = re_h.sub('',str(soup.find('i'))).strip().split(', ')
就能获得做者的信息函数
将每一个做者出现的次数写入到文件中,造成点集工具
将同时出现的做者以及出现的次数写入到文件中,以三元组形式,造成边集性能
代码以下
authors = [] i = 0 for paperInfo in papersInfo:#每篇论文的做者list的形式放入authors当中 title,abstract,author = getPaperInfo(paperInfo.find('a').get('href')) authors.append(author) for each in authors:#将同时出现的两个做者造成元组,放入到字典当中,并进行计数 for author1 in each: for author2 in each: if (author1,author2) not in relationships: relationships[(author1,author2)] = 1 else: relationships[(author1,author2)] = relationships[(author1,author2)] + 1
有了点集和边集后,用Gephi工具,将两个文本文档传而后就能造成做者之间的联系图了
这是总的做者联系图,由于做者太多,因此会很密集
这是放大后的图,每一个点都是一个做者,做者之间的联系粗细大小表明同时出现的频率,越粗的线表明频率越高
为了解决它想到以前将map改成unordered_map能减小一半的时间花费,可是此次花费时间差很少,结果以下:
除此以外其他花费时间较多的语句多为判断语句。。不知道应该怎么再改进了。
因为此次做业是在上一次的基础上进行改动,因此签入次数较少,bug都是在最后关头发现的(实际上是原来就有而后想偷懒没有改,最后良心发现才改了)
个人队友是个可靠的小伙伴,是个深藏不漏的大佬,是个6到飞起的人。