diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index bb8279d5..9a2019bb 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -641,5 +641,38 @@ def StripSuffix(string, suf_words): #除去字符串前后的空格及suf_words string = re.sub(sw+r"[\S]*$","",string) return(string) # 返回处理以后的字符串 +def MatchCondition(problem,condition_dict): #判断problem这一字典是否符合condition_dict中的所有筛选条件 + match = True #初始设定符合条件 + for fieldraw in [c for c in condition_dict if not "_not" in c and not condition_dict[c] == [""]]: #选出正向的条件([""]表示该条件不起作用) + cond_list = condition_dict[fieldraw] + if type(cond_list) == str: + cond_list = [cond_list] + field = re.sub(r"\d","",fieldraw) + if type(problem[field]) == list: #将题库字典中的相应字段转化成字符串string + string = "\n".join((problem[field])) + else: + string = str(problem[field]) + current_match = False + for cond in cond_list: #有一个条件被满足, 就认为当前字段满足条件了 + if len(re.findall(cond,string)) > 0: + current_match = True + if current_match == False: + match = False # 如果某个正向条件未满足, 那么match就赋值为False; 如果每一个正向条件都被满足, 那么match仍为True + for fieldraw in [c for c in condition_dict if "_not" in c and not condition_dict[c] == [""]]: #选出反向的条件([""]表示该条件不起作用) + cond_list = condition_dict[fieldraw] + fieldraw = fieldraw.replace("_not","") + field = re.sub(r"\d","",fieldraw) + if type(problem[field]) == list: #将题库字典中的相应字段转化成字符串string + string = "\n".join((problem[field])) + else: + string = str(problem[field]) + current_match = True + for cond in cond_list: #有一个条件被满足, 就认为当前字段不被满足了 + if len(re.findall(cond,string)) > 0: + current_match = False + if current_match == False: + match = False + return match #返回是否符合条件 + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file diff --git a/工具v2/关键字筛选题号.py b/工具v2/关键字筛选题号.py new file mode 100644 index 00000000..9246f9b3 --- /dev/null +++ b/工具v2/关键字筛选题号.py @@ -0,0 +1,33 @@ +keywords_dict = { + "id":[""], #题号 + "content":[""], #题面内容 + "objs":[""], #目标代码 + "tags":[""], #标签, 如["第二单元"]等 + "genre":[""], #题目类型, 填空题, 选择题, 解答题 + "ans":[""], #答案 + "solution":[""], #解答与提示 + "duration":[""], #解题时间(目前未设置) + "usages":[""], #使用记录, 数据库中格式为 <日期>\t<届别><班别>\t正确率[\t正确率]... 例如"20230301\t2023届01班\t0.985\t0.211 + "origin":["高二下学期期末","高一下学期"], #题目来源 + "edit":[""], #导入者及编辑者 + "same":[""], #相同题目题号 + "related":[""], #关联题目题号 + "remark":[""], #备注, 注记 + "space":[""], #解答题下的空间(em)表示一个m的宽度 + "unrelated":[""], #无关题目题号 + # "content2":["双曲线"], #在字段名中加入数字表示这个字段的另一个必要条件 + "content_not":["抛"], #加_not表示不能出现该样式的词 +} +#同一字段名中的条件为"或"的关系, 不同字段名(可加数字表示同一字段)中的条件为"且"的关系 +outputfilepath = "临时文件/题号筛选.txt" + +from database_tools import * + +prodictpath = "../题库0.3/problems.json" +pro_dict = load_dict(prodictpath) + +matchlist = [id for id in pro_dict if MatchCondition(pro_dict[id],keywords_dict)] +matchstring = generate_exp(matchlist) + +SaveTextFile(matchstring,outputfilepath) +os.system("code -g %s:1"%outputfilepath) \ No newline at end of file