1. 程式人生 > >福大軟工1816 · 第五次作業 - 結對作業2

福大軟工1816 · 第五次作業 - 結對作業2

同名 [] 分享 and rds 規範 fir 分鐘 begin

一、結對同學的博客鏈接、本作業博客的鏈接、Fork的同名倉庫的Github項目地址

結對同學的博客鏈接,本作業博客鏈接,github項目地址

二、具體分工:

基本功能部分:鄭孔宇
測試及附加題部分:俞凱欣

三、PSP表格:

PSP2.1 Personal Software Process Stages 預估耗時(分鐘) 實際耗時(分鐘)
Planning 計劃 10 10
· Estimate · 估計這個任務需要多少時間 540 620
Development 開發 0 0
· Analysis · 需求分析 (包括學習新技術) 120 60
· Design Spec · 生成設計文檔 20 20
· Design Review · 設計復審 20 20
· Coding Standard · 代碼規範 (為目前的開發制定合適的規範) 0 0
· Design · 具體設計 20 20
· Coding · 具體編碼 220 360
· Code Review · 代碼復審 40 40
· Test · 測試(自我測試,修改代碼,提交修改) 60 60
Reporting 報告 0 0
· Test Repor · 測試報告 0 0
· Size Measurement · 計算工作量 0 0
· Postmortem & Process Improvement Plan · 事後總結, 並提出過程改進計劃 30 3

四、需求分析

技術分享圖片

五、功能實現

1.主函數
  • 獲取命令行中的所有指令,並執行相關函數
int main(int args, char* argv[])
{
    char* a = NULL;
    char* b = NULL;
    char* c = NULL;
    char* d = NULL;
    char* e = NULL;
    string cstr, dstr, estr;
    int i;
    int w = 0, m = 0, n = 0;
    for (i = 0; i < args; i++)
    {
        if (strcmp(argv[i], "-i") == 0)  //檢測-i指令
        {
            a = argv[i + 1];
        }
        if (strcmp(argv[i], "-o") == 0) //檢測-o指令
        {
            b = argv[i + 1];
        }
        if (strcmp(argv[i], "-w") == 0) //檢測-w指令
        {
            c = argv[i + 1];
            cstr = c;
            w = atoi(cstr.c_str());
        }
        if (strcmp(argv[i], "-n") == 0) //檢測-n指令
        {
            d = argv[i + 1];
            dstr = d;
            n = atoi(dstr.c_str()); 
        }
        if (strcmp(argv[i], "-m") == 0) //檢測-m指令
        {
            e = argv[i + 1];
            estr = e;
            m = atoi(estr.c_str());
        }
    }
    readtxt(a); //讀取文件並獲取所有字符數
    divide_n(w); //獲取行數 單詞數 排除Title: Abstract: 和編號後的字符數,並分割、存入和排序單詞
    if (m == 0)
    {       
        writetxt_n(b, n); //輸出無-m時候的格式
    }
    else
    {
        readtxt2(a); //讀取文件不改變字符數,用於重新分割
        divide_m(w, m); //分割單詞若滿足詞組條件則存入並排序
        writetxt_m(b); //輸出有-m時候的格式
    }
}
2.詞頻統計(divide_n) (writetxt_n)

技術分享圖片

void divide_n(int w)
{
    size_t length;
    string wordstring;
    char wordchar[999];
    int w2 = 1;
    int i, j, k = 0;
    int pos = 0;
    const char *sep = "./;‘[] \\<>?:\"{}|`~!@#$%^&*()_+-=\n"; //需要分割的字符
    char *p;
    char *buf;
    p = strtok_s(s, sep, &buf);
    while (p)
    {
        wordstring = p;
        strcpy_s(wordchar, wordstring.c_str());
        if (strcmp(wordchar, "Title") == 0)
        {
            charnum -= 11;
            linenum++;
            w2 = w;
        } // 出現Title 權重為w;
        else if (strcmp(wordchar, "Abstract") == 0)
        {
            charnum -= 10;
            linenum++;
            w2 = 1;
        }// 出現Abstract 權重為1;
        else
        {
            length = wordstring.length();
            for (i = 0; i <= length; i++)
            {
                if (wordchar[i] >= ‘A‘ && wordchar[i] <= ‘Z‘)
                {
                    wordchar[i] = wordchar[i] + 32;
                }
            }
            wordstring = wordchar;
            if (wordstring.length() >= 4)
            {
                for (j = 0; j <= 3; j++)//判斷該單詞是否符合前四位為字母
                {
                    if (wordchar[j] >= ‘a‘ && wordchar[j] <= ‘z‘)
                        pos = 1;
                    else
                    {
                        pos = 0;
                        break;
                    }
                }
            }
            if (pos == 1)
            {
                wordnum++;
                if (w_c.count(wordstring) == 0)
                {
                    w_c.insert(make_pair(wordstring, w2));
                }
                else
                {
                    w_c[wordstring] += w2;
                }
                pos = 0;
            }
        }
        p = strtok_s(NULL, sep, &buf);
    }
    for (w_c_iter = w_c.begin(); w_c_iter != w_c.end(); w_c_iter++)
    {
        w_c2.push_back(make_pair(w_c_iter->first, w_c_iter->second));
    }
    sort(w_c2.begin(), w_c2.end(), Comp);
}
void writetxt_n(char *b, int n)
{
    char charnum_s[10], wordnum_s[10], linenum_s[10];
    char num_s[10];
    string res;
    char res_c[200000];
    _itoa_s(charnum + 2, charnum_s, 10);
    _itoa_s(wordnum, wordnum_s, 10);
    _itoa_s(linenum, linenum_s, 10);
    res = res + "characters: " + charnum_s + "\n";
    res = res + "words: " + wordnum_s + "\n";
    res = res + "lines: " + linenum_s + "\n";
    if (n == 0)
    {
        n = 10;
    }
    if (w_c2.size() >= n)
    {
        for (w_c2_iter = w_c2.begin(); w_c2_iter != w_c2.begin() + n; w_c2_iter++)
        {
            _itoa_s(w_c2_iter->second, num_s, 10);
            res = res + "<" + w_c2_iter->first + ">: " + num_s + "\n";
        }
    }
    else
    {
        for (w_c2_iter = w_c2.begin(); w_c2_iter != w_c2.end(); w_c2_iter++)
        {
            _itoa_s(w_c2_iter->second, num_s, 10);
            res = res + "<" + w_c2_iter->first + ">: " + num_s + "\n";
        }
    }
    strcpy_s(res_c, res.c_str());
    FILE *fp1;
    errno_t err;
    err = fopen_s(&fp1, b, "w");
    fwrite(res_c, res.length(), 1, fp1);
}
3.詞組統計(divide_m) (writetxt_m)

技術分享圖片

void divide_m(int w, int m)
{
    size_t length;
    int cznum = 0;
    string cz;
    string wordstring;
    char wordchar[999];
    int w2 = 1;
    int i, j, k = 0;
    int pos = 0;
    const char *sep = "./;‘[] \\<>?:\"{}|`~!@#$%^&*()_+-=\n"; //需要分割的字符
    char *p = NULL;
    char *buf;
    p = strtok_s(s, sep, &buf);
    while (p)
    {
        wordstring = p;
        strcpy_s(wordchar, wordstring.c_str());
        if (strcmp(wordchar, "Title") == 0)
        {
            w2 = w;
            while (cz_q1.empty() == 0)
            {
                cz_q1.pop();
            }
            while (cz_q2.empty() == 0)
            {
                cz_q2.pop();
            }
        } // 出現Title 權重為w;
        else if (strcmp(wordchar, "Abstract") == 0)
        {
            w2 = 1;
            while (cz_q1.empty() == 0)
            {
                cz_q1.pop();
            }
            while (cz_q2.empty() == 0)
            {
                cz_q2.pop();
            }
        }// 出現Abstract 權重為1;
        else
        {
            length = wordstring.length();
            for (i = 0; i <= length; i++)
            {
                if (wordchar[i] >= ‘A‘ && wordchar[i] <= ‘Z‘)
                {

                    wordchar[i] = wordchar[i] + 32;
                }
            }
            wordstring = wordchar;
            if (wordstring.length() >= 4) //合法pos=1  不合法pos=0
            {
                for (j = 0; j <= 3; j++)//判斷該單詞是否符合前四位為字母
                {
                    if (wordchar[j] >= ‘a‘ && wordchar[j] <= ‘z‘)
                    {
                        pos = 1;
                    }
                    else
                    {
                        pos = 0;
                        break;
                    }
                }
            }
            else
            {
                pos = 0;
            }

            if (pos == 1)
            {
                if (cz_q2.size() == 0)
                {
                    cz = "";
                }
                cz_q1.push(wordstring); //將合法單詞入隊q1
                cz_q2.push(wordstring); //將合法單詞入隊q2
                if (cz_q2.size() == m)
                {
                    cz_q1.pop();    //若滿足條件稱為詞組 則q1的首個單詞出隊
                    for (i = 1; i <= m; i++)   //q2的所有單詞存入cz中 用於輸出並清空q2
                    {
                        if (i == m)
                        {
                            cz = cz + cz_q2.front();
                            cz_q2.pop();
                        }
                        else
                        {
                            cz = cz + cz_q2.front() + " ";
                            cz_q2.pop();
                        }
                    }
                    if (cz_c.count(cz) == 0) //查詢map中是否有該詞組 無則將 詞組,頻率 引入  有則將原有 詞組的頻率累加
                    {
                        cz_c.insert(make_pair(cz, w2));
                        cz = "";
                    }
                    else
                    {
                        cz_c[cz] += w2;
                        cz = "";
                    }
                    for (j = 1; j <= cz_q1.size(); j++)  //將q1中剩余單詞存入pop[]中 同步存入q2
                    {
                        pop[j] = cz_q1.front();
                        cz_q1.pop();
                        cz_q1.push(pop[j]);
                        cz_q2.push(pop[j]);
                    }
                }
            }
            else if (pos == 0) //當遇到非法單詞 將兩個隊列清空
            {
                while (cz_q1.empty() == 0)
                {
                    cz_q1.pop();
                }
                while (cz_q2.empty() == 0)
                {
                    cz_q2.pop();
                }
            }
        }
        p = strtok_s(NULL, sep, &buf);
    }
    for (cz_c_iter = cz_c.begin(); cz_c_iter != cz_c.end(); cz_c_iter++)
    {
        cz_c2.push_back(make_pair(cz_c_iter->first, cz_c_iter->second));
    }
    sort(cz_c2.begin(), cz_c2.end(), Comp);
}
void writetxt_m(char *b)
{
    char charnum_s[10], wordnum_s[10], linenum_s[10];
    char num_s[10];
    string res;
    char res_c[200000];
    _itoa_s(charnum + 2, charnum_s, 10);
    _itoa_s(wordnum, wordnum_s, 10);
    _itoa_s(linenum, linenum_s, 10);
    res = res + "characters: " + charnum_s + "\n";
    res = res + "words: " + wordnum_s + "\n";
    res = res + "lines: " + linenum_s + "\n";
    if (cz_c2.size() >= 10)
    {
        for (cz_c2_iter = cz_c2.begin(); cz_c2_iter != cz_c2.begin() + 10; cz_c2_iter++)
        {
            _itoa_s(cz_c2_iter->second, num_s, 10);
            res = res + "<" + cz_c2_iter->first + ">: " + num_s + "\n";
        }
    }
    else
    {
        for (cz_c2_iter = cz_c2.begin(); cz_c2_iter != cz_c2.end(); cz_c2_iter++)
        {
            _itoa_s(cz_c2_iter->second, num_s, 10);
            res = res + "<" + cz_c2_iter->first + ">: " + num_s + "\n";
        }
    }
    strcpy_s(res_c, res.c_str());
    FILE *fp1;
    errno_t err;
    err = fopen_s(&fp1, b, "w");
    fwrite(res_c, res.length(), 1, fp1);
}

六、測試結果

  • 輸入
    技術分享圖片
  • 輸出
    技術分享圖片

七、性能分析

技術分享圖片

技術分享圖片

八、附加功能

* 代碼

import json

from pyecharts import Bar, Line, Scatter, EffectScatter, Grid, WordCloud, Graph, Page
name = ["learning","with","image","from","network","that","deep","networks","this","video","visual","neural","detection","model","segmentation","multi"]
value = [2879,2744,2306,1826,1757,1757,1735,1510,1423,1088,1030,952,938,909,889,827]

wordcloud = WordCloud("CVPR熱詞圖譜")
wordcloud.add("", name, value, word_size_range=[20, 100])
wordcloud.render()

技術分享圖片

九、評價隊友

刻苦勤奮!

十、學習記錄

第N周 新增代碼 累計代碼 本周學習時間 累計學習時間(小時) 重要成長
1 200 200 5 5 對Axure的學習
5 200 400 7 12 函數學習
5 200 600 7 19 函數學習

福大軟工1816 · 第五次作業 - 結對作業2