123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- #coding:UTF-8
- import re
- import pandas as pd
- def re_serviceTime(text):
- text_list = []
- text_list.append(text)
- # 初始化
- output_list = []
- text_index_list = []
- before = '(?P<before>' \
- '工期/交货期/服务期|工期,\(日历天\)|工期\(交货期\)|合格工期\(天\)|服务期限\(年\)|工期\(天\)' \
- '|工期要求|项目周期|工期\(交货期\)|计划工期\(服务期限\)|服务时限|履行期限|服务周期|供货期' \
- '|合格工期|计划工期\(服务期\)|服务期\(日历天\)|服务,期|交货\(完工\)时间|交付\(服务、完工\)时间' \
- '|交货时间|工期\(日历天\)' \
- '|服务期限为|计划工期|工期要求|服务期限|服务期' \
- '|投标工期|设计工期|合格服务周期|总工期|服务时间|流转期限|维护期限|服务时限|交货期|服务要求' \
- '|完成时间|服务期限|中标工期|项目周期|期限要求|周期|工期|供货期|合同履行日期|计划周期|工期' \
- ')'
- before2 = '(?P<before2>' \
- '自合同签订之日起至|合同签订之日起|约|自合同签订之日起|开工后|不超过|签订合同后|系统开发' \
- '|合同签订之日起至|自合同签订之日|合同签定后|自签订合同之日起|自合同签订起' \
- '|自合同签订生效之日起|自合同签订后不超过|中选后|均为|合同签订日至|本项目合同期|' \
- ')'
- charac = '(?P<charac>' \
- '[::,,]*' \
- ')'
- center = '(?P<center>' \
- '[自]?\d+年\d+月\d+日至\d+年\d+月\d+日|\d+年\d+月\d+日|[\d一二三四五六七两叁贰壹肆伍]+' \
- ')'
- center1 = '(?P<center1>' \
- '[自]?\d+年\d+月\d+日至\d+年\d+月\d+日|\d+年\d+月\d+日|[\d一二三四五六七两叁贰壹肆伍]+' \
- ')'
- after = '(?P<after>' \
- '天|个月|年|个日历天|日历天|日|\(日历天\)|\(天\)|周内|,日历天|' \
- ')'
- new1 = '(' \
- '\d{4}年?(\d{1,2}月?)?(\d{1,2}日?)?-(\d{4}年?)?(\d{1,2}月?)?(\d{1,2}日?)?(-\d{1,2}日?)?' \
- ')'
- reg = re.compile(before + charac + before2 + center + after)
- reg1 = re.compile(before + charac + '(.*?止)')
- reg2 = re.compile(before + charac + before2 + new1)
- reg_not = re.compile(u'(工期延误|工期节点|工期管理|交付使用'
- u'|工期、)'
- u'|工期情况|划工期内|服务期内')
- reg_not1 = re.compile(u'(履行日期:见|服务期限应按|签订合同前,'
- u'|务期限:1、|同签订日期:|证金在合同签|服务期限截止'
- u')')
- reg_not2 = re.compile(u'截止|1\.|1、')
- for index in range(len(text_list)):
- # 初始化
- output_str = ""
- input_str = text_list[index]
- # 替换混淆词
- # input_str = re.sub(reg_not, "####", input_str)
- # input_str = re.sub(reg_not1, "######", input_str)
- # input_str = re.sub(reg_not2, "##", input_str)
- for _reg_not in [reg_not,reg_not1,reg_not2]:
- match = re.findall(_reg_not, input_str)
- if match:
- for word in match:
- instead = "#" * len(word)
- input_str = re.sub(word, instead, input_str)
- output_str, text_index = re_findAllResult(reg2, input_str)
- if len(text_index) == 0:
- output_str, text_index = re_findAllResult(reg, input_str)
- if len(text_index) == 0:
- output_str, text_index = re_findAllResult(reg1, input_str)
- # 添加
- output_list.append(output_str)
- text_index_list.append(text_index)
- index2word = []
- for index in range(len(text_index_list)):
- word = ""
- for i in range(len(text_index_list[index])):
- word = word + text[text_index_list[index][i][0]:text_index_list[index][i][1]]
- if word != len(text_index_list[index])-1:
- word = word + " "
- index2word.append(word)
- return index2word[0], text_index_list[0]
- def re_findAllResult(reg, input, unit="", index=0):
- '''
- :param reg: 正则表达式
- :param input: 待匹配句子
- :param unit: 需要加的单位
- :param index: 字符串拼接的开始位置
- :return: 正则后的字符串
- '''
- match = re.findall(reg, input)
- output = ""
- # print(match)
- if match:
- ss = ""
- for i in range(len(match)):
- s = ""
- for j in range(index, len(match[i])):
- s = s + match[i][j]
- if unit != "" and j == len(match[i])-1:
- s = s + unit
- ss = ss + s
- if i < len(match)-1:
- ss = ss + " "
- output = ss
- # 全文下标
- text_index = []
- match1 = re.finditer(reg, input)
- for i in match1:
- d = i.groupdict()
- if d.get("before") is not None:
- front_len = len(d.get("before")) + len(d.get("charac"))
- else:
- front_len = 0
- text_index.append([i.start()+front_len, i.end()])
- return output, text_index
- def calculateLen(ss, i):
- front_len = 0
- back_len = 0
- for index in range(i):
- front_len += len(ss[index])
- for index in range(i+1, len(ss)):
- back_len += len(ss[index])
- return front_len, back_len
- def extract_servicetime(text):
- list_servicetime = []
- word, text_index_list = re_serviceTime(text)
- # print(word, text_index_list)
- for i in range(len(text_index_list)):
- word_list = word.split(" ")
- d = {"body": word_list[i], "begin_index": text_index_list[i][0], "end_index": text_index_list[i][1]}
- if len(word_list[i]) <= 35:
- list_servicetime.append(d)
- # print(list_servicetime)
- return list_servicetime
- if __name__ == '__main__':
- s = """
- 4、其他:无
- 合同履行期限:双方签订合同后30天内
- 本项目( 不接受 )联合体投标。
- 二、申请人的资格要求:
- 1.满足《中华人民共和国政府采购法》第二十二条规定;
- 2.落实政府采购政策需满足的资格要求:
- 2.1具备《政府采购法》第二十二条规定的条件,且提供以下证明文件:
- (1)在中华人民共和国境内注册的法人或其他组织或自然人, 投标(响应)时提交有效的营业执照(或事业法人登记证或身份证等相关证明)副本复印件。
- (2)有依法缴纳税收和社会保障资金的良好记录:提供投标截止日前6个月内任意1个月依法缴纳税收和社会保障资金的相关材料。如依法免税或不需要缴纳社会保障资金的,提供相应证明材料。
- (3)供应商必须具有良好的商业信誉和健全的财务会计制度(提供2020年度财务状况报告或基本开户行出具的资信证明)。
- (4)履行合同所必需的设备和专业技术能力的证明材料或书面声明。
- (5)参加政府采购活动前 3 年内在经营活动中没有重大违法记录的书面声明。
- (6)信用记录:供应商未被列入“信用中国”网站(www.creditchina.gov.cn)“记录失信被执行人或重大税收违法案件当事人名单”记录名单; 不处于中国政府采购网(www.ccgp.gov.cn)“政府采购严重违法失信行为信息记录”中的禁止参加政府采购活动期间。
- """
- # s = "自合同签订之日起至2022-6-30 自合同签订之日起至2022-07-30"
- print(extract_servicetime(s))
- # df = pd.read_csv("C:\\Users\\admin\\Desktop\\serviceTime_text.csv")
- # result_list = []
- # for index, row in df.iterrows():
- # result = extract_servicetime(row["text"])
- # result_list.append(str(result))
- #
- # df["new_word"] = pd.DataFrame(result_list)
- # df.to_csv("C:\\Users\\admin\\Desktop\\serviceTime_text_new.csv")
|