document_.py 17 KB

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