根据review意见修改
parent
45f07bbf71
commit
40e537af9f
|
@ -6,24 +6,25 @@
|
|||
Hui, 2024-09-23
|
||||
Last upated: 2024-09-25, 2024-09-30
|
||||
'''
|
||||
import os
|
||||
import pickle
|
||||
import random
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timedelta
|
||||
import heapq
|
||||
import snowballstemmer
|
||||
from flask import session
|
||||
import enchant
|
||||
|
||||
|
||||
|
||||
# word_lst = 词汇表
|
||||
|
||||
def load_record(pickle_fname):
|
||||
try:
|
||||
with open(pickle_fname, 'rb') as f:
|
||||
d = pickle.load(f)
|
||||
return d
|
||||
except FileNotFoundError:
|
||||
print("未发现文件")
|
||||
except pickle.UnpicklingError:
|
||||
print("无法打开文件")
|
||||
except Exception as e:
|
||||
print("文件处理异常")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
@ -43,10 +44,7 @@ def is_valid_datetime_string(date_string, format='%Y%m%d%H%M'):
|
|||
|
||||
def remove_non_words(input_string):
|
||||
cleaned_string = re.sub(r'[^a-zA-Z\s]', '', input_string)
|
||||
words = cleaned_string.split()
|
||||
result = ' '.join(words)
|
||||
return result
|
||||
|
||||
return cleaned_string.strip()
|
||||
|
||||
|
||||
class VocabularyLevelEstimator:
|
||||
|
@ -106,7 +104,11 @@ class UserVocabularyLevel(VocabularyLevelEstimator):
|
|||
return # 如果词库为空,直接返回
|
||||
|
||||
stemmer = snowballstemmer.stemmer('english')
|
||||
date_str = "20240805"
|
||||
#硬编码情况
|
||||
# date_str = "20240805"
|
||||
# 实际时间
|
||||
now = datetime.now()
|
||||
date_str = now.strftime('%Y%m%d')
|
||||
dt = datetime.strptime(date_str, "%Y%m%d")
|
||||
range_datetime = dt.strftime("%Y%m%d%H%M") # 设定筛选时间范围
|
||||
|
||||
|
@ -214,8 +216,10 @@ class ArticleVocabularyLevel(VocabularyLevelEstimator):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
user = UserVocabularyLevel({})
|
||||
print(user.level)
|
||||
now = datetime.now()
|
||||
print(now.strftime("%Y%m%d"))
|
||||
# user = UserVocabularyLevel({})
|
||||
# print(user.level)
|
||||
# _test = load_record('static/words_and_tests.p')
|
||||
# print(_test)
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue