re_servicetime.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #coding:UTF-8
  2. import re
  3. import pandas as pd
  4. def re_serviceTime(text):
  5. text_list = []
  6. text_list.append(text)
  7. # 初始化
  8. output_list = []
  9. text_index_list = []
  10. before = '(?P<before>' \
  11. '工期/交货期/服务期|工期,\(日历天\)|工期\(交货期\)|合格工期\(天\)|服务期限\(年\)|工期\(天\)' \
  12. '|工期要求|项目周期|工期\(交货期\)|计划工期\(服务期限\)|服务时限|履行期限|服务周期|供货期' \
  13. '|合格工期|计划工期\(服务期\)|服务期\(日历天\)|服务,期|交货\(完工\)时间|交付\(服务、完工\)时间' \
  14. '|交货时间|工期\(日历天\)' \
  15. '|服务期限为|计划工期|工期要求|服务期限|服务期' \
  16. '|投标工期|设计工期|合格服务周期|总工期|服务时间|流转期限|维护期限|服务时限|交货期|服务要求' \
  17. '|完成时间|服务期限|中标工期|项目周期|期限要求|周期|工期|供货期|合同履行日期|计划周期|工期' \
  18. ')'
  19. before2 = '(?P<before2>' \
  20. '自合同签订之日起至|合同签订之日起|约|自合同签订之日起|开工后|不超过|签订合同后|系统开发' \
  21. '|合同签订之日起至|自合同签订之日|合同签定后|自签订合同之日起|自合同签订起' \
  22. '|自合同签订生效之日起|自合同签订后不超过|中选后|均为|合同签订日至|本项目合同期|' \
  23. ')'
  24. charac = '(?P<charac>' \
  25. '[::,,]*' \
  26. ')'
  27. center = '(?P<center>' \
  28. '[自]?\d+年\d+月\d+日至\d+年\d+月\d+日|\d+年\d+月\d+日|[\d一二三四五六七两叁贰壹肆伍]+' \
  29. ')'
  30. center1 = '(?P<center1>' \
  31. '[自]?\d+年\d+月\d+日至\d+年\d+月\d+日|\d+年\d+月\d+日|[\d一二三四五六七两叁贰壹肆伍]+' \
  32. ')'
  33. after = '(?P<after>' \
  34. '天|个月|年|个日历天|日历天|日|\(日历天\)|\(天\)|周内|,日历天|' \
  35. ')'
  36. new1 = '(' \
  37. '\d{4}年?(\d{1,2}月?)?(\d{1,2}日?)?-(\d{4}年?)?(\d{1,2}月?)?(\d{1,2}日?)?(-\d{1,2}日?)?' \
  38. ')'
  39. reg = re.compile(before + charac + before2 + center + after)
  40. reg1 = re.compile(before + charac + '(.*?止)')
  41. reg2 = re.compile(before + charac + before2 + new1)
  42. reg_not = re.compile(u'(工期延误|工期节点|工期管理|交付使用'
  43. u'|工期、)'
  44. u'|工期情况|划工期内|服务期内')
  45. reg_not1 = re.compile(u'(履行日期:见|服务期限应按|签订合同前,'
  46. u'|务期限:1、|同签订日期:|证金在合同签|服务期限截止'
  47. u')')
  48. reg_not2 = re.compile(u'截止|1\.|1、')
  49. for index in range(len(text_list)):
  50. # 初始化
  51. output_str = ""
  52. input_str = text_list[index]
  53. # 替换混淆词
  54. # input_str = re.sub(reg_not, "####", input_str)
  55. # input_str = re.sub(reg_not1, "######", input_str)
  56. # input_str = re.sub(reg_not2, "##", input_str)
  57. for _reg_not in [reg_not,reg_not1,reg_not2]:
  58. match = re.findall(_reg_not, input_str)
  59. if match:
  60. for word in match:
  61. instead = "#" * len(word)
  62. input_str = re.sub(word, instead, input_str)
  63. output_str, text_index = re_findAllResult(reg2, input_str)
  64. if len(text_index) == 0:
  65. output_str, text_index = re_findAllResult(reg, input_str)
  66. if len(text_index) == 0:
  67. output_str, text_index = re_findAllResult(reg1, input_str)
  68. # 添加
  69. output_list.append(output_str)
  70. text_index_list.append(text_index)
  71. index2word = []
  72. for index in range(len(text_index_list)):
  73. word = ""
  74. for i in range(len(text_index_list[index])):
  75. word = word + text[text_index_list[index][i][0]:text_index_list[index][i][1]]
  76. if word != len(text_index_list[index])-1:
  77. word = word + " "
  78. index2word.append(word)
  79. return index2word[0], text_index_list[0]
  80. def re_findAllResult(reg, input, unit="", index=0):
  81. '''
  82. :param reg: 正则表达式
  83. :param input: 待匹配句子
  84. :param unit: 需要加的单位
  85. :param index: 字符串拼接的开始位置
  86. :return: 正则后的字符串
  87. '''
  88. match = re.findall(reg, input)
  89. output = ""
  90. # print(match)
  91. if match:
  92. ss = ""
  93. for i in range(len(match)):
  94. s = ""
  95. for j in range(index, len(match[i])):
  96. s = s + match[i][j]
  97. if unit != "" and j == len(match[i])-1:
  98. s = s + unit
  99. ss = ss + s
  100. if i < len(match)-1:
  101. ss = ss + " "
  102. output = ss
  103. # 全文下标
  104. text_index = []
  105. match1 = re.finditer(reg, input)
  106. for i in match1:
  107. d = i.groupdict()
  108. if d.get("before") is not None:
  109. front_len = len(d.get("before")) + len(d.get("charac"))
  110. else:
  111. front_len = 0
  112. text_index.append([i.start()+front_len, i.end()])
  113. return output, text_index
  114. def calculateLen(ss, i):
  115. front_len = 0
  116. back_len = 0
  117. for index in range(i):
  118. front_len += len(ss[index])
  119. for index in range(i+1, len(ss)):
  120. back_len += len(ss[index])
  121. return front_len, back_len
  122. def extract_servicetime(text):
  123. list_servicetime = []
  124. word, text_index_list = re_serviceTime(text)
  125. # print(word, text_index_list)
  126. for i in range(len(text_index_list)):
  127. word_list = word.split(" ")
  128. d = {"body": word_list[i], "begin_index": text_index_list[i][0], "end_index": text_index_list[i][1]}
  129. if len(word_list[i]) <= 35:
  130. list_servicetime.append(d)
  131. # print(list_servicetime)
  132. return list_servicetime
  133. if __name__ == '__main__':
  134. s = """
  135. 4、其他:无
  136. 合同履行期限:双方签订合同后30天内
  137. 本项目( 不接受 )联合体投标。
  138. 二、申请人的资格要求:
  139. 1.满足《中华人民共和国政府采购法》第二十二条规定;
  140. 2.落实政府采购政策需满足的资格要求:
  141. 2.1具备《政府采购法》第二十二条规定的条件,且提供以下证明文件:
  142. (1)在中华人民共和国境内注册的法人或其他组织或自然人, 投标(响应)时提交有效的营业执照(或事业法人登记证或身份证等相关证明)副本复印件。
  143. (2)有依法缴纳税收和社会保障资金的良好记录:提供投标截止日前6个月内任意1个月依法缴纳税收和社会保障资金的相关材料。如依法免税或不需要缴纳社会保障资金的,提供相应证明材料。
  144. (3)供应商必须具有良好的商业信誉和健全的财务会计制度(提供2020年度财务状况报告或基本开户行出具的资信证明)。
  145. (4)履行合同所必需的设备和专业技术能力的证明材料或书面声明。
  146. (5)参加政府采购活动前 3 年内在经营活动中没有重大违法记录的书面声明。
  147. (6)信用记录:供应商未被列入“信用中国”网站(www.creditchina.gov.cn)“记录失信被执行人或重大税收违法案件当事人名单”记录名单; 不处于中国政府采购网(www.ccgp.gov.cn)“政府采购严重违法失信行为信息记录”中的禁止参加政府采购活动期间。
  148. """
  149. # s = "自合同签订之日起至2022-6-30 自合同签订之日起至2022-07-30"
  150. print(extract_servicetime(s))
  151. # df = pd.read_csv("C:\\Users\\admin\\Desktop\\serviceTime_text.csv")
  152. # result_list = []
  153. # for index, row in df.iterrows():
  154. # result = extract_servicetime(row["text"])
  155. # result_list.append(str(result))
  156. #
  157. # df["new_word"] = pd.DataFrame(result_list)
  158. # df.to_csv("C:\\Users\\admin\\Desktop\\serviceTime_text_new.csv")