database_tools中增加generate_origin函数, 生成来源字符串

This commit is contained in:
weiye.wang 2024-04-07 19:35:42 +08:00
parent b97b62d6a3
commit 5e9b85b07d
1 changed files with 9 additions and 4 deletions

View File

@ -917,6 +917,14 @@ def StripSuffix(string, suf_words): #除去字符串前后的空格及suf_words
return(string) # 返回处理以后的字符串 return(string) # 返回处理以后的字符串
def generate_origin(origin_dict):
data = origin_dict["来源"]
if "题号" in origin_dict:
data = f"{data}试题{origin_dict['题号']}"
if "前序" in origin_dict:
data = f"{data}-改编自{origin_dict['前序']}"
return data
def MatchCondition2024(problem,condition_list): #判断problem这一字典是否符合condition_list中的所有筛选条件 def MatchCondition2024(problem,condition_list): #判断problem这一字典是否符合condition_list中的所有筛选条件
match = True #初始设定符合条件 match = True #初始设定符合条件
for field, flag_not, matchexp in condition_list: for field, flag_not, matchexp in condition_list:
@ -924,10 +932,7 @@ def MatchCondition2024(problem,condition_list): #判断problem这一字典是否
if type(problem[field]) == list: if type(problem[field]) == list:
data = "\n".join(problem[field]) data = "\n".join(problem[field])
elif field == "origin": elif field == "origin":
if "题号" in problem[field]: data = generate_origin(problem[field])
data = problem[field]["来源"]+"试题"+str(problem[field]["题号"]).zfill(2)
else:
data = problem[field]["来源"]
else: else:
data = str(problem[field]) #至此将每个字段中的内容都转为string data = str(problem[field]) #至此将每个字段中的内容都转为string
if flag_not == False: #表示肯定的筛选 if flag_not == False: #表示肯定的筛选