有没有免费做物流推荐的网站,国内wordpress空间,超级外链自动发布工具,六盘水市网站建设文章目录 前言一、环境实验所需的库终端指令 二、实现过程Version 1 起源Version 2 listVersion 3 arrayVersion 4 结构化数组Version 5 区分单元且打乱顺序Version 6 可视化 三、txt文件 前言 缘起自懒得考小孩儿单词#xff0c;最终效果如图#xff1a; 本文记录了英语单词… 文章目录 前言一、环境实验所需的库终端指令 二、实现过程Version 1 起源Version 2 listVersion 3 arrayVersion 4 结构化数组Version 5 区分单元且打乱顺序Version 6 可视化 三、txt文件 前言 缘起自懒得考小孩儿单词最终效果如图 本文记录了英语单词文本处理过程生成“试卷” PS单词docx文件来源于百度文库高校版单词txt文本附文末
一、环境
实验所需的库
import re
import numpy as np
from PIL import Image, ImageDraw, ImageFont终端指令
conda create -n DL python3.11conda activate DLconda install numpy pillow或
pip install numpy pillow二、实现过程 大过年的暂不对代码进行详细介绍其进化过程如下
Version 1 起源
import rewith open(./word.txt, r, encodingutf-8) as file:for line in file:if re.match(r^[A-Za-z*], line): # 使用正则表达式匹配以英文字母开头的行if Module in line:continueif [ not in line: # 如果行中没有 [print(无法解析的行:, line) # 直接输出行的内容continueword, pro_chinese line.strip().split([)pronunciation, meaning pro_chinese.strip().split(])pronunciation [ pronunciation ] # 将括号加回去meaning meaning.rstrip() # 去掉末尾的换行符print(单词:, word)print(音标:, pronunciation)print(中文:, meaning) Version 2 list 存储为列表
import rewords, pronunciations, meanings, modules [], [], [], []
with open(./word.txt, r, encodingutf-8) as file:current_module for line in file:if re.match(r^[A-Za-z*], line): # 使用正则表达式匹配以英文字母开头的行if Module in line:current_module line.strip()# print(current_module)continueif [ not in line: # 如果行中没有 [# print(无法解析的行:, line) # 直接输出行的内容continueword, pro_chinese line.strip().split([)pronunciation, meaning pro_chinese.strip().split(])pronunciation [ pronunciation ] # 将括号加回去meaning meaning.rstrip() # 去掉末尾的换行符# print(单词:, word)# print(音标:, pronunciation)# print(中文:, meaning)words.append(word)pronunciations.append(pronunciation)meanings.append(meaning)modules.append(current_module)for i in range(len(words)):print(modules[i], words[i], pronunciations[i], meanings[i])Version 3 array 存储为array数组
import re
import numpy as npwords, pronunciations, meanings np.array([]), np.array([]), np.array([])with open(./word.txt, r, encodingutf-8) as file:current_module for line in file:if re.match(r^[A-Za-z*], line): # 使用正则表达式匹配以英文字母开头的行if Module in line:current_module line.strip()print(current_module)continueif [ not in line: # 如果行中没有 [print(无法解析的行:, line) # 直接输出行的内容continueword, pro_chinese line.strip().split([)pronunciation, meaning pro_chinese.strip().split(])pronunciation [ pronunciation ] # 将括号加回去meaning meaning.rstrip() # 去掉末尾的换行符words np.append(words, word)pronunciations np.append(pronunciations, pronunciation)meanings np.append(meanings, meaning)for i in range(len(words)):print(单词:, words[i])print(音标:, pronunciations[i])print(中文:, meanings[i])Version 4 结构化数组 进化为结构化数组
import re
import numpy as np# 定义结构化数组的数据类型
dt np.dtype([(word, U50), (pronunciation, U50), (meaning, U50)])# 创建空的结构化数组
data np.array([], dtypedt)with open(./word.txt, r, encodingutf-8) as file:for line in file:if re.match(r^[A-Za-z*], line): # 使用正则表达式匹配以英文字母开头的行if Module in line:continueif [ not in line: # 如果行中没有 [# print(无法解析的行:, line) # 直接输出行的内容continueword, pro_chinese line.strip().split([)pronunciation, meaning pro_chinese.strip().split(])pronunciation [ pronunciation ] # 将括号加回去meaning meaning.rstrip() # 去掉末尾的换行符new_data np.array([(word, pronunciation, meaning)], dtypedt) # 创建包含当前单词数据的结构化数组data np.append(data, new_data) # 将当前单词数据添加到总的结构化数组中for i in data:print(i)Version 5 区分单元且打乱顺序 区分单元且打乱顺序
import re
import numpy as np# 定义结构化数组的数据类型
dt np.dtype([(module, U50), (word, U50), (pronunciation, U50), (meaning, U50)])# 创建空的结构化数组
data np.array([], dtypedt)with open(./word.txt, r, encodingutf-8) as file:current_module for line in file:if re.match(r^[A-Za-z*], line): # 使用正则表达式匹配以英文字母开头的行if Module in line:current_module line.strip()# print(current_module)continueif [ not in line: # 如果行中没有 [# print(无法解析的行:, line) # 直接输出行的内容continueword, pro_chinese line.strip().split([)pronunciation, meaning pro_chinese.strip().split(])pronunciation [ pronunciation ] # 将括号加回去meaning meaning.rstrip() # 去掉末尾的换行符new_data np.array([(current_module, word, pronunciation, meaning)], dtypedt) # 创建包含当前单词数据的结构化数组data np.append(data, new_data) # 将当前单词数据添加到总的结构化数组中np.random.shuffle(data)
# 打印打乱顺序后的数组
print(data[0][word])
print(len(data))
for d in data:print(d)
for d in data:if d[module] Module 1:print(d) Version 6 可视化 可视化
import re
import numpy as np
from PIL import Image, ImageDraw, ImageFont# 定义结构化数组的数据类型
dt np.dtype([(module, U50), (word, U50), (pronunciation, U50), (meaning, U50)])# 创建空的结构化数组
data np.array([], dtypedt)with open(./word.txt, r, encodingutf-8) as file:current_module for line in file:if re.match(r^[A-Za-z*], line): # 使用正则表达式匹配以英文字母开头的行if Module in line:current_module line.strip()print(current_module)continueif [ not in line: # 如果行中没有 [print(无法解析的行:, line) # 直接输出行的内容continueword, pro_chinese line.strip().split([)pronunciation, meaning pro_chinese.strip().split(])pronunciation [ pronunciation ] # 将括号加回去meaning meaning.rstrip() # 去掉末尾的换行符new_data np.array([(current_module, word, pronunciation, meaning)], dtypedt) # 创建包含当前单词数据的结构化数组data np.append(data, new_data) # 将当前单词数据添加到总的结构化数组中# 打印数组
print(data[0][word])
print(len(data))
for d in data:if d[module] Module 1:print(d)np.random.shuffle(data)
# 打印打乱顺序后的数组
print(data)
# dt np.dtype([(module, U50), (word, U50), (pronunciation, U50), (meaning, U50)])problem_image Image.new(RGB, (800, 1200), colorwhite)
draw ImageDraw.Draw(problem_image)
# font ImageFont.truetype(arial.ttf, 25)
c_font ImageFont.truetype(STKAITI.TTF, 25) # 华文楷体
e_font ImageFont.truetype(times.ttf, 25) # times new Romantext_y 100
draw.text((300, 20), English Problems, fillblue, fonte_font)
for i in range(20):draw.text((50, text_y), str(i1) data[i][word], fillblack, fonte_font)draw.text((350, text_y), str(i 21) data[i20][meaning], fillblack, fontc_font)text_y 50problem_image.save(en_problems_3.png)# Generate a combined image of the answers
answer_image Image.new(RGB, (800, 1200), colorwhite)
draw ImageDraw.Draw(answer_image)text_y 100
draw.text((300, 20), English Problems, fillblue, fonte_font)
for i in range(20):draw.text((50, text_y), str(i1) data[i][meaning], fillblack, fontc_font)draw.text((450, text_y), str(i 21) data[i20][word], fillblack, fonte_font)text_y 50answer_image.save(en_answers_3.png)问题左侧前20英译汉右侧汉译英 答案 三、txt文件
外研社小学英语五年级下册(三年级起点)单词表(带音标)
Module 1 still[stil]还仍然 Programme’prəugræm节目 lady[leidi]女士夫人 life[laif]生活 different[difrənt]不同的 ago[ə’gəu]以前 Interviewer[intɚvjuɚ]采访者 enough[i’nʌf]足够的 television[teliviiʒ(ə)n]电视机 *grandchildren’græn’tʃildrən外孙子女 change[tʃendʒ]改变变化 night[nait]夜晚夜间 work[wɜ:k]工作劳动干活儿 field[fi:ld]田地 fire[faiə]火,炉火 orɔ:也不也没 radio[reidiəu]收音机 telephone[telifəun]电话 couldntcould not不能 write[rait]写 hope[həup]希望
Module 2 learnt[lɜ:nt]learn的过去式学习 taughttɔ:t教讲授 language[læŋgwidʒ]语言 wroterəut写 dancer[dɑ:nsə®] 舞蹈演员 foreign[fɔrən]外国的 studied’stʌdid学习 hard[hɑ:d]努力地
Module 3 hamburger[hæmbɜ:gə®]汉堡 English[iŋgliʃ]英国式的 breakfast[brekfəst]早餐早饭 lunch[lʌntʃ]午餐午饭 sandwich[sænwitʃ]三明治 fish and chips炸鱼加炸薯条 traditional[trə’diʃənl]传统的 dish[diʃ]食品菜肴 very much[veri mʌtʃ]很非常 gave[geiv]give的过去式给 tonight[tə’nait]今夜今晚
Module 4 library[laibrəri]图书馆 student[stju:dnt]学生 sentsent发送寄 *CD 激光唱片光盘 idea[ai’diə]主意想法 put[put]放安放 *shelf[ʃelf]架子 heavy[hevi]重的沉的 dictionary[dikʃənri]词典;字典 card[kɑ:d]卡片 library card图书卡借书证 ask[ɑ:sk]邀请 wrong[rɔ:ŋ]错误的 dear[diə®]哎呀 information[ˌinfə’meiʃn]信息 *e-book电子书 project[prɔdʒekt]项目 guide[gaid]介绍指南手册 film[film]电影 as well又还也 way[wei]方法方式 on[ɔn]关于 *topic[tɔpik]话题
Module 5 light[lait]轻的 hard[hɑ:d]困难的费力的 *broken[brəukən]坏的破的 department store[di’pɑ:tmənt stɔ:]百货商店 pocket[pɔkit]口袋兜 umbrella[ʌm’brelə]雨伞 sales assistant[seilz ə’sistənt]售货员营业员 wheel[wi:l]轮子 easy[i:zi]容易的不费力的 take[teik]选择要选择购买 too[tu:]太过于 try[trai]试尝试 lovely[lʌvli]美丽的可爱的令人愉快的
Module 6 moon[mu:n]月亮月球 get[ɡet]到达 west[west]西西部西方向西方 parent[peərənt]母亲父亲家长 stay[stei]停留 July[dʒu’lai]七月 south[sauθ]南南部南方向南方 remember[ri’membə®]记得 June[dʒu:n]六月 east[i:st]东东部东方向东方 best[best]最好的 north[nɔ:θ]北北部北方向北方 rest[rest]休息 have a rest休息一下 rode[rəud]ride的过去式骑
Module 7 evening[i:vniŋ]傍晚晚上 late[leit]近日暮的近深夜的时间不早的 worker[wɜ:kə®]工人 factory[fæktri]制造厂工厂 early[ɜ:li]早的 taxi[tæksi]出租车计程车 quarter[kwɔ:tə®]一刻钟 to[tu,tə]距整点差… worry[wʌri]焦虑担心
Module 8 paper[peipə®]纸 Chinese[ˌtʃai’ni:z]中国人的 so[səʊ]如此这样 word[wɜ:d]词字 drewdru:画 cutkʌt剪切割 piece[pi:s]张片块 paint[peint]用颜料绘画着色 putput放安放 stick[stik]小木棍小木条 tied[taid]tie的过去式扎上系上 *string[striŋ]线绳子
Module 9 laugh[lɑ:f]笑 worewɔ:®穿 letter[letə®]信书信 theatre[θiətə]剧院 women’wimin女性妇女 actor[æktə®]演员 toldtəuld口述讲(故事等) joke[dʒəuk]笑话 after[ɑ:ftə®]在……以后 showʃəu演出表演 restaurant[restrɔnt]饭店餐馆 readri:d读 at all[æt ɔ:l]一点都 in[in]在将来一段时间之后 another[ə’nʌðə®]另一个 history[histri]历史 ask[ɑ:sk]问询问 question[kwestʃən]问题 forget[fə’get]忘忘记 bring[briŋ]带来拿来 soon[su:n]不久,很快
Module 10 when[wen]在什么时候 end[end]结束终止 nervous[nɜ:vəs]紧张的情绪不安的 all right[ɔ:l rait]没事没问题 airport[eəpɔ:t]机场 ticket[tikit]票 passport[pɑ:spɔ:t]护照 safe[seif]安全的平安的 pet[pet]宠物 speak[spi:k]说讲 building[bildiŋ]建筑物 American[ə’merikən]美国的美国人的美国人 find out[faind aut]发现弄清 more[mɔ:®]更多的量较多的量