From 51024182e737b7ffc965b6655ad59787b525b0a5 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Fri, 23 Feb 2024 22:28:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EMatchCondition2014,=20?= =?UTF-8?q?=E5=B0=86=E6=9F=A5=E6=89=BE=E6=9D=A1=E4=BB=B6=E5=8F=98=E4=B8=BA?= =?UTF-8?q?condition=5Flist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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] == [""]]: #选出正向的条件([""]表示该条件不起作用)