From a83f91a88d916ff979dede00a2c0e4655c9b5abb Mon Sep 17 00:00:00 2001 From: PlutoCtx Date: Thu, 18 May 2023 20:36:31 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E8=AF=AF=E5=88=A0?= =?UTF-8?q?=E7=9A=84IELTS=E5=8D=95=E8=AF=8D=E6=A0=87=E7=AD=BE=202=E3=80=81?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E8=AF=84=E7=BA=A7=E6=B5=81=E7=A8=8B=EF=BC=88?= =?UTF-8?q?=E5=BF=AB=E5=BE=88=E5=A4=9A=EF=BC=8C=E5=87=A0=E4=B9=8E=E4=B8=8E?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E7=9B=B8=E5=90=8C=EF=BC=89=203=E3=80=81?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=86=E5=8E=9F=E5=85=88=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E8=AF=8D=E6=A0=B9=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/difficulty.py | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/app/difficulty.py b/app/difficulty.py index 9ae52eb..5df3575 100644 --- a/app/difficulty.py +++ b/app/difficulty.py @@ -24,7 +24,7 @@ def convert_test_type_to_difficulty_level(d): :return: """ result = {} - L = list(d.keys()) # in dic, we have test types (e.g., CET4,CET6,BBC) for each word + L = list(d.keys()) # in d, we have test types (e.g., CET4,CET6,BBC) for each word for k in L: if 'CET4' in d[k]: @@ -33,30 +33,13 @@ def convert_test_type_to_difficulty_level(d): result[k] = 5 elif 'CET6' in d[k] or 'GRADUATE' in d[k]: result[k] = 6 - elif 'OXFORD5000' in d[k]: + elif 'OXFORD5000' in d[k] or 'IELTS' in d[k]: result[k] = 7 elif 'BBC' in d[k]: result[k] = 8 return result # {'apple': 4, ...} -def simplify_the_words_dict(d): - """ - 用于把保存了词库中评级后的词新建一个以词根为键、以同词根的最低等级为值 - """ - stem = snowballstemmer.stemmer('english') - - result = {} - 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[k]: - result[temp] = d[k] - - return result - def get_difficulty_level_for_user(d1, d2): """ @@ -65,14 +48,13 @@ def get_difficulty_level_for_user(d1, d2): 在d2的后面添加单词,没有新建一个新的字典 """ d2 = convert_test_type_to_difficulty_level(d2) # 根据d2的标记评级{'apple': 4, 'abandon': 4, ...} - d2_simplified = simplify_the_words_dict(d2) # 提取d2的词根 {'appl': 4, 'abandon': 4, ...} stem = snowballstemmer.stemmer('english') for k in d1: # 用户的词 if k in d2: # 如果用户的词以原型的形式存在于词库d2中 continue # 无需评级,跳过 - elif stem.stemWord(k) in d2_simplified: # 如果用户的词的词根存在于词库d2的词根库中 - d2[k] = d2_simplified[k] # 按照词根进行评级 + elif stem.stemWord(k) in d2: # 如果用户的词的词根存在于词库d2的词根库中 + d2[k] = d2[stem.stemWord(k)] # 按照词根进行评级 break else: d2[k] = 3 # 如果k的词根都不在,那么就当认为是3级 @@ -108,7 +90,7 @@ def user_difficulty_level(d_user, d): for date in sorted(d_user2.keys(), reverse=True): # most recently added words are more important while determining user's level lst = d_user2[date] # a list of words lst2 = [] # a list of tuples, (word, difficulty level) - for word in lst: + for word in lst: if word in d: lst2.append((word, d[word]))