forked from mrlan/EnglishPal
1、删除了difficulty_level_from_frequency
2、修改了get_difficulty_level_for_user,按新的方式修改了单词的评级方式:CET4 等于 level 4, OXFORD3000 等于 level 5, CET6 等于 level 6, GRADUATE 等于 level 6, OXFORD5000 等于 level 7, BBC 等于 level 8,找不到等于 level 3Bug476-ZhangWeiHao-YuHuangtao
parent
fc515a7b08
commit
c4378e73cd
|
@ -62,8 +62,11 @@ def get_today_article(user_word_list, articleID):
|
||||||
d = reading
|
d = reading
|
||||||
break
|
break
|
||||||
|
|
||||||
s = '<div class="alert alert-success" role="alert">According to your word list, your level is <span class="badge bg-success">%4.2f</span> and we have chosen an article with a difficulty level of <span class="badge bg-success">%4.2f</span> for you.</div>' % (
|
s = '<div class="alert alert-success" role="alert">' \
|
||||||
user_level, text_level)
|
'According to your word list, your level is <span class="badge bg-success">%4.2f</span> ' \
|
||||||
|
'and we have chosen an article with a difficulty level of ' \
|
||||||
|
'<span class="badge bg-success">%4.2f</span> for you.' \
|
||||||
|
'</div>' % (user_level, text_level)
|
||||||
s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])
|
s += '<p class="text-muted">Article added on: %s</p>' % (d['date'])
|
||||||
s += '<div class="p-3 mb-2 bg-light text-dark">'
|
s += '<div class="p-3 mb-2 bg-light text-dark">'
|
||||||
article_title = get_article_title(d['text'])
|
article_title = get_article_title(d['text'])
|
||||||
|
|
|
@ -17,26 +17,6 @@ def load_record(pickle_fname):
|
||||||
f.close()
|
f.close()
|
||||||
return d
|
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):
|
def convert_test_type_to_difficulty_level(d):
|
||||||
"""
|
"""
|
||||||
对原本的单词库中的单词进行难度评级
|
对原本的单词库中的单词进行难度评级
|
||||||
|
@ -49,14 +29,14 @@ def convert_test_type_to_difficulty_level(d):
|
||||||
for k in L:
|
for k in L:
|
||||||
if 'CET4' in d[k]:
|
if 'CET4' in d[k]:
|
||||||
result[k] = 4 # CET4 word has level 4
|
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]:
|
elif 'CET6' in d[k] or 'GRADUATE' in d[k]:
|
||||||
result[k] = 6
|
result[k] = 6
|
||||||
elif 'IELTS' in d[k]: # 雅思
|
elif 'OXFORD5000' in d[k]:
|
||||||
result[k] = 7
|
result[k] = 7
|
||||||
elif 'BBC' in d[k]:
|
elif 'BBC' in d[k]:
|
||||||
result[k] = 8
|
result[k] = 8
|
||||||
elif 'EnWords' in d[k]: # 除基础词汇外的绝大多数词,包括一些犄角旮旯的专业词汇,近九万个,定级不太好处理,绝大多数我是真不认识
|
|
||||||
result[k] = 3
|
|
||||||
|
|
||||||
return result # {'apple': 4, ...}
|
return result # {'apple': 4, ...}
|
||||||
|
|
||||||
|
@ -80,7 +60,7 @@ def simplify_the_words_dict(d):
|
||||||
|
|
||||||
def get_difficulty_level_for_user(d1, d2):
|
def get_difficulty_level_for_user(d1, d2):
|
||||||
"""
|
"""
|
||||||
d2 来自于词库的27000个已标记单词
|
d2 来自于词库的35511个已标记单词
|
||||||
d1 用户不会的词
|
d1 用户不会的词
|
||||||
在d2的后面添加单词,没有新建一个新的字典
|
在d2的后面添加单词,没有新建一个新的字典
|
||||||
"""
|
"""
|
||||||
|
@ -89,12 +69,13 @@ def get_difficulty_level_for_user(d1, d2):
|
||||||
stem = snowballstemmer.stemmer('english')
|
stem = snowballstemmer.stemmer('english')
|
||||||
|
|
||||||
for k in d1: # 用户的词
|
for k in d1: # 用户的词
|
||||||
for l in d2_simplified: # l是词库的某个单词的词根
|
if k in d2: # 如果用户的词以原型的形式存在于词库d2中
|
||||||
if stem.stemWord(k) == l: # 两者相等则视为同一难度的词
|
continue # 无需评级,跳过
|
||||||
d2[k] = d2_simplified[l] # 给d2定级
|
elif stem.stemWord(k) in d2_simplified: # 如果用户的词的词根存在于词库d2的词根库中
|
||||||
break
|
d2[k] = d2_simplified[k] # 按照词根进行评级
|
||||||
else: # 不相等则表明词库中没这词,按照单词的频率定级
|
break
|
||||||
d2[k] = difficulty_level_from_frequency(k, d1)
|
else:
|
||||||
|
d2[k] = 3 # 如果k的词根都不在,那么就当认为是3级
|
||||||
return d2
|
return d2
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue