diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 3ba40654..d36ac772 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -823,6 +823,23 @@ def StripSuffix(string, suf_words): #除去字符串前后的空格及suf_words string = re.sub(sw+r"[\S]*$","",string) return(string) # 返回处理以后的字符串 + +def MatchCondition2014(problem,condition_list): #判断problem这一字典是否符合condition_list中的所有筛选条件 + match = True #初始设定符合条件 + for field, flag_not, matchexp in condition_list: + exps = [i.strip() for i in matchexp.split(",")] + if problem[field] == list: + data = "\n".join(problem[field]) + else: + data = str(problem[field]) #至此将每个字段中的内容都转为string + if flag_not == False: #表示肯定的筛选 + if all([re.findall(exp,data) == [] for exp in exps]): #如果有一个条件中的每个关键字都找不到, 就返回"不符合条件"(False) + return False + if flag_not == True: + if all([re.findall(exp,data) != [] for exp in exps]): #如果有一个条件中的每个关键字都能找到, 就返回"不符合条件"(False) + return False + return match #返回是否符合条件 + 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] == [""]]: #选出正向的条件([""]表示该条件不起作用)