document_.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. '''
  2. 招投标文件预审查
  3. '''
  4. from tools import BaseMethods
  5. from pprint import pprint
  6. import re
  7. chinese_num_map = {
  8. '零': 0,
  9. '一': 1,
  10. '二': 2,
  11. '三': 3,
  12. '四': 4,
  13. '五': 5,
  14. '六': 6,
  15. '七': 7,
  16. '八': 8,
  17. '九': 9,
  18. '十': 10
  19. }
  20. class DocumentPreReview():
  21. def __init__(self) -> None:
  22. self.bm = BaseMethods()
  23. self.bidding_tables = self.get_bidding_table()
  24. self.contexts = self.get_contexts()
  25. self.announcement = self.get_announcement()
  26. self.bidding_context = self.get_bidding_context()
  27. self.chinese_num_map = chinese_num_map
  28. def get_contexts(self, file_path:str = 'data/预审查数据/contexts.json'):
  29. ''' get contexts by page
  30. '''
  31. contexts = self.bm.json_read(file_path)
  32. return contexts
  33. def get_bidding_table(self):
  34. ''' get table data
  35. '''
  36. file_path = "data/预审查数据/Bidding_tables_2022-2025年度三峡电站9台机组检修密封加工制作重新招标招标文件印刷版.json"
  37. all_tables = self.bm.json_read(file_path)
  38. return all_tables
  39. def get_bidding_context(self):
  40. ''' read json to get context
  41. '''
  42. file_path = "data/预审查数据/基于物联网技术的三峡坝区智慧仓储研究与建设招标文件-发出.json"
  43. bidding_context = self.bm.json_read(file_path)
  44. return bidding_context
  45. def _scrutinize_judge(self, tag:str):
  46. ''' Clause number content judgment
  47. 商务 技术 报价 评审 评分 标准
  48. '''
  49. scrutinize_tuple = ("商务","技术","报价","评审","评分","标准")
  50. hit_num = 0
  51. for scru in scrutinize_tuple:
  52. if scru in tag: hit_num+= 1
  53. if hit_num>=3: return True
  54. else: return False
  55. def get_table(self):
  56. ''' parse the tables.json file to get the table data from it.
  57. '''
  58. all_tables = self.bidding_tables
  59. # 招标文件内容中预审查
  60. tag_sign = ''
  61. tag_list = ("形式评审标准", "资格评审标准", "响应性评审标准")
  62. tag_dict = dict([(tag,[]) for tag in tag_list])
  63. # 招标文件内容中清标表格数据
  64. scrutinize_tuple = ("商务部分评分标准","技术部分评审标准","投标报价评审标准","报价部分评审标准","报价评分标准")
  65. scrutinize_dict = dict([(scrutinize,[]) for scrutinize in scrutinize_tuple])
  66. scrutinize_page = 0
  67. scrutinize_index = 0
  68. scrutinize_Initial_position_marker = 0 # 详审位置标记
  69. record_page = 0
  70. bidder_know = {} # 投标人须知前附表
  71. for partial_form in all_tables:
  72. table_name = partial_form['table_name']
  73. page_number = partial_form['page_numbers']
  74. title_len = partial_form['title_len']
  75. tables = partial_form["table"]
  76. if '投标人须知前附表' == table_name:
  77. record_page = page_number[0]
  78. if page_number[0] < record_page + 3:
  79. for table in tables[1:]:
  80. try:
  81. if table[0] and table[0] not in bidder_know: bidder_know[table[0]] = []
  82. if table[0]: bidder_know[table[0]].append({"条款名称":table[1],"编列内容":table[2]})
  83. except:
  84. print()
  85. if '评标方法' in table_name:
  86. table_name = table_name.strip().replace("\n","")
  87. if table_name == "评标办法前附表":
  88. table_page_num = page_number[0]
  89. inital_data = tables[0]
  90. # confirm data location
  91. regulation_number_index = inital_data.index("条款号")
  92. evaluation_factor_index = inital_data.index("评审因素")
  93. evaluation_criteria_index = inital_data.index("评审标准")
  94. for table in tables[1:]:
  95. tag = table[regulation_number_index+1]
  96. if tag: tag = tag.strip().replace("\n","")
  97. if tag and self._scrutinize_judge(tag):
  98. tag_sign = tag
  99. evaluation_factor,evaluation_criteria = table[evaluation_factor_index],table[evaluation_criteria_index]
  100. if tag_sign in tag_dict:
  101. tag_dict[tag_sign].append({"评审因素":evaluation_factor.strip().replace("\n",""),
  102. "评审标准":evaluation_criteria.strip().replace("\n","")})
  103. if '评分因素' in table or '评分标准' in table:
  104. scrutinize_page = table_page_num
  105. scrutinize_Initial_position_marker = 1
  106. if not scrutinize_page: scrutinize_page = table_page_num+1
  107. ''' scrutinize '''
  108. if (scrutinize_page == page_number[0] and scrutinize_Initial_position_marker) or scrutinize_page == page_number[0]:
  109. regulation_number_index,evaluation_factor_index,evaluation_criteria_index,weights_index = 0,0,0,0
  110. for table in tables:
  111. if '评分因素' in table and '评分标准' in table:
  112. regulation_number_index = table.index("条款号")
  113. evaluation_factor_index = table.index("评分因素")
  114. evaluation_criteria_index = table.index("评分标准")
  115. weights_index = table.index("权重")
  116. tag_sign = ''
  117. scrutinize_index = tables.index(table)
  118. if scrutinize_index:
  119. for table in tables[scrutinize_index+1:]:
  120. if table[regulation_number_index+1]: tag = table[regulation_number_index+1]
  121. else: tag = table[regulation_number_index+2]
  122. if tag:
  123. tag = tag.strip().replace("\n","")
  124. tag = re.findall("[\u4e00-\u9fff]+", tag)[0]
  125. if tag and self._scrutinize_judge(tag):
  126. tag_sign = tag
  127. if tag_sign not in scrutinize_dict: scrutinize_dict[tag_sign] = []
  128. evaluation_factor,evaluation_criteria,weights = table[evaluation_factor_index],table[evaluation_criteria_index],table[weights_index]
  129. if not weights: value = {"评分因素":evaluation_factor.strip().replace("\n",""),"评分标准":evaluation_criteria.strip().replace("\n","")}
  130. else: value = {"评分因素":evaluation_factor.strip().replace("\n",""),
  131. "评分标准":evaluation_criteria.strip().replace("\n",""),
  132. "权重":weights.strip().replace("\n","")}
  133. scrutinize_dict[tag_sign].append(value)
  134. if '报价' in tag_sign and '标准' in tag_sign:
  135. scrutinize_dict = {key: value for key, value in scrutinize_dict.items() if value}
  136. break
  137. elif scrutinize_page+1 == page_number[0] and title_len == 5 and '报价' not in tag_sign:
  138. if scrutinize_Initial_position_marker:
  139. evaluation_factor_index -= 1
  140. evaluation_criteria_index -= 1
  141. weights_index -= 1
  142. for table in tables:
  143. if not table[2]:
  144. scrutinize_dict[tag_sign][-1]['评分标准'] += table[3]
  145. continue
  146. tag = table[regulation_number_index+1]
  147. if tag:
  148. tag = tag.strip().replace("\n","")
  149. tag = re.findall("[\u4e00-\u9fff]+", tag)[0]
  150. if tag and self._scrutinize_judge(tag):
  151. tag_sign = tag
  152. if tag_sign not in scrutinize_dict: scrutinize_dict[tag_sign] = []
  153. evaluation_factor,evaluation_criteria,weights = table[evaluation_factor_index],table[evaluation_criteria_index],table[weights_index]
  154. if not weights: value = {"评分因素":evaluation_factor.strip().replace("\n",""), "评分标准":evaluation_criteria.strip().replace("\n","")}
  155. else: value = {"评分因素":evaluation_factor.strip().replace("\n",""),
  156. "评分标准":evaluation_criteria.strip().replace("\n",""),
  157. "权重":weights.strip().replace("\n","")}
  158. scrutinize_dict[tag_sign].append(value)
  159. if '报价' in tag_sign and '标准' in tag_sign:
  160. scrutinize_dict = {key: value for key, value in scrutinize_dict.items() if value}
  161. scrutinize_Initial_position_marker = 0
  162. break
  163. elif scrutinize_page+2 == page_number[0] and title_len == 5 and '报价' not in tag_sign:
  164. for table in tables:
  165. if not table[2]:
  166. scrutinize_dict[tag_sign][-1]['评分标准'] += table[3]
  167. continue
  168. tag = table[regulation_number_index+1]
  169. if tag:
  170. tag = tag.strip().replace("\n","")
  171. tag = re.findall("[\u4e00-\u9fff]+", tag)[0]
  172. if tag and self._scrutinize_judge(tag):
  173. tag_sign = tag
  174. if tag_sign not in scrutinize_dict: scrutinize_dict[tag_sign] = []
  175. evaluation_factor,evaluation_criteria,weights = table[evaluation_factor_index],table[evaluation_criteria_index],table[weights_index]
  176. if not weights: value = {"评分因素":evaluation_factor.strip().replace("\n",""), "评分标准":evaluation_criteria.strip().replace("\n","")}
  177. else: value = {"评分因素":evaluation_factor.strip().replace("\n",""),
  178. "评分标准":evaluation_criteria.strip().replace("\n",""),
  179. "权重":weights.strip().replace("\n","")}
  180. scrutinize_dict[tag_sign].append(value)
  181. if '报价' in tag_sign and '标准' in tag_sign:
  182. scrutinize_dict = {key: value for key, value in scrutinize_dict.items() if value}
  183. break
  184. # pprint(tag_dict)
  185. pprint(scrutinize_dict)
  186. # pprint(bidder_know)
  187. return tag_dict,bidder_know,scrutinize_dict
  188. def get_announcement(self)->str:
  189. ''' bidder announcement
  190. '''
  191. announcements = ''
  192. announcement_contexts = self.contexts[2:8]
  193. for index, announcement in enumerate(announcement_contexts):
  194. finder = re.findall("^第一章",announcement['text'])
  195. if finder:
  196. for text in announcement_contexts[index:]:
  197. if re.findall("^第二章", text["text"]): break
  198. announcements += text["text"]
  199. break
  200. return announcements
  201. def formal_criteria(self, review_criteria_list:list):
  202. ''' Analysis of formal review criteria
  203. 形式评审标准
  204. [{'评审因素': '投标人名称', '评审标准': '与营业执照书一致'},
  205. {'评审因素': '投标文件封面、投标函签字盖章',
  206. '评审标准': '投标文件封面、投标函须有法定代表人(或其委托代理人)签字(或签章)并加盖单位章,由委托代理人签字的须具有有效的授权委托书'},
  207. {'评审因素': '投标文件格式', '评审标准': '符合第八章“投标文件格式”的要求'},
  208. {'评审因素': '联合体投标人(如有)', '评审标准': '不适用'},
  209. {'评审因素': '报价唯一', '评审标准': '只能有一个有效报价'}]
  210. '''
  211. for review_criteria in review_criteria_list:
  212. evaluation_factor = review_criteria['评审因素']
  213. evaluation_criteria = review_criteria['评审标准']
  214. if '投标人名称' in evaluation_factor or '供应商名称' in evaluation_factor:
  215. ['营业执照','资质证书']
  216. '''
  217. 要求投标文件中 投标公司 与 其提供的营业执照或资质证书中的名称相同
  218. '''
  219. pass
  220. elif '报价函签字盖章' in evaluation_factor or '投标文件封面、投标函签字盖章' in evaluation_factor:
  221. '''
  222. 要求投标文件中 投标公司的 法人或委托人签字或是 存在单位盖章
  223. '''
  224. pass
  225. elif '投标文件格式' in evaluation_factor:
  226. comp1 = re.compile("(第.*?章)")
  227. comp2 = re.compile("“(.*?)”")
  228. title = comp1.findall(evaluation_criteria)[0]+comp2.findall(evaluation_criteria)[0]
  229. comp3 = re.compile("第(.*?)章")
  230. title_list = []
  231. format_index,sta_page = -1,-1
  232. sign = True
  233. title_next = ''
  234. for context in self.bidding_context: # 取招标文件内容
  235. text = context['text'].strip().replace(" ","")
  236. if text == '目录':
  237. sta_page = context['page_number']
  238. if sta_page != -1 and context['page_number'] < 4:
  239. finder = comp3.findall(context['text'])
  240. if finder and sign:
  241. if title_list:
  242. chinese_num = self.chinese_num_map.get(comp3.findall(title_list[-1])[0],None)
  243. if chinese_num > self.chinese_num_map.get(finder[0],0):
  244. sign = False
  245. else:
  246. title_list.append(context['text'].split(' ')[0])
  247. else:
  248. title_list.append(context['text'].split(' ')[0])
  249. if text == title and format_index == -1:
  250. format_index = self.bidding_context.index(context)
  251. break
  252. title_index = title_list.index(title)
  253. if title_index != len(title_list)-1:
  254. title_next = title_list[title_index+1]
  255. file_format = {title:[]}
  256. for context in self.bidding_context[format_index+1:]:
  257. text = context['text'].strip().replace(" ","")
  258. if title_next and title_next == text:
  259. break
  260. file_format[title].append(text)
  261. pprint(file_format) # 需要优化提取的内容
  262. '''
  263. 招标文件 file_format 与投标文件内容对比,投标文件中只要存在file_format内容即可
  264. '''
  265. elif '联合体投标人' in evaluation_factor:
  266. if '不适用' in evaluation_criteria: continue
  267. elif '报价唯一' in evaluation_factor:
  268. '''
  269. 需要在投标文件中比对三个位置的报价总和值抽取
  270. '''
  271. pass
  272. def qualification_criteria(self, review_criteria_list:list, bidder_know:dict):
  273. ''' Qualification assessment criteria
  274. 资格评审标准
  275. '''
  276. for review_criteria in review_criteria_list:
  277. evaluation_factor = review_criteria['评审因素']
  278. evaluation_criteria = review_criteria['评审标准']
  279. if '营业执照' in evaluation_factor:
  280. '''
  281. 在投标文件中 对营业执照识别营业期限;长期识别认为可以;只有开始时间没有结束时间给提示。
  282. '''
  283. pass
  284. elif '资质' in evaluation_factor:
  285. comp1 = re.compile('(第.*?章)')
  286. comp2 = re.compile('“(.*?)”')
  287. comp3 = re.compile('第(.*?)项规定')
  288. finder1 = comp1.findall(evaluation_criteria)[0]
  289. finder2 = comp2.findall(evaluation_criteria)[0]
  290. finder3 = comp3.findall(evaluation_criteria)[0]
  291. chapter_name = finder1+finder2
  292. stipulation = finder3
  293. if '第二章' in chapter_name:
  294. bidder_data = bidder_know.get(stipulation,None)
  295. if not bidder_data: continue
  296. clause_name = bidder_data['条款名称'].replace("\n","")
  297. list_content = bidder_data['编列内容']
  298. if '招标公告' in list_content:
  299. cert_index = self.announcement.index('资质') ## 默认 资质条件 不变
  300. cert_required = re.findall(":(.*?)\\n",self.announcement[cert_index:cert_index+500])[0]
  301. '''
  302. big model
  303. 需要设计prompt,可将内容及情况在线上glm4中使用,测出合适prompt
  304. '''
  305. def content_parsing(self):
  306. ''' data analysis aggregate function
  307. '''
  308. tag_dict,bidder_know = dpr.get_table()
  309. # {}
  310. # self.formal_criteria(tag_dict['形式评审标准'])
  311. # self.qualification_criteria(tag_dict['资格评审标准'], bidder_know)
  312. if __name__ == '__main__':
  313. dpr = DocumentPreReview()
  314. dpr.get_table()
  315. # print(dpr.bidding_context)
  316. # formal_review_criteria = [
  317. # {'评审因素': '投标文件格式', '评审标准': '符合第八章“投标文件格式”的要求'}
  318. # ]
  319. # dpr.formal_criteria(formal_review_criteria)