document_.py 17 KB

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