• 计算与软件工程课程 作业四


    作业要求 https://edu.cnblogs.com/campus/jssf/infor_computation17-31/homework/10534
    课程目标 完成简单软件功能的开发,会对简单代码进行审核,学会结对编程,和队友搭档一起开发新的功能,会对代码进行单元测试等,分析代码的利用率
    参考文献 https://www.cnblogs.com/xinz/archive/2011/08/07/2130332.html)
    结对伙伴 https://(www.cnblogs.com/1124-/p/12638944.html)

    作业一

    1.要求:

    (1)每个人针对之前两次作业所写的代码,针对要求,并按照代码规范(风格规范、设计规范)要求评判其他学生的程序,同时进行代码复审(按照代码复审核表 https://www.cnblogs.com/xinz/archive/2011/11/20/2255971.html),要求评价数目不少于8人次
    (3)评价内容直接放在你被评价的作业后面评论中
    (4)同时另建立一个博客,将你作的评论的截图或者链接,放在博客中,并在你的博客中谈谈自己的总体看法
    写博客仍然按照之前格式要求处理

    2.作业链接:

    https://i-beta.cnblogs.com/posts)

    作业二

    1.要求:

    两人自由组队进行结对编程
    参考结对编程的方法、过程(https://www.cnblogs.com/xinz/archive/2011/08/07/2130332.html)开展两人合作完成本项目
    (1)实现一个简单而完整的软件工具(中文文本文件人物统计程序):针对小说《红楼梦》要求能分析得出各个人物在每一个章回中各自出现的次数,将这些
    统计结果能写入到一个csv格式的文件。
    (2)进行单元测试、回归测试、效能测试,在实现上述程序的过程中使用相关的工具。
    (3)进行个人软件过程(PSP)的实践,逐步记录自己在每个软件工程环节花费的时间。
    (4)使用源代码管理系统 (GitHub, Gitee, Coding.net, 等);
    (5)针对上述形成的软件程序,对于新的文本小说《水浒传》分析各个章节人物出现次数,来考察代码。
    将上述程序开发结对编程过程记录到新的博客中,尤其是需要通过各种形式展现结对编程过程,并将程序获得的《红楼梦》与《水浒传》各个章节人物出现次数与全本人物出现总次数,通过柱状图、饼图、表格等形式展现。
    《红楼梦》与《水浒传》的文本小说将会发到群里。
    注意,要求能够分章节自动获得人物出现次数

    2.代码及运行结果

    (1)红楼梦

    import jieba
    from wordcloud import WordCloud
    
    def getFile():
        f = open('D:\Python练习\计算机二级教材(python)\小说txt\红楼梦.txt','r',encoding = 'utf-8')
        txt = f.read()
        f.close()
        jieba.load_userdict('D:\Python练习\计算机二级教材(python)\分词词典\红楼梦分词.txt')
        all_words = jieba.lcut_for_search(txt)
        words = []
        for i in all_words:
            if i in keyWord():
                words.append(i)
        return words
    
    def keyWord():
        f = open('D:\Python练习\计算机二级教材(python)\分词词典\红楼梦分词.txt','r',encoding = 'utf-8')
        txt = f.read()
        f.close()
        name = txt.split()
        return name
    
    def changeWord(words):
        with open('D:\Python练习\计算机二级教材(python)\分词词典\红楼梦替换词典.txt','r',encoding = 'utf-8') as f:
            txt = f.read()
        word_dict = eval(txt)
        keys = []
        values = []
        for k,v in word_dict.items():
            keys.append(k)
            values.append(v)
        for i in words:
            if i in keys:
                words.append(values[keys.index(i)])
        last_word = []
        for ch in words:
            if ch not in keys:
                last_word.append(ch)
        new_words = ' '.join(last_word)
        return last_word,new_words
    
    def wordCount(last_word):
        counts = {}
        for word in last_word:
            counts[word] = counts.get(word,0) + 1
        items = list(counts.items())
        items.sort(key = lambda x:x[1],reverse = True)
        for i in range(10):
            word,count = items[i]
            print("{0:<10}{1:>5}".format(word,count))
    
    def wordCloud(new_words):
        fontpath = 'STHUPO.TTF'
        wc = WordCloud(font_path = fontpath,
                       width=800,
                       height=600,
                       max_words=50,
                       max_font_size=150,
                       background_color = 'white', #背景板颜色
                       collocations = False,#去除重复单词 
                       ).generate(new_words) 
        wc.to_file('D:\Python练习\计算机二级教材(python)\红楼梦人物词云.png')  
    
    def main():
        words = getFile()
        last_word,new_words = changeWord(words)
        wordCount(last_word)
        wordCloud(new_words)
    
    main()
    





    (2)水浒传

    package javaapplication10;
    import java.io.*;
    
    public class JavaApplication10 {
    public static int count(String filename,String target)throws FileNotFoundException,IOException{
          FileReader fr=new FileReader(filename);
          BufferedReader br=new BufferedReader(fr);
          StringBuilder strb=new StringBuilder();
          while(true){
              String line=br.readLine();
              if(line==null){
                  break;
              }
              strb.append(line);
          }
          String result=strb.toString();
          int count=0;
          int index=0;
          while(true){
              index=result.indexOf(target,index+1);
              if(index>0){
                  count++;
              }
              else{
                  break;
              }
          }
          br.close();
          return count;
      }
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)throws FileNotFoundException,IOException {
            // TODO code application logic here
            String a="C:/Users/李敏/Desktop/软件工程/水浒传.txt";
            String n=null;
            String b[]={"宋江","鲁智深","花荣","武松","吴用","高俅","史进","卢俊义","李逵","林冲",
                "杨志","戴宗","时迁","公孙胜","孙二娘","顾大嫂","扈三娘"};
            int j1=count(a,b[0]),j2=count(a,b[1]),j3=count(a,b[2]),j4=count(a,b[3]),j5=count(a,b[4]),j6=count(a,b[5]),
                    j7=count(a,b[6]),j8=count(a,b[7]),j9=count(a,b[8]),j10=count(a,b[9]),j11=count(a,b[10]),j12=count(a,b[11]),
                    j13=count(a,b[12]),j14=count(a,b[13]),j15=count(a,b[14]),j16=count(a,b[15]), j17=count(a,b[16]);
            int num []={j1,j2,j3};
            try{
                System.out.println("宋江在文中出现的次数:"+count(a,b[0]));
                 System.out.println("鲁智深在文中出现的次数:"+count(a,b[1]));
                  System.out.println("花荣在文中出现的次数:"+count(a,b[2]));
                  System.out.println("武松在文中出现的次数:"+count(a,b[3]));
                  System.out.println("吴用在文中出现的次数:"+count(a,b[4]));
                  System.out.println("高俅在文中出现的次数:"+count(a,b[5]));
                  System.out.println("史进在文中出现的次数:"+count(a,b[6]));
                  System.out.println("卢俊义在文中出现的次数:"+count(a,b[7]));
                  System.out.println("李逵在文中出现的次数:"+count(a,b[8]));
                  System.out.println("林冲在文中出现的次数:"+count(a,b[9]));
                  System.out.println("杨志在文中出现的次数:"+count(a,b[10]));
                  System.out.println("戴宗在文中出现的次数:"+count(a,b[11]));
                  System.out.println("时迁在文中出现的次数:"+count(a,b[12]));
                  System.out.println("公孙胜在文中出现的次数:"+count(a,b[13]));
                  System.out.println("孙二娘在文中出现的次数:"+count(a,b[14]));
                  System.out.println("顾大嫂在文中出现的次数:"+count(a,b[15]));
                  System.out.println("扈三娘在文中出现的次数:"+count(a,b[16]));
                 
            }catch (FileNotFoundException e){
                e.printStackTrace();
            }catch (IOException e){
                e.printStackTrace();
            }
           
        }
        
    }
    

  • 相关阅读:
    PHP程序员应该知道的15个库
    MongoDB、Cassandra 和 HBase 三种 NoSQL 数据库比较
    四种常见的POST提交数据方式
    PHP中获取文件扩展名的N种方法
    【问底】徐汉彬:亿级Web系统搭建——单机到分布式集群(三)
    【问底】徐汉彬:亿级Web系统搭建——单机到分布式集群(二)
    【问底】徐汉彬:亿级Web系统搭建——单机到分布式集群(一)
    ZF框架数据对象映射模式的思考
    概念大集合:单一入口、MVC、ORM、CURD、ActiveRecord...
    有默认参数的函数,默认参数为何需后置
  • 原文地址:https://www.cnblogs.com/sunsijiao/p/12620514.html
Copyright © 2020-2023  润新知