From c4378e73cdfffebd98e5e43e4fa3ca6321797877 Mon Sep 17 00:00:00 2001 From: PlutoCtx Date: Thu, 18 May 2023 16:59:30 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=88=A0=E9=99=A4=E4=BA=86difficulty?= =?UTF-8?q?=5Flevel=5Ffrom=5Ffrequency=202=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86get=5Fdifficulty=5Flevel=5Ffor=5Fuser=EF=BC=8C?= =?UTF-8?q?=E6=8C=89=E6=96=B0=E7=9A=84=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E5=8D=95=E8=AF=8D=E7=9A=84=E8=AF=84=E7=BA=A7=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=9ACET4=20=E7=AD=89=E4=BA=8E=20level=204?= =?UTF-8?q?=EF=BC=8C=20OXFORD3000=20=E7=AD=89=E4=BA=8E=20level=205?= =?UTF-8?q?=EF=BC=8C=20CET6=20=E7=AD=89=E4=BA=8E=20level=206=EF=BC=8C=20GR?= =?UTF-8?q?ADUATE=20=E7=AD=89=E4=BA=8E=20level=206,=20OXFORD5000=20?= =?UTF-8?q?=E7=AD=89=E4=BA=8E=20level=207=EF=BC=8C=20BBC=20=E7=AD=89?= =?UTF-8?q?=E4=BA=8E=20level=208=EF=BC=8C=E6=89=BE=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E7=AD=89=E4=BA=8E=20level=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Article.py | 7 +++++-- app/difficulty.py | 41 +++++++++++------------------------------ 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/app/Article.py b/app/Article.py index b493f47..51b9b74 100644 --- a/app/Article.py +++ b/app/Article.py @@ -62,8 +62,11 @@ def get_today_article(user_word_list, articleID): d = reading break - s = '' % ( - user_level, text_level) + s = '' % (user_level, text_level) s += '

Article added on: %s

' % (d['date']) s += '
' article_title = get_article_title(d['text']) diff --git a/app/difficulty.py b/app/difficulty.py index 0d6d8b7..9ae52eb 100644 --- a/app/difficulty.py +++ b/app/difficulty.py @@ -17,26 +17,6 @@ def load_record(pickle_fname): f.close() return d - -def difficulty_level_from_frequency(word, d): - """ - 根据单词的频率进行难度的评级 - :param word: - :param d: - :return: - """ - level = 1 - if not word in d: - return level - - if 'what' in d: - ratio = (d['what']+1)/(d[word]+1) # what is a frequent word - level = math.log(max(ratio, 1), 2) - - level = min(level, 8) - return level - - def convert_test_type_to_difficulty_level(d): """ 对原本的单词库中的单词进行难度评级 @@ -49,14 +29,14 @@ def convert_test_type_to_difficulty_level(d): for k in L: if 'CET4' in d[k]: result[k] = 4 # CET4 word has level 4 + elif 'OXFORD3000' in d[k]: + result[k] = 5 elif 'CET6' in d[k] or 'GRADUATE' in d[k]: result[k] = 6 - elif 'IELTS' in d[k]: # 雅思 + elif 'OXFORD5000' in d[k]: result[k] = 7 elif 'BBC' in d[k]: result[k] = 8 - elif 'EnWords' in d[k]: # 除基础词汇外的绝大多数词,包括一些犄角旮旯的专业词汇,近九万个,定级不太好处理,绝大多数我是真不认识 - result[k] = 3 return result # {'apple': 4, ...} @@ -80,7 +60,7 @@ def simplify_the_words_dict(d): def get_difficulty_level_for_user(d1, d2): """ - d2 来自于词库的27000个已标记单词 + d2 来自于词库的35511个已标记单词 d1 用户不会的词 在d2的后面添加单词,没有新建一个新的字典 """ @@ -89,12 +69,13 @@ def get_difficulty_level_for_user(d1, d2): stem = snowballstemmer.stemmer('english') for k in d1: # 用户的词 - for l in d2_simplified: # l是词库的某个单词的词根 - if stem.stemWord(k) == l: # 两者相等则视为同一难度的词 - d2[k] = d2_simplified[l] # 给d2定级 - break - else: # 不相等则表明词库中没这词,按照单词的频率定级 - d2[k] = difficulty_level_from_frequency(k, d1) + if k in d2: # 如果用户的词以原型的形式存在于词库d2中 + continue # 无需评级,跳过 + elif stem.stemWord(k) in d2_simplified: # 如果用户的词的词根存在于词库d2的词根库中 + d2[k] = d2_simplified[k] # 按照词根进行评级 + break + else: + d2[k] = 3 # 如果k的词根都不在,那么就当认为是3级 return d2