201671030109 韓豔豔 《英文文本統計分析》結對項目報告

項目 內容
這個做業屬於哪一個課程 任課教師博客主頁連接
這個做業的要求在哪裏 做業連接地址
課程學習目標 熟悉軟件開發總體流程,提高自身能力
本次做業在哪一個具體方面幫助咱們實現目標 第一次體驗一個完整的工程

任務一:

點評做業博客地址
源代碼地址
點評內容:在博客的實驗運行截圖中,未顯示出你所運行的文件是哪一個;經過研讀代碼知,已在代碼中定義了要運行的文件名,我認爲這樣作程序的適用範圍就變小了,因此建議應擴大程序的適用性;同時經過閱讀你的博客及代碼,意識到了本身做業過程當中所出現的代碼不規範、博客結構不合理等問題,並進行了改正。在你的PSP中「計劃共完成須要的時間」與「實際完成須要的時間」兩列數據的差別主要在與編碼階段預計時間與實際時間之間的偏差,可能更多的是因爲基礎知識不紮實或粗心形成的偏差,但願經過結隊編程,可以把這部分作的更好
點評心得:經過閱讀以及點評隊友的實驗二內容,瞭解了隊友的代碼風格而且對其實驗過程當中採用的高效算法以及好的想法進行了探討以及借鑑,同時,對其在實驗過程當中出現的錯誤以及失誤等提出了本身的意見及建議等,爲繼續進行結隊項目奠基了基礎。html

任務二:

a.需求分析
採用兩人合做方式,設計開發一個英文文本統計分析軟件,使之具備如下功能:
(1)實驗2要求的功能;
(2)單詞頻數可視化柱狀圖要求是如下樣式:

(3)統計該文本行數及字符數;
(4)各類統計功能均提供計時功能,顯示程序統計所消耗時間(單位:ms);
(5)可處理任意用戶導入的任意英文文本;
(6)人機交互界面要求GUI界面(WEB頁面、APP頁面均可);
(7)附加分功能:統計文本中除冠詞、代詞、介詞以外的高頻詞;
(8)附加分功能:統計前10個兩個單詞組成的詞組頻率。git

b.軟件設計:使用類圖
github

c.核心功能代碼展現:展現核心功能代碼
人機交互界面的實現:算法

public class main extends JFrame 
{
    //高頻詞輸出按鈕
    private static JButton highFrequencyButton; 
    //統計指定單詞個數按鈕
    private static JButton wordCountButton;
    //詞頻寫入文件按鈕
    private static JButton printFile; 
    //行數單詞數統計按鈕
    private static JButton lineWordCount; 
    //版面
    private static JLabel input;
    //框架
    private static JFrame statistics; 
    //文件名
    private static JTextField file2; 
    private static JLabel file ;
    
    public static FileReader fr;
    static BufferedReader br;
    //行數
    static int rowNumber=0; 
    //單詞數
    static int wordNumber=0;
    //統計行數單詞數所用時間
    static long time;
    /**初始化登錄界面*/
    public main ()
    { 
        //設置字體
        Font font =new Font("楷體", Font.PLAIN, 30); 
        statistics=new JFrame("英文文本統計分析軟件");
        statistics.setSize(500, 600);
        input=new JLabel();
        
        file=new JLabel("輸入文件名:");
        file.setBounds(20, 40, 100, 50);
        
        highFrequencyButton=new JButton("查看前N個高頻詞");    
        highFrequencyButton.setBounds(20, 150, 400, 50);
        highFrequencyButton.setFont(font);
        
        wordCountButton=new JButton("統計指定單詞詞頻");
        wordCountButton.setBounds(20, 250, 400, 50);
        wordCountButton.setFont(font);

        printFile=new JButton("寫入文件");
        printFile.setBounds(20, 450, 400, 50);
        printFile.setFont(font);
        
        lineWordCount=new JButton("統計行數單詞數");
        lineWordCount.setBounds(20, 350, 400, 50);
        lineWordCount.setFont(font);

        //加入文本框
        file2 = new JTextField();
        file2.setBounds(150, 40, 250, 40);
        
        input.add(file);
        input.add(file2);
     
        input.add(highFrequencyButton);
        input.add(wordCountButton);
        input.add(printFile);
        input.add(lineWordCount);
        
        statistics.add(input);
        statistics.setVisible(true);
        statistics.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        statistics.setLocation(300,400);

    }

柱狀圖的實現編程

public void paint(Graphics g)
    {
        int Width = getWidth();
        int Height = getHeight();
        int leftMargin = 50;//柱形圖左邊界
        int topMargin = 50;//柱形圖上邊界
        Graphics2D g2 = (Graphics2D) g;
        int ruler = Height-topMargin;
        int rulerStep = ruler/20;//將當前的高度平分爲20個單位
        g2.setColor(Color.WHITE);//繪製白色背景
        g2.fillRect(0, 0, Width, Height);//繪製矩形圖
        g2.setColor(Color.LIGHT_GRAY);
        for(int i=0;i<rulerStep;i++){
            g2.drawString((30000-1500*i)+"個", 8, topMargin+rulerStep*i);//繪製Y軸上的數據
        }
        g2.setColor(Color.darkGray);
        int m=0;
        for (Entry<String, Integer> entry : map.entrySet()) 
        { 
            int value =entry.getValue();
            int step = (m+1)*40;//設置每隔柱形圖的水平間隔爲40
            g2.fillRoundRect(leftMargin+step*2,Height-value/50-5, 40, value, 40, 10);//繪製每一個柱狀條
            g2.drawString(entry.getKey(), leftMargin+step*2, Height-value/50-5);    //標識每一個柱狀條       
            m++;
         } 
         
    }

查詢並顯示指定單詞詞頻並統計時間框架

inputButton.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent event)
        {
           if (event.getSource()==inputButton)
           {
               long start = System.currentTimeMillis();
               String word=word2.getText();
               if (!word.isEmpty())
               {          
                    Map<String,Integer> map = new TreeMap<String, Integer>();  
                    String[] input= word.split(" ");
                    int i;
                    String print = "";
                    for (i=0; i<input.length; i++) 
                    {
                        for (Entry<String, Integer> entry : maps.entrySet()) 
                        { 
                            if (input[i].equals(entry.getKey()))
                            {
                                map.put(entry.getKey(), entry.getValue());
                                print += entry.getKey() + ":" + entry.getValue()+"    "; 
                                break;
                            }
                         } 
                     }
                    long time=System.currentTimeMillis() - start;
                    JOptionPane.showConfirmDialog(null,print+"\n"+"所用時間:"+(System.currentTimeMillis() - start)+"ms","結果",JOptionPane.DEFAULT_OPTION);
                             plot histogram=new plot(map,input.length);
                    histogram.setVisible(true);
                    }
                else
                {
                    JOptionPane.showConfirmDialog(null, "請輸入要查詢的信息!","提示",JOptionPane.DEFAULT_OPTION);                  
                } 
               
           }
        }
     });

輸出到文件學習

Map<String,Integer> Map = new LinkedHashMap<String, Integer>(); 
     /**按字典順序排序*/
    void Sort(Map<String, Integer> map) 
    {  
       Set<Entry<String,Integer>> m= map.entrySet();   
       LinkedList<Entry<String, Integer>> List = new LinkedList<Entry<String,Integer>>(m);
    
           Collections.sort(List, new Comparator<Entry<String,Integer>>() 
           {     
               public int compare(Entry<String, Integer> a,  Entry<String, Integer> b) 
               {  
                   return a.getKey().compareTo(b.getKey());  
              }     
           });  
       for (Entry<String,Integer> entry: List) 
       {  
           Map.put(entry.getKey(), entry.getValue());  
       }  
   } 
    /**寫入文件*/
     void PrintToF(Map<String, Integer> map)throws IOException 
     {  
            long start = System.currentTimeMillis();
            Sort(map);
            File file = new File("result.txt");
            FileWriter f = new FileWriter(file.getAbsoluteFile());
            for (Entry<String,Integer> w: Map.entrySet()) 
            {
                f.write(w.getKey() + "/" + w.getValue()+"     ");
            }
            f.close();
            JOptionPane.showConfirmDialog(null,"所用時間:"+(System.currentTimeMillis() - start)+"ms","結果",JOptionPane.DEFAULT_OPTION);
     }

d. 程序運行:程序運行時每一個功能界面截圖測試

人機交互界面:
字體

高頻詞的統計:
編碼

柱狀圖的顯示:

統計單詞數、行數以及所用時間:

輸出到result.txt文件:

e. 描述結對的過程,提供兩人在討論、細化和編程時的結對照片(非擺拍)

f. 提供這次結對做業的PSP。

結對項目開發過程當中,構建PSP表以下:

PSP 任務內容 計劃共完成須要的時間(min) 實際完成須要的時間(min)
Planning 計劃 10 15
- Estimate 估計這個任務須要多少時間,並規劃大體工做步驟 10 15
Development 開發 345 425
- Analysis 需求分析 (包括學習新技術) 20 25
- Design Spec - 生成設計文檔 25 25
- Design Review - 設計複審 (和同事審覈設計文檔) 25 20
- Coding Standard 代碼規範 (爲目前的開發制定合適的規範) 20 25
- Design 具體設計 45 50
- Coding 具體編碼 200 255
- Test - 測試(自我測試,修改代碼,提交修改) 30 25
Reporting 報告 50 48
-- Test Report - 測試報告 25 20
- Size Measurement 計算工做量 25 28
- Postmortem & Process Improvement Plan - 過後總結 ,並提出過程改進計劃 30 28

結對感覺和體會:在項目正式開發以前,咱們先預估本次合做開發任務的PSP環節的消耗時間,並在PSP過程當中統計實際耗時,填寫PSP表格。在實施項目結對過程當中兩我的一塊兒溝通,共同參與程序的編碼工做,經過討論,造成了兩我的都承認的編程規範,經過查閱資料等過程,最終完成告終對項目。經過這次結對項目,切身體會到了1+1>2的結對優點,並對之後的項目開發奠基了基礎。

項目源碼在Github的倉庫主頁連接地址

相關文章
相關標籤/搜索