From fc515a7b08365c9df0cba4223ac0fb3175b771a1 Mon Sep 17 00:00:00 2001 From: PlutoCtx Date: Tue, 16 May 2023 19:02:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Article.py | 4 ++-- app/difficulty.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Article.py b/app/Article.py index 04a32ea..b493f47 100644 --- a/app/Article.py +++ b/app/Article.py @@ -7,7 +7,7 @@ import random, glob import hashlib from datetime import datetime from flask import Flask, request, redirect, render_template, url_for, session, abort, flash, get_flashed_messages -from difficulty import get_difficulty_level, text_difficulty_level, user_difficulty_level +from difficulty import get_difficulty_level_for_user, text_difficulty_level, user_difficulty_level path_prefix = '/var/www/wordfreq/wordfreq/' @@ -45,7 +45,7 @@ def get_today_article(user_word_list, articleID): # Choose article according to reader's level d1 = load_freq_history(path_prefix + 'static/frequency/frequency.p') d2 = load_freq_history(path_prefix + 'static/words_and_tests.p') - d3 = get_difficulty_level(d1, d2) + d3 = get_difficulty_level_for_user(d1, d2) d = {} d_user = load_freq_history(user_word_list) diff --git a/app/difficulty.py b/app/difficulty.py index 3e6007b..0d6d8b7 100644 --- a/app/difficulty.py +++ b/app/difficulty.py @@ -37,7 +37,7 @@ def difficulty_level_from_frequency(word, d): return level -def get_difficulty_level_for_words_and_tests(d): +def convert_test_type_to_difficulty_level(d): """ 对原本的单词库中的单词进行难度评级 :param d: 存储了单词库pickle文件中的单词的字典 @@ -51,12 +51,12 @@ def get_difficulty_level_for_words_and_tests(d): 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]: # 雅思或研究生英语 + elif 'IELTS' in d[k]: # 雅思 result[k] = 7 elif 'BBC' in d[k]: result[k] = 8 - # elif 'EnWords' in d[k]: # 除基础词汇外的绝大多数词,包括一些犄角旮旯的专业词汇,近九万个,定级不太好处理,绝大多数我是真不认识 - # result[k] = 7 + elif 'EnWords' in d[k]: # 除基础词汇外的绝大多数词,包括一些犄角旮旯的专业词汇,近九万个,定级不太好处理,绝大多数我是真不认识 + result[k] = 3 return result # {'apple': 4, ...} @@ -78,13 +78,13 @@ def simplify_the_words_dict(d): return result -def get_difficulty_level(d1, d2): +def get_difficulty_level_for_user(d1, d2): """ d2 来自于词库的27000个已标记单词 d1 用户不会的词 在d2的后面添加单词,没有新建一个新的字典 """ - d2 = get_difficulty_level_for_words_and_tests(d2) # 根据d2的标记评级{'apple': 4, 'abandon': 4, ...} + 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') @@ -181,7 +181,7 @@ if __name__ == '__main__': #print(d2) - d3 = get_difficulty_level(d1, d2) + d3 = get_difficulty_level_for_user(d1, d2) s = ''' South Lawn