From 1e6c4c6da0e7c28d29f5d961b20a252cb23f258e Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Fri, 10 Jun 2022 19:06:23 +0800
Subject: [PATCH 1/7] =?UTF-8?q?[IMPROVE]:.gitignore:=E5=BF=BD=E7=95=A5pyth?=
=?UTF-8?q?on=E5=AD=97=E8=8A=82=E7=A0=81=E7=BC=93=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore
index 413c71c..09cd91c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,5 @@ app/static/frequency/frequency.p
app/static/wordfreqapp.db
app/static/donate-the-author.jpg
app/static/donate-the-author-hidden.jpg
+
+**/__pycache__
\ No newline at end of file
--
2.17.1
From 3e554c61c990db41a84702ae2da661adc488e57c Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Fri, 10 Jun 2022 19:13:47 +0800
Subject: [PATCH 2/7] =?UTF-8?q?[BugFix]:requirements.txt:=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8DFlask1=E7=89=88=E6=9C=AC=E4=B8=8D=E5=85=BC=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
ImportError: cannot import name 'escape' from 'jinja2'
---
requirements.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/requirements.txt b/requirements.txt
index 2746a3b..f431e0a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-Flask==1.1.2
+Flask==2.1.2
selenium==3.141.0
PyYAML~=6.0
--
2.17.1
From f214838cdd2ae459582bf6ed50a6b832dfd28c02 Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Fri, 10 Jun 2022 19:20:18 +0800
Subject: [PATCH 3/7] =?UTF-8?q?[IMPROVE]:create=5FclozeTest.py:=E7=94=9F?=
=?UTF-8?q?=E6=88=90=E5=AE=8C=E5=9E=8B=E5=A1=AB=E7=A9=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/cloze/create_clozeTest.py | 122 ++++++++++++++++++++++++++++++++++
requirements.txt | 1 +
2 files changed, 123 insertions(+)
create mode 100644 app/cloze/create_clozeTest.py
diff --git a/app/cloze/create_clozeTest.py b/app/cloze/create_clozeTest.py
new file mode 100644
index 0000000..c11dc31
--- /dev/null
+++ b/app/cloze/create_clozeTest.py
@@ -0,0 +1,122 @@
+import random
+import sqlite3,re
+from nltk.corpus import wordnet as wn
+
+class Essay:
+ def __init__(self):
+ self._article_id = 0
+ self._essay = None
+ self._difficulty = None
+ self._answers = None
+ self._questions = None
+ pass
+
+ @property
+ def article_id(self):
+ pass
+
+ @article_id.setter
+ def article_id(self,article_id):
+ self._article_id = article_id
+ self.find_essay_in_database(self._article_id)
+
+ #获取数据库中的文章和等级
+ def find_essay_in_database(self,id):
+ try:
+ # 连接数据库
+ conn = sqlite3.connect("static/wordfreqapp.db")
+ # 创建游标
+ cursor = conn.cursor()
+ cursor.execute("select text,level from article where article_id = "+str(id))
+ results = cursor.fetchall()
+ conn.commit()
+ cursor.close()
+ conn.close()
+ self._essay = results[0][0]
+ self._difficulty = results[0][1]
+ return results
+ except Exception as e:
+ print(e)
+
+ #将文章分割成单词列表
+ def split_essay_to_word(self):
+ article = "".join(self._essay)
+ words = re.split(r"\b[\.,\s\n\r\n\$\']+?\b", article)
+ word_list = [word.lower() for word in words]
+ return word_list
+
+ #从数据库中查找和文章难度相同的单词
+ def find_same_difficulty_words(self):
+ result_list = []
+ try:
+ # 连接数据库
+ conn = sqlite3.connect("static/wordfreqapp.db")
+ # 创建游标
+ cursor = conn.cursor()
+ cursor.execute("select word from words where difficulty = " + str(self._difficulty))
+ results = cursor.fetchall()
+ conn.commit()
+ cursor.close()
+ conn.close()
+ for result in results:
+ for res in result:
+ result_list.append(res)
+ return result_list
+ except Exception as e:
+ print(e)
+
+ #获取单词的近义词
+ def get_word_synsets(self,word):
+ synsets_set = wn.synsets(word)
+ synset_list = []
+ for synset in synsets_set:
+ synset_list.append(synset.name().split(".")[0])
+ return synset_list
+
+ #生成完形填空
+ def create_clozeTest(self,essay):
+ essay.article_id = self._article_id
+ word = [] # 存放文章中含有的与文章难度相同的单词
+ answers = [] # 存放正确答案
+ questions = [] # 存放题目
+
+ database_words = essay.find_same_difficulty_words()
+ essay_words = essay.split_essay_to_word()
+ for essay_word in essay_words:
+ if database_words.__contains__(essay_word) and essay_word not in word:
+ word.append(essay_word)
+
+ if len(word) <= 10:
+ answers = word
+ else:
+ for i in range(0, 10):
+ w = word[random.randint(0, len(word) - 1)]
+ if not answers.__contains__(w):
+ answers.append(w)
+
+ self._answers = answers
+
+ No = 1
+ for answer in answers:
+ questions.append(list(answer.split(",")))
+ self._essay = self._essay.replace(answer,'('+str(No)+')____', 1)
+ No += 1
+
+ for question in questions:
+ synset = list(set(essay.get_word_synsets(question[0])))
+ if len(synset) == 0 or len(synset) == 1:
+ question.append(word[random.randint(0, len(word) - 1)])
+ else:
+ syn = synset[random.randint(0, len(synset) - 1)]
+ while (syn == question[0]):
+ syn = synset[random.randint(0, len(synset) - 1)]
+ question.append(syn)
+
+ while len(question) < 4:
+ add_word = word[random.randint(0, len(word) - 1)]
+ while question.__contains__(add_word):
+ add_word = word[random.randint(0, len(word) - 1)]
+ question.append(add_word)
+ random.shuffle(question)
+
+ self._questions = questions
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index f431e0a..fcb5910 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
Flask==2.1.2
selenium==3.141.0
PyYAML~=6.0
+nltk==3.7
\ No newline at end of file
--
2.17.1
From 4870772f1f9a9c23e207485ef020322f1223fdc8 Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Fri, 10 Jun 2022 19:23:14 +0800
Subject: [PATCH 4/7] =?UTF-8?q?[IMPROVE]:clozeTest.html,userpage=5Fget.htm?=
=?UTF-8?q?l:=E5=AE=8C=E5=9E=8B=E5=A1=AB=E7=A9=BA=E9=A1=B5=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/templates/clozeTest.html | 56 +++++++++++++++++++++++++++++++++
app/templates/userpage_get.html | 4 +++
2 files changed, 60 insertions(+)
create mode 100644 app/templates/clozeTest.html
diff --git a/app/templates/clozeTest.html b/app/templates/clozeTest.html
new file mode 100644
index 0000000..52a4f44
--- /dev/null
+++ b/app/templates/clozeTest.html
@@ -0,0 +1,56 @@
+
+
+
+
+ clozeTest
+
+
+
+
+
+
{{ msg }}
+{% set ascll = ['A','B','C','D'] %}
+
{{ essay._essay }}
+
+
+
请输入abcd或其大写
+
tip:异常输入会被自动清除
+
+
+
\ No newline at end of file
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index 19542c1..bbf2107 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -32,6 +32,10 @@
阅读文章并回答问题
{{ today_article|safe }}
+
+
生词高亮
大声朗读
划词入库
--
2.17.1
From 241708af9c443d1a324c55fffde7b213cd329f81 Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Fri, 10 Jun 2022 19:24:58 +0800
Subject: [PATCH 5/7] =?UTF-8?q?[IMPROVE]:main.py:=E5=AE=8C=E5=9E=8B?=
=?UTF-8?q?=E5=A1=AB=E7=A9=BA=E8=AF=B7=E6=B1=82=E5=92=8C=E8=AE=A1=E5=88=86?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/cloze/__init__.py | 0
app/main.py | 39 +++++++++++++++++++++++++++++++--------
2 files changed, 31 insertions(+), 8 deletions(-)
create mode 100644 app/cloze/__init__.py
diff --git a/app/cloze/__init__.py b/app/cloze/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/app/main.py b/app/main.py
index d903bf4..3b3b3b7 100644
--- a/app/main.py
+++ b/app/main.py
@@ -11,6 +11,7 @@ from Article import *
import Yaml
from user_service import userService
from account_service import accountService
+from cloze.create_clozeTest import Essay
app = Flask(__name__)
app.secret_key = 'lunch.time!'
@@ -68,9 +69,10 @@ def mark_word():
for word in request.form.getlist('marked'):
lst.append((word, 1))
d = pickle_idea.merge_frequency(lst, lst_history)
- pickle_idea.save_frequency_to_pickle(d, path_prefix + 'static/frequency/frequency.p')
+ pickle_idea.save_frequency_to_pickle(
+ d, path_prefix + 'static/frequency/frequency.p')
return redirect(url_for('mainpage'))
- else: # 不回应GET请求
+ else: # 不回应GET请求
return 'Under construction'
@@ -88,7 +90,8 @@ def mainpage():
d = load_freq_history(path_prefix + 'static/frequency/frequency.p')
lst_history = pickle_idea.dict2lst(d)
d = pickle_idea.merge_frequency(lst, lst_history)
- pickle_idea.save_frequency_to_pickle(d, path_prefix + 'static/frequency/frequency.p')
+ pickle_idea.save_frequency_to_pickle(
+ d, path_prefix + 'static/frequency/frequency.p')
return render_template('mainpage_post.html', lst=lst, yml=Yaml.yml)
elif request.method == 'GET': # when we load a html page
@@ -101,14 +104,34 @@ def mainpage():
d_len=d_len, lst=lst, yml=Yaml.yml)
+essay = Essay()
+
+
+@app.route('/goCroze', methods=['GET', 'POST'])
+def go_ClozeTest():
+ if request.method == 'GET':
+ essay._article_id += 1
+ essay.create_crozeTest(essay)
+
+ return render_template('clozeTest.html', essay=essay, answers=None)
+ if request.method == 'POST':
+ score = 0
+ # submit_answers = []
+ questions = essay._questions
+ answers = essay._answers
+
+ for i in range(0, len(answers)):
+ ans = request.form.get('answer' + str(i+1))
+ if ans:
+ ans = ans.upper()
+ no = ord(ans)-ord('A')
+ if questions[i][no] == answers[i]:
+ score += 10
+ return render_template('clozeTest.html', essay=essay, msg=f'你的分数是: {score}', answers=answers)
+
if __name__ == '__main__':
'''
运行程序
'''
- # app.secret_key = os.urandom(16)
- # app.run(debug=False, port='6000')
app.run(debug=True)
- # app.run(debug=True, port='6000')
- # app.run(host='0.0.0.0', debug=True, port='6000')
- # print(mod5('123'))
--
2.17.1
From 0117470ab523e83a1f37d6be40d0a997d394b5e6 Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Tue, 14 Jun 2022 21:53:20 +0800
Subject: [PATCH 6/7] =?UTF-8?q?WIP:[BugFix]:main.py:=E8=B7=B3=E8=BD=AC?=
=?UTF-8?q?=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/main.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/main.py b/app/main.py
index 3b3b3b7..7bbcdff 100644
--- a/app/main.py
+++ b/app/main.py
@@ -107,11 +107,11 @@ def mainpage():
essay = Essay()
-@app.route('/goCroze', methods=['GET', 'POST'])
+@app.route('/gocloze', methods=['GET', 'POST'])
def go_ClozeTest():
if request.method == 'GET':
essay._article_id += 1
- essay.create_crozeTest(essay)
+ essay.create_clozeTest(essay)
return render_template('clozeTest.html', essay=essay, answers=None)
if request.method == 'POST':
--
2.17.1
From 9d5175d0a6bc40666a1ce555c2b201c69049afc1 Mon Sep 17 00:00:00 2001
From: stfujnkk <3365310020@qq.com>
Date: Tue, 14 Jun 2022 22:01:44 +0800
Subject: [PATCH 7/7] =?UTF-8?q?WIP:[REFACTOR]:main.py,create=5FclozeTest.p?=
=?UTF-8?q?y:=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/cloze/create_clozeTest.py | 39 ++++++++++++++++++++---------------
app/main.py | 4 ++++
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/app/cloze/create_clozeTest.py b/app/cloze/create_clozeTest.py
index c11dc31..fb6021e 100644
--- a/app/cloze/create_clozeTest.py
+++ b/app/cloze/create_clozeTest.py
@@ -1,7 +1,9 @@
import random
-import sqlite3,re
+import sqlite3
+import re
from nltk.corpus import wordnet as wn
+
class Essay:
def __init__(self):
self._article_id = 0
@@ -16,18 +18,19 @@ class Essay:
pass
@article_id.setter
- def article_id(self,article_id):
+ def article_id(self, article_id):
self._article_id = article_id
self.find_essay_in_database(self._article_id)
- #获取数据库中的文章和等级
- def find_essay_in_database(self,id):
+ # 获取数据库中的文章和等级
+ def find_essay_in_database(self, id):
try:
# 连接数据库
conn = sqlite3.connect("static/wordfreqapp.db")
# 创建游标
cursor = conn.cursor()
- cursor.execute("select text,level from article where article_id = "+str(id))
+ cursor.execute(
+ "select text,level from article where article_id = "+str(id))
results = cursor.fetchall()
conn.commit()
cursor.close()
@@ -38,14 +41,14 @@ class Essay:
except Exception as e:
print(e)
- #将文章分割成单词列表
+ # 将文章分割成单词列表
def split_essay_to_word(self):
article = "".join(self._essay)
words = re.split(r"\b[\.,\s\n\r\n\$\']+?\b", article)
word_list = [word.lower() for word in words]
return word_list
- #从数据库中查找和文章难度相同的单词
+ # 从数据库中查找和文章难度相同的单词
def find_same_difficulty_words(self):
result_list = []
try:
@@ -53,7 +56,8 @@ class Essay:
conn = sqlite3.connect("static/wordfreqapp.db")
# 创建游标
cursor = conn.cursor()
- cursor.execute("select word from words where difficulty = " + str(self._difficulty))
+ cursor.execute(
+ "select word from words where difficulty = " + str(self._difficulty))
results = cursor.fetchall()
conn.commit()
cursor.close()
@@ -65,16 +69,16 @@ class Essay:
except Exception as e:
print(e)
- #获取单词的近义词
- def get_word_synsets(self,word):
+ # 获取单词的近义词
+ def get_word_synsets(self, word):
synsets_set = wn.synsets(word)
synset_list = []
for synset in synsets_set:
synset_list.append(synset.name().split(".")[0])
return synset_list
- #生成完形填空
- def create_clozeTest(self,essay):
+ # 生成完形填空
+ def create_clozeTest(self, essay):
essay.article_id = self._article_id
word = [] # 存放文章中含有的与文章难度相同的单词
answers = [] # 存放正确答案
@@ -82,26 +86,27 @@ class Essay:
database_words = essay.find_same_difficulty_words()
essay_words = essay.split_essay_to_word()
+ # 寻找文章中与文章难度相同的单词存入word[]中
for essay_word in essay_words:
if database_words.__contains__(essay_word) and essay_word not in word:
word.append(essay_word)
-
+ # 给出因文章内容太少的问题导致题目少于10个的情况
if len(word) <= 10:
answers = word
- else:
+ else: # 将找出来的单词作为正确答案存入answers[]中
for i in range(0, 10):
w = word[random.randint(0, len(word) - 1)]
if not answers.__contains__(w):
answers.append(w)
self._answers = answers
-
+ # 用题号来替换文章中的单词
No = 1
for answer in answers:
questions.append(list(answer.split(",")))
- self._essay = self._essay.replace(answer,'('+str(No)+')____', 1)
+ self._essay = self._essay.replace(answer, '('+str(No)+')____', 1)
No += 1
-
+ # 生成每道题目的四个选项
for question in questions:
synset = list(set(essay.get_word_synsets(question[0])))
if len(synset) == 0 or len(synset) == 1:
diff --git a/app/main.py b/app/main.py
index 7bbcdff..bc3ce1d 100644
--- a/app/main.py
+++ b/app/main.py
@@ -109,6 +109,10 @@ essay = Essay()
@app.route('/gocloze', methods=['GET', 'POST'])
def go_ClozeTest():
+ '''
+ 根据GET或POST方法来分别返回答题前后的完型填空界面
+ :return: 完型填空界面
+ '''
if request.method == 'GET':
essay._article_id += 1
essay.create_clozeTest(essay)
--
2.17.1