From 541f78c7eabcaade6f6393ab584dd30f1f1b0833 Mon Sep 17 00:00:00 2001 From: PlutoCtx Date: Mon, 15 May 2023 09:58:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E5=AE=A1=E5=90=8E=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=88words=5Fand=5Ftests.p=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=8F=90=E4=BA=A4=EF=BC=8C=E4=B8=BA=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E7=89=88=E6=9C=AC=E7=9A=84=E6=8E=A7=E5=88=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/difficulty.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/app/difficulty.py b/app/difficulty.py index 2570f77..3e6007b 100644 --- a/app/difficulty.py +++ b/app/difficulty.py @@ -37,26 +37,28 @@ def difficulty_level_from_frequency(word, d): return level -def get_difficulty_level_for_words_and_tests(d_in): +def get_difficulty_level_for_words_and_tests(d): """ 对原本的单词库中的单词进行难度评级 - :param d_in: 存储了单词库pickle文件中的单词的字典 + :param d: 存储了单词库pickle文件中的单词的字典 :return: """ - d = {} - L = list(d_in.keys()) # in dic, we have test types (e.g., CET4,CET6,BBC) for each word + result = {} + L = list(d.keys()) # in dic, we have test types (e.g., CET4,CET6,BBC) for each word for k in L: - if 'CET4' in d_in[k]: - d[k] = 4 # CET4 word has level 4 - elif 'CET6' in d_in[k]: - d[k] = 6 - elif 'IELTS' in d_in[k] or 'GRADUATE' in d_in[k]: # 雅思或研究生英语 - d[k] = 8 - elif 'EnWords' in d_in[k]: # 除基础词汇外的绝大多数词,包括一些犄角旮旯的专业词汇,近九万个,绝大多数我是真不认识 - d[k] = 7 + if 'CET4' in d[k]: + result[k] = 4 # CET4 word has level 4 + elif 'CET6' in d[k] or 'GRADUATE' in d[k]: + result[k] = 6 + elif 'IELTS' in d[k]: # 雅思或研究生英语 + result[k] = 7 + elif 'BBC' in d[k]: + result[k] = 8 + # elif 'EnWords' in d[k]: # 除基础词汇外的绝大多数词,包括一些犄角旮旯的专业词汇,近九万个,定级不太好处理,绝大多数我是真不认识 + # result[k] = 7 - return d # {'apple': 4, ...} + return result # {'apple': 4, ...} def simplify_the_words_dict(d): """ @@ -65,13 +67,13 @@ def simplify_the_words_dict(d): stem = snowballstemmer.stemmer('english') result = {} - for j in d: # j 在字典中 - temp = stem.stemWord(j) # 提取j得词根 - if not temp in result: # 如果这个词根不在结果字典中,则以词根为键、以dic中的等级作为值添加 - result[temp] = d[j] + for k in d: # j 在字典中 + temp = stem.stemWord(k) # 提取j得词根 + if temp not in result: # 如果这个词根不在结果字典中,则以词根为键、以dic中的等级作为值添加 + result[temp] = d[k] else: # 如果这个词在结果词典中,则比较一下单词的难度等级是否最小 - if result[temp] > d[j]: - result[temp] = d[j] + if result[temp] > d[k]: + result[temp] = d[k] return result