這個作業屬於哪個課程 | 課程鏈接 |
---|---|
這個作業要求在哪里 | 作業要求 |
這個作業的目標 | PSP表格的使用,基本開發流程的了解與知識的學習,程序測試與開發。 |
個人項目
一、個人開發流程PSP表格
PSP | Personal Software Process Stages | 預估耗時(分鍾) | 實際耗時(分鍾) |
---|---|---|---|
Planning | 計划 | 20 | 15 |
· Estimate | · 估計這個任務需要多少時間 | 20 | 15 |
Development | 開發 | 590 | 600 |
· Analysis | · 需求分析 (包括學習新技術) | 120 | 60 |
· Design Spec | · 生成設計文檔 | 30 | 20 |
· Design Review | · 設計復審 | 20 | 30 |
· Coding Standard | · 代碼規范 (為目前的開發制定合適的規范) | 10 | 15 |
· Design | · 具體設計 | 200 | 240 |
· Coding | · 具體編碼 | 100 | 130 |
· Code Review | · 代碼復審 | 50 | 25 |
· Test | · 測試(自我測試,修改代碼,提交修改) | 60 | 80 |
Reporting | 報告 | 70 | 90 |
· Test Repor | · 測試報告 | 50 | 60 |
· Size Measurement | · 計算工作量 | 10 | 10 |
· Postmortem & Process Improvement Plan | · 事后總結, 並提出過程改進計划 | 10 | 20 |
· 合計 | 680 | 705 |
二、計算模塊接口的設計與實現過程
基本思路是:
先通過FileUtils分析出文件的字符串,再獲取字符串的詞頻與單詞后通過數值計算工具解析詞頻單詞Map為詞頻數組並進行重復率計算,最后再通過FileUtils輸出答案文件。
三、模塊接口之間的調用與耗時情況
如圖使用jprofiler分析結果
結果說明程序占用時間最久的在於對字符串進行分詞與解析功能上,這個方法是Ansj組件內部方法,所能做的優化可以是在傳入字符串時不將整個文件內容傳入,而是分段將內容傳入,這樣可以初步優化這個程序的執行。但最好的方式還是選擇一個處理方式更快的分析算法。
四、具體的測試案例:
1. 文件讀取功能的測試
@Test
public void testReadFileToString() throws IOException {
String path = "log.log";
String context = FileUtils.readFileToString(path);
System.out.println(context);
}
四月 15, 2021 2:25:37 下午 com.moxiaoxiao.JULTest testLogConfig
嚴重: severe
四月 15, 2021 2:25:37 下午 com.moxiaoxiao.JULTest testLogConfig
警告: warning
四月 15, 2021 2:25:37 下午 com.moxiaoxiao.JULTest testLogConfig
信息: info
四月 15, 2021 2:25:37 下午 com.moxiaoxiao.JULTest testLogConfig
配置: configProcess finished with exit code 0
2. 分析詞頻與單詞測試
@Test
public void testGetTermsAndCounts() throws IOException, FileEmptyException {
String path = "log.log";
String context = FileUtils.readFileToString(path);
Map<String, Integer> map = AnalysisUtils.getTermsAndCounts(context);
System.out.println(map);
}
九月 15, 2021 10:23:11 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/ambiguity.dic
九月 15, 2021 10:23:11 下午 org.ansj.library.AmbiguityLibrary info
信息: load dic use time:1 path is : library/ambiguity.dic
九月 15, 2021 10:23:11 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/default.dic
九月 15, 2021 10:23:11 下午 org.ansj.library.DicLibrary info
信息: load dic use time:1 path is : library/default.dic
九月 15, 2021 10:23:12 下午 org.ansj.library.DATDictionary info
信息: init core library ok use time : 865
九月 15, 2021 10:23:12 下午 org.ansj.library.NgramLibrary info
信息: init ngram ok use time :469
{com=4, 嚴重=1, 25=4, 15=4, 37=4, 信息=1, 四月=4, moxiaoxiao=4, 2021=4, testlogconfig=4, jultest=4, 2=4, 配置=1, 下午=4, 警告=1, severe=1, warning=1, config=1, info=1}Process finished with exit code 0
3.測試計算重復率
@Test
public void testGetRepeatRate() throws IOException, FileEmptyException {
String path = "log.log";
String path2 = "2.log";
String context = FileUtils.readFileToString(path);
Map<String, Integer> map = AnalysisUtils.getTermsAndCounts(context);
String context2 = FileUtils.readFileToString(path2);
Map<String, Integer> map2 = AnalysisUtils.getTermsAndCounts(context2);
System.out.println(MathUtils.getRepeatRate(map, map2));
}
九月 15, 2021 10:24:00 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/ambiguity.dic
九月 15, 2021 10:24:00 下午 org.ansj.library.AmbiguityLibrary info
信息: load dic use time:0 path is : library/ambiguity.dic
九月 15, 2021 10:24:00 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/default.dic
九月 15, 2021 10:24:00 下午 org.ansj.library.DicLibrary info
信息: load dic use time:2 path is : library/default.dic
九月 15, 2021 10:24:01 下午 org.ansj.library.DATDictionary info
信息: init core library ok use time : 765
九月 15, 2021 10:24:02 下午 org.ansj.library.NgramLibrary info
信息: init ngram ok use time :453
0.9881371839677033
4.測試答案輸出
@Test
public void testWriteAns() throws IOException, FileEmptyException {
String path = "log.log";
String path2 = "2.log";
String context = FileUtils.readFileToString(path);
Map<String, Integer> map = AnalysisUtils.getTermsAndCounts(context);
String context2 = FileUtils.readFileToString(path2);
Map<String, Integer> map2 = AnalysisUtils.getTermsAndCounts(context2);
Double rate = MathUtils.getRepeatRate(map, map2);
FileUtils.writeAns("ans.txt", path, path2, rate);
}
九月 15, 2021 10:24:43 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/ambiguity.dic
九月 15, 2021 10:24:43 下午 org.ansj.library.AmbiguityLibrary info
信息: load dic use time:0 path is : library/ambiguity.dic
九月 15, 2021 10:24:43 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/default.dic
九月 15, 2021 10:24:43 下午 org.ansj.library.DicLibrary info
信息: load dic use time:1 path is : library/default.dic
九月 15, 2021 10:24:44 下午 org.ansj.library.DATDictionary info
信息: init core library ok use time : 687
九月 15, 2021 10:24:45 下午 org.ansj.library.NgramLibrary info
信息: init ngram ok use time :422Process finished with exit code 0
答案文件:
原文:log.log
抄襲版論文的文件:2.log
重復率:0.99
5.測試空白參數
@Test
public void testEmptyMain() throws Exception{
String[] args = {"", "",""};
App.main(args);
}
原論文與抄襲論文不存在或答案輸出路徑為空!
6.測試正常參數
@Test
public void testMain() throws Exception{
String[] args = {"orig.txt", "orig.txt","ans.txt"};
App.main(args);
}
九月 15, 2021 10:26:14 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/ambiguity.dic
九月 15, 2021 10:26:14 下午 org.ansj.library.AmbiguityLibrary info
信息: load dic use time:0 path is : library/ambiguity.dic
九月 15, 2021 10:26:14 下午 org.ansj.dic.impl.File2Stream info
信息: path to stream library/default.dic
九月 15, 2021 10:26:14 下午 org.ansj.library.DicLibrary info
信息: load dic use time:2 path is : library/default.dic
九月 15, 2021 10:26:15 下午 org.ansj.library.DATDictionary info
信息: init core library ok use time : 725
九月 15, 2021 10:26:16 下午 org.ansj.library.NgramLibrary info
信息: init ngram ok use time :462
已將結果輸出至:ans.txtProcess finished with exit code 0
輸出文件:
原文:orig.txt
抄襲版論文的文件:orig.txt
重復率:1.00
五、異常聲明
-
請確保參數個數正確:
該錯誤可能出現在使用cmd命令時參數個數並沒有按要求給出3個文件路徑導致,有可能是因為給少了也可能是因為給多了。
-
原論文與抄襲論文不存在或答案輸出路徑為空!:
該錯誤可能出現於原論文與抄襲論文路徑不存在或答案輸出路徑為空。
-
答案文件已存在,請使用新路徑以避免覆蓋!:
該錯誤可能出現與答案文件已經存在於本地磁盤上,請更換一個路徑並帶上一個想要輸出的答案文件的名字。
-
文件讀取有異常!:
該錯誤可能出現與文件讀取權限的設置上,請確保所有文件都是處於可讀狀態下。
六、其他聲明
-
控制台輸出:
九月 15, 2021 10:26:14 下午 org.ansj.dic.impl.File2Stream info 信息: path to stream library/ambiguity.dic 九月 15, 2021 10:26:14 下午 org.ansj.library.AmbiguityLibrary info 信息: load dic use time:0 path is : library/ambiguity.dic 九月 15, 2021 10:26:14 下午 org.ansj.dic.impl.File2Stream info 信息: path to stream library/default.dic 九月 15, 2021 10:26:14 下午 org.ansj.library.DicLibrary info 信息: load dic use time:2 path is : library/default.dic 九月 15, 2021 10:26:15 下午 org.ansj.library.DATDictionary info 信息: init core library ok use time : 725 九月 15, 2021 10:26:16 下午 org.ansj.library.NgramLibrary info 信息: init ngram ok use time :462
屬於正常日志記錄信息,而不是錯誤。
-
重復率的計算采用的是余弦相似性的方式進行計算,對於兩篇相似的文章,單詞詞頻越相近則會得出一個更高的重復率,而如果單詞詞頻相差較遠甚至完全不相同時,重復率才會較低。
-
參考文章:TF-IDF與余弦相似性的應用