zoukankan      html  css  js  c++  java
  • 20180918-1 词频统计

    作业要求参见 https://edu.cnblogs.com/campus/nenu/2018fall/homework/2126

    本次作业代码地址:https://coding.net/u/y45777704/p/WF/git/tree/origin/dist

    词频统计

     

    1.代码部分

    2.1代码实现#调用函数(系统模块、正则表达式、采集模块等)

    import sys
    # print("Input argument is %s" %(sys.argv))
    import re
    import collections
    import operator
    # file = input('请输入文件位置:')
    # for line in open(add):
    #     print(line)
    import glob

    2.2词频统计部分

     def get_words(file):
            with open(file,encoding='gbk') as f:
                words_box = []
                for line in f:
                    if re.match(r'[a-zA-Z0-9]*', line):
                        words_box.extend(line.strip().split())
            return collections.Counter(words_box)

    2.3输出词频统计

        for file in file_list:
            #print(file)
            a = get_words(file)
            print("total    %d" % len(a))
            print()
            a10 = collections.Counter.most_common(a, 10)
            #print(a10)
            # l = sorted(a.items(), key=operator.itemgetter(0), reverse=True)
            for item in a10:
                print("{key}	{value}".format(key=item[0], value=item[1]))
            print("")

    3.功能实现

    3.1从TXT文件中统计总字数,输出总字数并打印词语出现频率次数,降序输出。

    3.2统计jane_Eyre的总字数和词频

    3.3统计test文件夹中的Jane_Eyre和Wuthering_Heights的文本字数及词频

    3.4尝试用command = input()输入指令实现功能,但没有成功。

    4.PSP表格

     

    PSP阶段 预计时间(min) 实际时间(min) 原因
    第一功能 125 217 需求没有明确分析,没能输入单词,导致功能错误。
    第二功能 62 73 没有找到功能函数,导致编码错误。
    第三功能 146 172 没有输出正确的格式,一直在调整。
    第四功能 35 69 没能实现功能
  • 相关阅读:
    P5331 [SNOI2019]通信
    P3700 [CQOI2017]小Q的表格
    Linux
    P3268 [JLOI2016]圆的异或并
    P3317 [SDOI2014]重建
    P5492 [PKUWC2018]随机算法
    P3210 [HNOI2010]取石头游戏
    支配树
    P5401 [CTS2019]珍珠
    P4027 [NOI2007]货币兑换
  • 原文地址:https://www.cnblogs.com/yangjm137/p/9695894.html
Copyright © 2011-2022 走看看