工具v2中增加分类题号字典生成.py功能
This commit is contained in:
parent
c6909e13c7
commit
1793138b57
|
|
@ -626,7 +626,20 @@ def SortUsages(prodict):
|
|||
return 0 #返回0
|
||||
|
||||
|
||||
def SortUsagesbyAverage(theusages): #根据使用记录每一条的平均值进行排序, 越高的在越前面
|
||||
glossdifflist = []
|
||||
for i in range(len(theusages)):
|
||||
glossdifflist = glossdifflist + [(i,parseUsage(theusages[i])["glossdiff"])]
|
||||
sortedglossdifflist = sorted(glossdifflist, key = lambda x:x[1], reverse = True)
|
||||
newusages = [theusages[i[0]] for i in sortedglossdifflist]
|
||||
return(newusages) # 返回排序后的list
|
||||
|
||||
|
||||
def StripSuffix(string, suf_words): #除去字符串前后的空格及suf_words中每一个符合regex的字符串及其之后的部分
|
||||
string = string.strip()
|
||||
for sw in suf_words:
|
||||
string = re.sub(sw+r"[\S]*$","",string)
|
||||
return(string) # 返回处理以后的字符串
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("数据库工具, import用.")
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
original_id_list = "1:50000"
|
||||
suffix_words = ["试题",r"第[\d]*题"]
|
||||
outputfilepath = "临时文件/分类题号列表.json"
|
||||
|
||||
from database_tools import *
|
||||
|
||||
pro_dict = load_dict("../题库0.3/problems.json")
|
||||
idlist = generate_number_set(original_id_list,pro_dict)
|
||||
|
||||
#记录每一个出处对应的题号列表
|
||||
setlist = {}
|
||||
for id in idlist:
|
||||
p = pro_dict[id]["origin"]
|
||||
origin = StripSuffix(p,suffix_words)
|
||||
if not origin in setlist:
|
||||
setlist[origin] = [id]
|
||||
else:
|
||||
setlist[origin].append(id)
|
||||
|
||||
outputdict = {}
|
||||
for origin in setlist:
|
||||
outputdict[origin] = generate_exp(setlist[origin])
|
||||
|
||||
save_dict(outputdict,outputfilepath)
|
||||
print("已将结果输出至 %s"%outputfilepath)
|
||||
Reference in New Issue