新增MatchCondition2014, 将查找条件变为condition_list

This commit is contained in:
weiye.wang 2024-02-23 22:28:35 +08:00
parent 35f3143a88
commit 51024182e7
1 changed files with 17 additions and 0 deletions

View File

@ -823,6 +823,23 @@ def StripSuffix(string, suf_words): #除去字符串前后的空格及suf_words
string = re.sub(sw+r"[\S]*$","",string) string = re.sub(sw+r"[\S]*$","",string)
return(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中的所有筛选条件 def MatchCondition(problem,condition_dict): #判断problem这一字典是否符合condition_dict中的所有筛选条件
match = True #初始设定符合条件 match = True #初始设定符合条件
for fieldraw in [c for c in condition_dict if not "_not" in c and not condition_dict[c] == [""]]: #选出正向的条件([""]表示该条件不起作用) for fieldraw in [c for c in condition_dict if not "_not" in c and not condition_dict[c] == [""]]: #选出正向的条件([""]表示该条件不起作用)