00.前言:
- 本次作业链接
- 队友博客链接
- github仓库链接
- 结对成员:031602605 陈浩 and 031602634 吴志鸿
01.分工:
- 陈浩同学负责:
- 吴志鸿同学负责:
02.PSP表格:
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 25 |
• Estimate | • 估计这个任务需要多少时间 | 30 | 25 |
Development | 开发 | 480 | 600 |
• Analysis | • 需求分析 (包括学习新技术) | 60 | 120 |
• Design Spec | • 生成设计文档 | 35 | 30 |
• Design Review | • 设计复审 | 20 | 20 |
• Coding Standard | • 代码规范 (为目前的开发制定合适的规范) | 20 | 25 |
• Design | • 具体设计 | 120 | 150 |
• Coding | • 具体编码 | 120 | 120 |
• Code Review | • 代码复审 | 120 | 150 |
• Test | • 测试(自我测试,修改代码,提交修改) | 60 | 120 |
Reporting | 报告 | 90 | 120 |
• Test Repor | • 测试报告 | 30 | 45 |
• Size Measurement | • 计算工作量 | 10 | 15 |
• Postmortem & Process Improvement Plan | • 事后总结, 并提出过程改进计划 | 30 | 35 |
合计 | 1225 | 1600 |
03.解题思路描述与设计实现说明:
- 爬虫使用
- 工具:Python
- 代码如下
- 代码组织与内部实现设计(类图)
- 主要由两个类组成
- Word类用于实现基本功能
- FIle类用于实现对文本的输入输出
- 说明算法的关键与关键实现部分流程图
- 主要说明这次新加的三个功能
- 自定义命令行参数
- 遇到 -i 时 读取后面的输入路径字符,并写入输入路径中
- 遇到 -o 时 读取后面的输出路径字符,并写入输出路径中
- 遇到 -m 时 读取后面的字符串,并利用函数转换成正整数,存储数值
- 遇到 -n 时 读取后面的字符串,并利用函数转换成正整数,存储数值
- 遇到 -w 时 读取后面的字符串,并利用函数转换成正整数,存储数值
- 权重统计:
- 首先根据从-w参数后读出的数值是0和1分别选择两种权重模式。
- 每次利用getline函数读取一行,判断开头第一个单词是 “Title“” 还是“Absatra”,在根据权重模式来分别计算两种情况下单词的权重值。
- 词组统计
- 获取一个合法输入单词,将单词的起始加入队列,判断下一个单词是不是合法单词,如果不是,清空队列,重新获取单词;如果是,则循环上一次操作,队列长度+1,直到队列长度符合输入的指定词组长度,从队列中得到单词位置,记录词组。
- 获取一个合法输入单词,将单词的起始加入队列,判断下一个单词是不是合法单词,如果不是,清空队列,重新获取单词;如果是,则循环上一次操作,队列长度+1,直到队列长度符合输入的指定词组长度,从队列中得到单词位置,记录词组。
04.附加题设计与展示:
设计的创意独到之处
实现思路
实现成果展示
05.关键代码解释:
- 这是自定义命令行参数的代码
void File::del(char *argv[])
{
for (int i = 1; argv[i] != NULL; i = i + 2)
{
if (strcmp(argv[i],"-i") == 0) {
input = argv[i + 1];
continue;
}
else if (strcmp(argv[i], "-o") == 0) {
output = argv[i + 1];
continue;
}
else if (strcmp(argv[i], "-w") == 0) {
fcountquz = atoi(argv[i + 1]);
//cout << countquz << "aaa" << endl;
}
else if (strcmp(argv[i], "-m") == 0) {
fcountphrase = atoi(argv[i + 1]);
//cout << countphrase << "bbb" << endl;
}
else if (strcmp(argv[i], "-n") == 0) {
fouttop = atoi(argv[i + 1]);
//cout << outtop << "ccc" << endl;
}
}
return;
}
- 如下展示一个测试样例 命令行参数为-i ./result.txt -o output.txt -w 1 -m 3
0
Title: Embodied Question Answering
Abstract: We present a new AI task -- Embodied Question Answering (EmbodiedQA) -- where an agent is spawned at a random location in a 3D environment and asked a question ("What color is the car?"). In order to answer, the agent must first intelligently navigate to explore the environment, gather necessary visual information through first-person (egocentric) vision, and then answer the question ("orange"). EmbodiedQA requires a range of AI skills -- language understanding, visual recognition, active perception, goal-driven navigation, commonsense reasoning, long-term memory, and grounding language into actions. In this work, we develop a dataset of questions and answers in House3D environments, evaluation metrics, and a hierarchical model trained with imitation and reinforcement learning.
06.性能分析与改进:
- 使用从CVPR2018官网爬取的979篇文章的标题和摘要来进行测试
- 命令行参数为 -i input.txt -o output.txt -m 4 -n 66 -w 1
- 测试得到代码覆盖率如下所示
- 主要存在问题是如下所示的异常处理部分
- 改进
一开始使用的是数组来存储,后来发现开销过大,从而改用队列的形式。
07.单元测试:
- 测试空白输入文本(行数、字符数和单词数都应该为0)
TEST_CLASS(EmptyTest)
{
public:
TEST_METHOD(TestMethod1)
{
//空白文本
File f;
Word w;
f.Filein();
int num = w.Countcharacters(f.fin);
int num1 = w.Countlines(f.fin);
int num2 = w.Countwords(f.fin);
Assert::IsTrue( (num==0) &&(num1==0) && (num2== 0) );
// TODO: 在此输入测试代码
}
};
- 测试不存在输入文本文本输入(文本输入路径不存在,返回值为1)
TEST_CLASS(UnexistTest)
{
public:
TEST_METHOD(TestMethod1)
{
//错误文本
File f;
Word w;
f.input = "./unexist.txt";
int num=f.Filein();
Assert::IsTrue(num == 1);
// TODO: 在此输入测试代码
}
};
- 测试只含Title的输入文本(返回行数为1行)
TEST_CLASS(TitleTest)
{
public:
TEST_METHOD(TestMethod1)
{
//只含Title
File f;
Word w;
f.input = "./TitleTest.txt";
int num=f.Filein();
int num2 = w.Countlines(f.fin);
Assert::IsTrue(num2 == 1);
// TODO: 在此输入测试代码
}
};
- 测试只含Abstract的文本输入(返回行数为1行)
TEST_CLASS(AbstractTest)
{
public:
TEST_METHOD(TestMethod1)
{
//只含Abstract
File f;
Word w;
f.input = "./AbstractTest.txt";
f.Filein();
int num1 = w.Countlines(f.fin);
Assert::IsTrue(num1 == 1);
// TODO: 在此输入测试代码
}
};
测试纯数字样本(返回字符数应该为0)
TEST_CLASS(NumTest) { public: TEST_METHOD(TestMethod1) { //测试纯数字样本 File f; Word w; f.input = "./input2.txt"; f.Filein(); int num2 = w.Countwords(f.fin); Assert::IsTrue(num2 == 0); // TODO: 在此输入测试代码 } };
测试基本案例(返回行数1行,字符数80)
TEST_CLASS(Test) { public: TEST_METHOD(TestMethod1) { //测试样本 File f; Word w; f.input = "./input1.txt"; f.Filein(); int num1 = w.Countlines(f.fin); int num2 = w.Countwords(f.fin); Assert::IsTrue(num1 == 2 && num2 == 80); // TODO: 在此输入测试代码 } };
测试大型样本含权重样本输出词组
TEST_CLASS(TopTest1) { public: TEST_METHOD(TestMethod1) { //测试大型样本含权重样本输出词组 File f; Word w; w.set(3, 1, 20); f.input = "./top.txt"; f.Filein(); vector<pair<string, int>> v = w.Counttop10(f.fin, 20); int characters = w.Countcharacters(f.fin); int word = w.Countwords(f.fin); int line = w.Countlines(f.fin); vector<pair<string, int>>::iterator iter = v.begin(); Assert::IsTrue(characters == 2915 && word ==287 && line == 6 && iter->second == 11); // TODO: 在此输入测试代码 } };
测试大型样本不含权重样本输出词组
TEST_CLASS(TopTest2) { public: TEST_METHOD(TestMethod1) { //测试大型样本不含权重样本输出词组 File f; Word w; w.set(3, 0, 20); f.input = "./top.txt"; f.Filein(); vector<pair<string, int>> v = w.Counttop10(f.fin, 20); int characters = w.Countcharacters(f.fin); int word = w.Countwords(f.fin); int line = w.Countlines(f.fin); vector<pair<string, int>>::iterator iter = v.begin(); Assert::IsTrue(characters == 2915 && word == 287 && line == 6 && iter->second == 2); // TODO: 在此输入测试代码 } };
测试含权重样本的输出词组
TEST_CLASS(PhraseTest1) { public: TEST_METHOD(TestMethod1) { //测试含权重样本的输出词组 File f; Word w; w.set(3, 1, 66); f.input = "./P.txt"; f.Filein(); vector<pair<string, int>> v = w.Counttop10(f.fin,66); int characters = w.Countcharacters(f.fin); int word = w.Countwords(f.fin); int line = w.Countlines(f.fin); int num = v.size(); vector<pair<string, int>>::iterator iter = v.begin(); Assert::IsTrue(characters == 817 && word == 80 && line == 2 && num == 38 && iter->first == "embodied question answering" && iter->second==11); // TODO: 在此输入测试代码 } };
测试不含权重样本的输出词组
TEST_CLASS(PhraseTest2) { public: TEST_METHOD(TestMethod1) { //测试不含权重样本的输出词组 File f; Word w; w.set(3, 0, 66); f.input = "./P.txt"; f.Filein(); vector<pair<string, int>> v = w.Counttop10(f.fin, 66); int characters = w.Countcharacters(f.fin); vector<pair<string, int>>::iterator iter = v.begin(); Assert::IsTrue(iter->first == "embodied question answering" && iter->second == 2); // TODO: 在此输入测试代码 } };
08.Github的代码签入记录:
9.遇到的代码模块异常或结对困难及解决方法:
问题描述
做过哪些尝试
是否解决
有何收获
10.评价你的队友:
值得学习的地方
需要改进的地方