花了一小时,拿python手搓了一个考研背单词软件

本文介绍了一位开发者用Python编写的自定义考研背单词软件,利用SQLite存储数据,利用Jarowinkler距离和BERT模型的词嵌入实现形近词和近义词跳转。代码已开源,包含6646个考研单词及索引。
摘要由CSDN通过智能技术生成

听说没有好用的电脑端背单词软件?只好麻烦一下,花了一小时,拿python手搓了一个考研背单词软件。
在这里插入图片描述
代码已经开源在我的github上,欢迎大家STAR!
其中,数据是存放在sqlite中,形近词跳转是根据jaro winkler距离得到最近单词的,近义词跳转是使用huggingface上的bert-base-uncased模型得到的词嵌入向量,然后计算cosine相似距离得到的。这部分代码没有开源,大家可以自行实现,开源项目中包含了6646个考研必备单词及索引,可以正常使用检索功能。
数据库的建表语句如下,下载之后可以自己导出数据,获得完整单词库。

c.execute('''DROP TABLE IF exists process;''')
c.execute("CREATE TABLE process(id INTEGER);")
c.execute('''DROP TABLE IF exists words;''')
c.execute('''CREATE TABLE IF NOT EXISTS words(id INTEGER PRIMARY KEY AUTOINCREMENT, word TEXT, en TEXT, us TEXT, meaning TEXT, count INTEGER)''')

以后有空再来补充一些具体做法!

  • 27
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
好的,我可以为您提供一个简单的背单词软件的开发方案: 1. 确定数据源:可以使用外部的单词库,或者自己爬取单词库进行使用。可以考虑使用Python的requests和beautifulsoup库进行爬取和解析。 2. 设计界面:可以使用Python的GUI库Tkinter,设计一个简单的界面,包括显示单词和释义的窗口、输入框、按钮等控件。 3. 实现功能:实现单词的随机抽取和显示、输入框输入单词并判断是否正确、显示正确率等功能。 下面是一个简单的代码示例,可以作为参考: ```python import random import tkinter as tk class WordGame(): def __init__(self, master): self.master = master master.title("背单词软件") # 单词库 self.word_dict = {'apple': '苹果', 'banana': '香蕉', 'orange': '橙子', 'grape': '葡萄'} self.word_list = list(self.word_dict.keys()) self.current_word = '' self.current_meaning = '' # 生成控件 self.label_word = tk.Label(master, text='', font=('Arial', 20)) self.label_word.pack() self.entry_word = tk.Entry(master, font=('Arial', 20)) self.entry_word.pack() self.button_submit = tk.Button(master, text='提交', font=('Arial', 20), command=self.submit_word) self.button_submit.pack() self.label_result = tk.Label(master, text='', font=('Arial', 20)) self.label_result.pack() self.label_accuracy = tk.Label(master, text='', font=('Arial', 20)) self.label_accuracy.pack() # 随机抽取一个单词 self.get_new_word() def get_new_word(self): self.current_word = random.choice(self.word_list) self.current_meaning = self.word_dict[self.current_word] self.label_word.config(text=self.current_word) self.entry_word.delete(0, tk.END) self.label_result.config(text='') def submit_word(self): input_word = self.entry_word.get() if input_word == self.current_meaning: self.label_result.config(text='正确') self.label_result.config(fg='green') self.get_new_word() else: self.label_result.config(text='错误') self.label_result.config(fg='red') accuracy = len(self.word_list) / len(self.word_dict) * 100 self.label_accuracy.config(text='正确率:%.2f%%' % accuracy) root = tk.Tk() game = WordGame(root) root.mainloop() ``` 这个示例中,我们使用了字典来存储单词和释义,使用了Tkinter库来实现简单的GUI界面。当然,这只是一个简单的示例,您可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛钦亮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值