zoukankan      html  css  js  c++  java
  • 词频统计 SPEC

    此作业的要求参见 https://edu.cnblogs.com/campus/nenu/2020Fall/homework/11206

    功能1 小文件输入。 为表明程序能跑,结果真实而不是迫害老五,请他亲自键
    盘在控制台下输入命令。

    重点/难点 :

    (1)如何将.py文件打包成.exe文件

    详情见:https://www.cnblogs.com/smart-zihan/p/11881172.html

    (2)如何处理标点符号问题

    字符预处理:

    def openFile(filePath):
        with open(filePath, "r", encoding="utf-8") as file:
            filecontent = file.read()
            for replaceChar in '!"#$&()*+,-./:;<=>?@[\]^_{|}·~“”‘’':
                filecontent = filecontent.replace(replaceChar, " ")
        return filecontent.lower().split()

    执行效果图:

    功能2 支持命令行输入英文作品的文件名,请老五亲自录入。

    重点/难点:对大量数据的处理

    代码:

    def sortAndprint(wordList):
        print("
    ")
        wordDict = {}
        for word in wordList:
            wordDict[word] = wordDict.get(word, 0) + 1
        wordDict_List=list(wordDict.items())
        wordDict_List.sort(key=lambda x:x[1],reverse=True)
        print("{0:<10}{1}".format('total',len(wordDict_List)))
        if(len(wordDict_List) > 10):
            for i in range(10):
                word,count =wordDict_List[i]
                print("{0:<10}{1}".format(word,count))
        else:
            for i in range(len(wordDict_List)):
                word,count =wordDict_List[i]
                print("{0:<10}{1}".format(word,count))
        return

    截图:

    功能3 支持命令行输入存储有英文作品文件的目录名,批量统计。

    代码:

    elif ((args.filePath != None) and (os.path.isdir(args.filePath) == True) and (args.s == None)):
        filePathList = os.listdir(args.filePath)
        for file in filePathList:
            print('File:' + file.split('.')[0])
            sortAndprint(openFile(args.filePath + '\' + file))
        pass

    截图:

    功能4 从控制台读入英文单篇作品,这不是为了打脸老五,而是为了向你女朋
    友炫酷,表明你能提供更适合嵌入脚本中的作品(或者如她所说,不过是更灵活
    的接口)。如果读不懂需求,请教师兄师姐,或者 bing: linux 重定向,尽管
    这个功能在windows下也有,搜索关键词中加入linux有利于迅速找到。

    重点/难点:对重定向的理解

    代码:

    elif ((args.filePath != None) and(os.path.isfile(args.filePath) != True) and (args.s == None) and (os.path.isdir(args.filePath) != True)):
        #print('File:' + args.filePath)
        args.filePath=args.filePath+".txt"
        sortAndprint(openFile(args.filePath))
        pass    

    截图:

    PSP表格

    PSP阶段 预计花费时间 实际花费时间 原因
    功能1 126min 139min 对于python知识的不熟悉,不会处理标点符号
    功能2 130min 148min 其他事情耽搁
    功能3 104min 165min 学习python中读取流知识
    功能4 150min 196min 理解重定向概念

    代码及版本控制
    (5分。虽然只有5分,但此题如果做错,因为教师得不到你的代码,所以会导致“功能实现”为负分。)
    代码要求在 coding.net 做版本控制。要求push&pull时使用git客户端,不允许使用web页面。

     答:

    (感谢李思源同学在微信群里的指出,已把项目设置为公开项目)

    (由于在做补充作业git pull测试的时候,出现问题,导致重新创建了本地仓库,重新上传到了github上,所以代码的地址和github的地址做了更改。)

    原始代码地址:

    https://a123098.coding.net/p/word/d/jia_word/git

    更改后代码地址:

    https://e.coding.net/a123098/word/word-py.git

    原始github地址:

    https://github.com/jia-alt/test2.git

    更改后github代码地址:

    https://github.com/jia-alt/test3.git

  • 相关阅读:
    转:五年java人的一点感悟
    6:ZigZag Conversion
    5:Longest Palindromic Substring
    4:Median of Two Sorted Arrays
    3:Longest Substring Without Repeating Characters
    读写分离
    docker swarm部署spring cloud服务
    kubeadm方式安装kubernetes
    《Spring Boot 实战》随记
    https部署
  • 原文地址:https://www.cnblogs.com/jia123/p/13718364.html
Copyright © 2011-2022 走看看