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