第六周作业
组员:李肖华、陆遥
一、理论学习
1、完成《软件工程》的学习内容
2、关于UML建模
Unified Modeling Language (UML)又称统一建模语言或标准建模语言,是始于1997年一个OMG标准,它是一个支持模型化和软件系统开发的图形化语言,为软件开发的所有阶段提供模型化和可视化支持,包括由需求分析到规格,到构造和配置。 面向对象的分析与设计(OOA&D,OOAD)方法的发展在80年代末至90年代中出现了一个高潮,UML是这个高潮的产物。它不仅统一了Booch、Rumbaugh和Jacobson的表示方法,而且对其作了进一步的发展,并最终统一为大众所接受的标准建模语言。
其他建模方法优缺点:①Flowchartsl流程图:老式流程图的缺点是它们依赖于顺序流,不支持构成流程一部分的并行活动。因为使用这种类型的表示不能捕获那么多信息,所以它最好用于不需要太多详细说明的非常简单且可预测的流程。② 数据流图(Data Flow Diagram):简称 DFD,它从数据传递和加工角度,以图形方式来表达系统的逻辑功能、数据在系统内部的逻辑流向和逻辑变换过程,是结构化系统分析方法的主要表达工具是及用于表示软件模型的一种图示方法。③Gantt Charts甘特图:直观、简单、容易制作,便于理解,能很清晰地标识出直到每一项任务的起始与结束时间,一般适用比较简单的小型项目,可用于WBS的任何层次、进度控制、资源优化、编制资源和费用计划。不能系统地表达一个项目所包含的个项工作之间的复杂关系,难以进行定量的计算和分析,以及计划的优化等。
二、实践学习
本周
(
1 # -*- coding: UTF-8 -*- 2 import jieba.posseg as peg 3 import json 4 5 with open('唐诗三百首.txt',encoding='gbk') as f: 6 string = f.read() 7 8 #利用jieba将诗句分词并用词性筛选关键词 9 def extract_keyword(words): 10 global result 11 tem = peg.cut(words) 12 for word,flag in tem: 13 if flag == 'n' or flag == 'nr': 14 result = [] 15 result.append(word) 16 return result 17 18 #逐步建立字典 19 list = [] 20 list_poem = string.split('\n\n') 21 print(list_poem) 22 for i in range(len(list_poem)): #len(list_poem) 23 dic = {} 24 if list_poem[i][0].isdigit(): 25 words = list_poem[i+1].split('\n') 26 dic['id'] = int(list_poem[i][0:3]) 27 dic['line'] = len(words) 28 tem = list_poem[i].split(':') 29 dic['title'] = tem[1] 30 dic['author'] = tem[0][3:] 31 dic['text'] = words 32 keyword = [] 33 for j in range(len(words)): 34 word = extract_keyword(words[j]) 35 keyword.extend(word) 36 dic['keyword'] = keyword 37 list.append(dic) 38 39 with open('poetry_database2.json', 'w') as f: 40 str2='%s'%list 41 f.write(str2.replace('\'','\"').replace(',',',\n'))#将字典中的单引号换位双引号,并及时换行
(
1 # -*- coding: UTF-8 -*- 2 # Author: Lu Yao and Li Xiaohua 3 4 import json 5 import random 6 import time 7 import tkinter as tk 8 import tkinter.messagebox 9 from PIL import Image, ImageTk 10 11 12 def open_db(json_file): 13 text = open(json_file, "r", encoding="utf-8") 14 poetry_dict = json.load(text) 15 return poetry_dict 16 17 18 def img_process(jpg_file): 19 source_img = Image.open(jpg_file) 20 real_img = ImageTk.PhotoImage(source_img) 21 return real_img 22 23 24 def countdown(): 25 seconds = 100 26 time_lab = tk.Label(root, bg="white", fg="black", font=("微软雅黑", 14, "bold"), width=3, height=1, 27 relief="ridge", borderwidth=10) 28 time_lab.place(x=420, y=150) 29 for s in range(seconds, -1, -1): 30 try: 31 time_lab["text"] = s 32 root.update() 33 time.sleep(1) 34 except tk.TclError: 35 break 36 if s == 0: 37 tk.messagebox.showinfo(message="时间到!游戏结束!") 38 39 40 def show_labs(): 41 lab_1.place(x=0, y=0) 42 lab_2.place(x=100, y=0) 43 lab_3.place(x=200, y=0) 44 lab_4.place(x=300, y=0) 45 lab_5.place(x=0, y=100) 46 lab_6.place(x=100, y=100) 47 lab_7.place(x=200, y=100) 48 lab_8.place(x=300, y=100) 49 lab_9.place(x=0, y=200) 50 lab_10.place(x=100, y=200) 51 lab_11.place(x=200, y=200) 52 lab_12.place(x=300, y=200) 53 54 55 def random_sel(): 56 record = [] 57 poetry_dict = open_db("poetry_database.json") 58 start_btn.place_forget() 59 quit_btn.place(x=420, y=220) 60 start_bg.pack_forget() 61 play_bg.pack() 62 show_labs() 63 for i in range(100): 64 loc = random.randint(1, 100) 65 if loc not in record: 66 record.append(loc) 67 line_count = poetry_dict[loc - 1]["line"] 68 line_num = random.randint(1, line_count) 69 if len(record) == 1: 70 kwd_1.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 71 elif len(record) == 2: 72 kwd_2.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 73 elif len(record) == 3: 74 kwd_3.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 75 elif len(record) == 4: 76 kwd_4.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 77 elif len(record) == 5: 78 kwd_5.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 79 elif len(record) == 6: 80 kwd_6.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 81 elif len(record) == 7: 82 kwd_7.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 83 elif len(record) == 8: 84 kwd_8.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 85 elif len(record) == 9: 86 kwd_9.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 87 elif len(record) == 10: 88 kwd_10.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 89 elif len(record) == 11: 90 kwd_11.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 91 elif len(record) == 12: 92 kwd_12.set(poetry_dict[loc - 1]["keyword"][line_num - 1]) 93 countdown() 94 break 95 if loc in record: 96 continue 97 98 99 def close_window(): 100 if tk.messagebox.askokcancel(message="您确定要退出吗?"): 101 root.destroy() 102 103 104 def quit_game(): 105 if tk.messagebox.askokcancel(message="您确定要退出吗?"): 106 root.destroy() 107 108 109 root = tk.Tk() 110 root.title("出口成诗游戏") 111 root.geometry("520x300") 112 113 start_img = img_process("start.jpg") 114 start_bg = tk.Canvas(root, bg="white", width=520, height=300) 115 start_bg.create_image(260, 160, image=start_img) 116 start_bg.pack() 117 title = start_bg.create_text(260, 120, font=("微软雅黑", 50, "bold"), fill="Snow", text="出 口 成 诗") 118 play_img = img_process("play.jpg") 119 play_bg = tk.Canvas(root, width=520, height=300) 120 play_bg.create_image(260, 150, image=play_img) 121 122 kwd_1 = tk.StringVar() 123 kwd_2 = tk.StringVar() 124 kwd_3 = tk.StringVar() 125 kwd_4 = tk.StringVar() 126 kwd_5 = tk.StringVar() 127 kwd_6 = tk.StringVar() 128 kwd_7 = tk.StringVar() 129 kwd_8 = tk.StringVar() 130 kwd_9 = tk.StringVar() 131 kwd_10 = tk.StringVar() 132 kwd_11 = tk.StringVar() 133 kwd_12 = tk.StringVar() 134 135 start_btn = tk.Button(root, text="开始游戏", font=('微软雅黑', 14, "bold"), width=10, height=1, command=random_sel, relief= 136 "raised", borderwidth=10) 137 start_btn.place(x=190, y=220) 138 quit_btn = tk.Button(root, text="退出", font=('微软雅黑', 14, "bold"), width=5, height=1, command=quit_game, relief= 139 "raised", borderwidth=10) 140 141 lab_1 = tk.Label(root, textvariable=kwd_1, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 142 relief="raised", borderwidth=10) 143 lab_2 = tk.Label(root, textvariable=kwd_2, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 144 relief="raised", borderwidth=10) 145 lab_3 = tk.Label(root, textvariable=kwd_3, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 146 relief="raised", borderwidth=10) 147 lab_4 = tk.Label(root, textvariable=kwd_4, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 148 relief="raised", borderwidth=10) 149 lab_5 = tk.Label(root, textvariable=kwd_5, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 150 relief="raised", borderwidth=10) 151 lab_6 = tk.Label(root, textvariable=kwd_6, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 152 relief="raised", borderwidth=10) 153 lab_7 = tk.Label(root, textvariable=kwd_7, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 154 relief="raised", borderwidth=10) 155 lab_8 = tk.Label(root, textvariable=kwd_8, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 156 relief="raised", borderwidth=10) 157 lab_9 = tk.Label(root, textvariable=kwd_9, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2, 158 relief="raised", borderwidth=10) 159 lab_10 = tk.Label(root, textvariable=kwd_10, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2 160 , relief="raised", borderwidth=10) 161 lab_11 = tk.Label(root, textvariable=kwd_11, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2 162 , relief="raised", borderwidth=10) 163 lab_12 = tk.Label(root, textvariable=kwd_12, bg="red", fg="white", font=("微软雅黑", 14, "bold"), width=6, height=2 164 , relief="raised", borderwidth=10) 165 166 root.protocol('WM_DELETE_WINDOW', close_window) 167 root.mainloop()
总结:
学习阶段 | 学习内容 | 学习收获 |
2019.3.24 14:00-17:00 | 软件工程 | 对软件建模有了一定了解 |
2019.3.25 14:00-17:00 | UML资料查询 | 了解软件建模工具 |
2019.3.27 09:00-17:00 | 实践学习 | 编写诗句处理程序 |
2019.3.28 09:00-2100 | 实践学习 | 编写诗句处理程序 |