re_bidway.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. import ast
  2. import pandas as pd
  3. import re
  4. # from BiddingKG.dl.interface import Entitys
  5. # def re_bidway_old(text):
  6. # df = pd.read_csv("C:\\Users\\admin\\Desktop\\bidway_text.csv")
  7. #
  8. # reg = re.compile(u'(采购方式|竞价方式|招标方式|询价类型|交易方式|寻源策略|招标形式|询价方式'
  9. # u'|发包方式|发包类型|开展方式|招标类型)(.*)'
  10. # u'(公开招标|竞争性磋商|竞争性谈判|公开采购|单一来源'
  11. # u'|电子书面竞投|邀请招标|定向公开|询价采购|抽签摇号'
  12. # u'|网上电子投标|比质比价|询单|询比采购|比选|单一来源采购'
  13. # u'|网上招标|其他'
  14. # u'|竞谈竞价|网上直购|公开竞谈'
  15. # u'|库内邀请|库内公开发包)')
  16. #
  17. # # reg = re.compile(u'(公开招标|竞争性磋商|竞争性谈判采购|公开采购|单一来源|网络竞价'
  18. # # u'|竞争性谈判|公开询价|邀请招标|公开招募|公开询比价|电子书面竞投'
  19. # # u'|网上电子投标|比质比价|定向询单|国内比选|电子竞价'
  20. # # u'|公开招租|公开竞标方式|网上招标|公开招标|国内竞争性谈判'
  21. # # u'|国内竞争性磋商|公开竞谈|定向询价|网上询价|网上竞价|公开比选|磋商采购|网上直购'
  22. # # u'|库内邀请|询价采购|询比采购|分散采购|单一来源采购)')
  23. #
  24. # reg2 = re.compile(u'(采用|以|)'
  25. # u'(公开招标|竞争性磋商|竞争性谈判|公开采购|单一来源'
  26. # u'|竞争性谈判|询价|电子书面竞投|电子竞价'
  27. # u'|网上电子投标|比质比价|询单|询比采购|比选|单一来源采购'
  28. # u'|网上招标|分散采购'
  29. # u'|竞谈竞价|网上直购|公开竞谈'
  30. # u'|库内邀请)'
  31. # u'(采购方式|方式)')
  32. #
  33. # reg1 = re.compile(
  34. # # u'(公开招标|竞争性磋商|竞争性谈判采购|公开采购|单一来源采购|网络竞价|公开招商方式'
  35. # # u'|竞争性谈判|公开询价|询价采购|邀请招标|公开招募|公开询比|电子书面竞投'
  36. # # u'|网上电子投标|比质比价|定向询单|询比采购|国内比选|单一来源|公开选取|库内公开发包'
  37. # # u'|公开招租|公开竞标方式|网上招标|公开招标|竞争性谈判|公开招投标'
  38. # # u'|国内竞争性磋商|公开竞谈|定向询价|网上询价|网上竞价|公开比选|磋商采购|网上直购'
  39. # # u'|国际公开竞争性招标)'
  40. # u'(公开招标|竞争性磋商|竞争性谈判|公开采购|单一来源'
  41. # u'|竞争性谈判|询价|电子书面竞投'
  42. # u'|网上电子投标|比质比价|询单|询比采购|比选|单一来源采购'
  43. # u'|网上招标|分散采购'
  44. # u'|竞谈竞价|网上直购|公开竞谈'
  45. # u'|库内邀请)'
  46. # )
  47. #
  48. # # 都切为4个字符
  49. # # reg1_not = re.compile(u'(及单一来源|询价小组成员|除单一来源|竞争性谈判邀请函|询价记录)')
  50. # reg1_not = re.compile(u'(及单一来|价小组成|除单一来|性谈判邀|询价记录)')
  51. #
  52. # reg3 = re.compile(u'(采购方式:邀请|采购方式:公开|采购方式:询价|分散采购|公开招标|竞价|磋商|询比|竞标|邀请招标|公开招募|公开招租)')
  53. #
  54. #
  55. # reg_standard = re.compile(u'(公开招标|竞争性磋商|竞争性谈判|单一来源'
  56. # u'|竞争性谈判|询价|邀请招标|公开招募|询比|电子书面竞投'
  57. # u'|网上电子投标|比质比价|询单|比选'
  58. # u'|公开招租|网上招标|分散采购'
  59. # u'|网上直购|公开竞谈|采购方式:邀请|采购方式:公开|采购方式:询价)'
  60. # )
  61. #
  62. # text_list = df["text"].to_list()
  63. # # text_list = []
  64. # # text_list.append(text)
  65. # text_index_list = []
  66. # output_list = []
  67. # for index in range(len(text_list)):
  68. # # 全文下标
  69. # text_index = [0, 0]
  70. #
  71. # input_str = text_list[index]
  72. #
  73. # # 把一些混淆的词先替换掉
  74. # input_str = re.sub(reg1_not, "####", input_str)
  75. #
  76. # match = reg.search(input_str)
  77. # output_str = None
  78. # # 根据正则表达式匹配
  79. # if match:
  80. # # 更新全文下标
  81. # text_index[0] = match.start()
  82. # text_index[1] = match.end()
  83. #
  84. # # 判断长度,截断
  85. # if len(match.group()) >= 15:
  86. # ss = re.split(",|\.|,|。|;|;", match.group())
  87. # # 判断所需的字符串在哪一段
  88. # for i in range(len(ss)):
  89. # if re.search(reg1, ss[i]):
  90. # output_str = ss[i]
  91. #
  92. # # 更新全文下标
  93. # front_len, back_len = calculateLen(ss, i)
  94. # text_index[0] = text_index[0] + front_len + i
  95. # text_index[1] = text_index[1] - back_len + len(ss) -1 - i
  96. #
  97. # break
  98. # else:
  99. # output_str = match.group()
  100. #
  101. # else:
  102. # match2 = re.search(reg2, input_str)
  103. # if match2:
  104. # # 更新全文下标
  105. # text_index[0] = match2.start()
  106. # text_index[1] = match2.end()
  107. #
  108. # output_str = match2.group()
  109. #
  110. # else:
  111. # match1 = re.search(reg1, input_str)
  112. # if match1:
  113. # # 更新全文下标
  114. # text_index[0] = match1.start()
  115. # text_index[1] = match1.end()
  116. # output_str = match1.group()
  117. #
  118. # # 再判断一次长度
  119. # if output_str is not None:
  120. # if len(output_str) >= 15:
  121. # match2 = re.search(reg2, input_str)
  122. # if match2:
  123. # # 更新全文下标
  124. # text_index[0] = match2.start()
  125. # text_index[1] = match2.end()
  126. #
  127. # output_str = match2.group()
  128. # if len(output_str) >= 15:
  129. # match1 = re.search(reg1, input_str)
  130. # if match1:
  131. # # 更新全文下标
  132. # text_index[0] = match1.start()
  133. # text_index[1] = match1.end()
  134. #
  135. # output_str = match1.group()
  136. #
  137. # # 最后输出还为空,匹配一些易混淆的词
  138. # if output_str is None:
  139. # match3 = re.search(reg3, input_str)
  140. # if match3:
  141. # # 更新全文下标
  142. # text_index[0] = match3.start()
  143. # text_index[1] = match3.end()
  144. #
  145. # output_str = match3.group()
  146. #
  147. # # 处理前缀等无用词
  148. # if output_str is not None:
  149. # match5 = re.search("分散采购|采购方式:邀请", output_str)
  150. # if not match5:
  151. # # 公开采购转为公开招标
  152. # output_str = re.sub("公开采购", "公开招标", output_str)
  153. #
  154. # # 去掉第一个字符冒号
  155. # ss = re.split(":|:", output_str)
  156. # output_str = ss[-1]
  157. # # 更新全文下标
  158. # front_len, back_len = calculateLen(ss, len(ss) - 1)
  159. # text_index[0] = text_index[0] + front_len + len(ss) - 1
  160. #
  161. # # 去掉采购、方式、采用
  162. # match6 = re.search("(采用|出售|直接(|现就本次|招标为)", output_str)
  163. # match7 = re.search("(采购|方式|进行)", output_str)
  164. # output_str = re.sub("(采购|方式|采用|出售|进行|直接(|现就本次|招标为)", "", output_str)
  165. # # 更新全文下标
  166. # if match6:
  167. # text_index[0] += match6.end() - match6.start()
  168. # if match7:
  169. # text_index[1] -= match7.end() - match7.start()
  170. #
  171. # # 使用标准标签过滤
  172. # match4 = re.search(reg_standard, output_str)
  173. # if match4:
  174. # output_str = match4.group()
  175. # # 更新全文下标
  176. # text_index[0] += match4.start()
  177. # text_index[1] = text_index[0] + match4.end() - match4.start()
  178. #
  179. # output_list.append(output_str)
  180. # # text_index_list.append(str(text_index))
  181. # text_index_list.append(text_index)
  182. #
  183. # # df["re"] = pd.DataFrame(output_list)
  184. # # df["text_index"] = pd.DataFrame(text_index_list)
  185. #
  186. # # index_to_word = []
  187. # # for index, row in df.iterrows():
  188. # # i_list = ast.literal_eval(row["text_index"])
  189. # # word = row["text"][i_list[0]:i_list[1]]
  190. # # if len(word) >= 20:
  191. # # word = ""
  192. # # index_to_word.append(word)
  193. #
  194. #
  195. # # df["index2word"] = pd.DataFrame(index_to_word)
  196. # # df.to_csv("C:\\Users\\admin\\Desktop\\bidway_text2.csv")
  197. #
  198. # return output_list[0], text_index_list[0]
  199. normal_bidway = "公开招标|邀请招标|竞争性谈判|竞争性磋商|单一来源|框架协议|询价"
  200. bidway = '单一来源' \
  201. '|国内竞争性磋商|竞争性磋商|竞争性谈判|网络竞价|网上竞价|公开竞谈|公开竞价|电子竞价|竞价|竞标|竞谈竞价|电子书面竞投' \
  202. '|公开比选|比质比价|比选' \
  203. '|公开招标|公开招租|公开招募|公开选取|公开招投标' \
  204. '|网上直购|网上招标|网上电子投标|网上挂牌' \
  205. '|邀请招标' \
  206. '|网上询价|公开询价|非定向询价|定向询价|询比价|询单|询价|询比' \
  207. '|库内邀请|库内公开发包|内部邀标' \
  208. '|定点采购议价|定点采购' \
  209. '|竞争性评审|框架协议'
  210. not_bidway = '及单一来源|询价小组成员|除单一来源|竞争性谈判邀请函|询价记录|自由竞价' \
  211. '|限时竞价|咨询单位|询价单'
  212. not_bidway_preffix = "本次|拟|参加|无效|标的|联合体|参与|否决|除|可以选择|包括|涉及|非"
  213. not_bidway_suffix = "文件|报名|邀请|项目|失败|数量|编号|后|时间|类型|名称|和|成交" \
  214. "|标题|开始|结束|产品|报价|供应商|部门|监督|需求|范围|入围|内容|人" \
  215. "|条件|公司|保证金|完毕|事件|成功|活动|地点|标|会|须知|范围" \
  216. "|响应|报价|采购公示|的原因|采购供应商|价|采购人员|失败|小组"
  217. bidway_preffix = '采购方式|竞价方式|招标方式|询价类型|交易方式|寻源策略|招标形式|询价方式' \
  218. '|发包方式|发包类型|开展方式|招标类型|选取方式|招租方式'
  219. bidway_special = '采购方式:公开|采购方式:邀请|采购方式:询价' \
  220. '|招标方式:.公开|采购方式:.公开' \
  221. '|分散采购' \
  222. ''
  223. def re_not_bidway(_str):
  224. match = re.findall(not_bidway, _str)
  225. if match:
  226. for word in match:
  227. instead = "#" * len(word)
  228. _str = re.sub(word, instead, _str)
  229. reg_not1 = "(" + bidway + ")" + "(" + not_bidway_suffix + ")"
  230. match = re.findall(reg_not1, _str)
  231. if match:
  232. for word in match:
  233. word_add = ""
  234. for w in word:
  235. word_add += w
  236. instead = "#" * len(word_add)
  237. _str = re.sub(word_add, instead, _str)
  238. reg_not2 = "(" + not_bidway_preffix + ")" + "(" + bidway + ")"
  239. match = re.findall(reg_not2, _str)
  240. if match:
  241. for word in match:
  242. word_add = ""
  243. for w in word:
  244. word_add += w
  245. instead = "#" * len(word_add)
  246. _str = re.sub(word_add, instead, _str)
  247. return _str
  248. def re_standard_bidway(_str):
  249. reg_standard = "(?P<preffix>" + bidway_preffix + ")" \
  250. + "(?P<char>.{1,2})" \
  251. + "(?P<value>" + bidway + ")"
  252. match = re.finditer(reg_standard, _str)
  253. bidway_list = []
  254. if match:
  255. for m in match:
  256. keyword = m.group('value')
  257. keyword_index = list(m.span('value'))
  258. behind_str = _str[m.start(): m.end()+30]
  259. if len(re.findall(normal_bidway, behind_str))>1:
  260. keyword = ''
  261. for it in re.finditer('(?P<sign>.{1,2})(?P<bidway>'+normal_bidway+')+', behind_str): # 招标方式后面多个选择处理
  262. if '□' != it.group('sign')[-1]:
  263. keyword = it.group('bidway')
  264. keyword_index = [m.start()+it.start('bidway'), m.start()+it.end('bidway')]
  265. break
  266. # m_dict = m.groupdict()
  267. # m_span = m.span()
  268. # keyword = ""
  269. # keyword_index = [m_span[0], m_span[1]]
  270. # for key in m_dict.keys():
  271. # if key == "value":
  272. # keyword = m_dict.get(key)
  273. # else:
  274. # keyword_index[0] += len(m_dict.get(key))
  275. bidway_list.append([keyword, keyword_index])
  276. return bidway_list
  277. def re_normal_bidway(_str):
  278. ser = re.search("("+normal_bidway+")(转为?|变更为|更改为)"+"(?P<bidway>(" + normal_bidway + "))", _str) # 如果方式变更取变更后的
  279. if ser:
  280. return [[ser.group('bidway'), list(ser.span('bidway'))]]
  281. reg_all = "(?P<value>" + normal_bidway + ")"
  282. match = re.finditer(reg_all, _str)
  283. bidway_list = []
  284. bidway_set = set()
  285. if match:
  286. for m in match:
  287. keyword = m.group()
  288. if keyword == '公开招标' and m.start()>0 and _str[m.start()-1]=='非':
  289. continue
  290. keyword_index = list(m.span())
  291. bidway_set.add(keyword)
  292. bidway_list.append([keyword, keyword_index])
  293. if len(bidway_list) == 0: # 如果找不到标准方式,匹配简称方式
  294. ser = re.search('(?P<bidway>(磋商|谈判))(公告|成交|结果)', _str)
  295. if ser:
  296. return [[ser.group('bidway'), list(ser.span('bidway'))]]
  297. if len(bidway_set) > 1: # 匹配到多种招标方式返回空
  298. return []
  299. return bidway_list
  300. def re_all_bidway(_str):
  301. reg_all = "(?P<value>" + normal_bidway + ")" # 优先匹配规范的招标方式
  302. match = re.finditer(reg_all, _str)
  303. bidway_list = []
  304. if match:
  305. for m in match:
  306. keyword = m.group()
  307. keyword_index = list(m.span())
  308. bidway_list.append([keyword, keyword_index])
  309. return bidway_list
  310. reg_all = "(?P<value>" + bidway + ")"
  311. match = re.finditer(reg_all, _str)
  312. bidway_list = []
  313. if match:
  314. for m in match:
  315. keyword = m.group()
  316. keyword_index = list(m.span())
  317. bidway_list.append([keyword, keyword_index])
  318. return bidway_list
  319. def re_special_bidway(_str):
  320. reg_special = "(?P<value>" + bidway_special + ")"
  321. match = re.finditer(reg_special, _str)
  322. bidway_list = []
  323. if match:
  324. for m in match:
  325. keyword = m.group()
  326. keyword_index = list(m.span())
  327. bidway_list.append([keyword, keyword_index])
  328. return bidway_list
  329. def get_one_word(bidway_list):
  330. # 若有多个,去重,输出较长的
  331. word = None
  332. text_index = [0, 0]
  333. if len(bidway_list) > 1:
  334. word_dict = {}
  335. for bw in bidway_list:
  336. if bw[0] in word_dict.keys():
  337. if bw[1][0] < word_dict.get(bw[0])[0]:
  338. word_dict[bw[0]] = bw[1]
  339. else:
  340. word_dict[bw[0]] = bw[1]
  341. word_list = []
  342. for key in word_dict.keys():
  343. word_list.append([key, word_dict.get(key)[0]])
  344. if len(word_list) > 1:
  345. word_list.sort(key=lambda x: (-int(x[1]), len(x[0])))
  346. word = word_list[-1][0]
  347. text_index = word_dict.get(word)
  348. elif word_list:
  349. word = word_list[0][0]
  350. text_index = word_dict.get(word)
  351. else:
  352. text_index = [0, 0]
  353. elif len(bidway_list) == 1:
  354. word = bidway_list[0][0]
  355. text_index = bidway_list[0][1]
  356. return word, text_index
  357. def re_bidway(text, title):
  358. # 优先匹配标题标准招标方式
  359. if len(title)<100:
  360. bidway_list = re_normal_bidway(title)
  361. if bidway_list:
  362. word, text_index = get_one_word(bidway_list)
  363. return word, text_index
  364. # 替换易混淆词
  365. text_clean = re_not_bidway(text)
  366. title_clean = re_not_bidway(title)
  367. # 查找符合标准形式的
  368. bidway_list = re_standard_bidway(text_clean)
  369. if bidway_list:
  370. word = bidway_list[0][0]
  371. text_index = bidway_list[0][1]
  372. return word, text_index
  373. # 无符合标准形式的,查找title里的所有形式
  374. bidway_list = re_all_bidway(title_clean)
  375. if bidway_list:
  376. word, text_index = get_one_word(bidway_list)
  377. return word, text_index
  378. # 无符合标准形式的,查找所有形式
  379. bidway_list = re_all_bidway(text_clean)
  380. if bidway_list:
  381. word, text_index = get_one_word(bidway_list)
  382. return word, text_index
  383. # 还无结果,查找特殊形式
  384. bidway_list = re_special_bidway(text_clean)
  385. if bidway_list:
  386. word = bidway_list[0][0]
  387. text_index = bidway_list[0][1]
  388. return word, text_index
  389. # 查无结果
  390. return None, [0, 0]
  391. def extract_bidway(text, title):
  392. list_bidway = []
  393. word, text_index_list = re_bidway(text, title)
  394. if word is not None:
  395. if text_index_list[1]-text_index_list[0] != len(word) \
  396. or text_index_list[1]-text_index_list[0] >= 10:
  397. return []
  398. d = {"body": word, "begin_index": text_index_list[0], "end_index": text_index_list[1]}
  399. list_bidway.append(d)
  400. # print(d.get("body"), d.get("begin_index"), d.get("end_index"))
  401. return list_bidway
  402. bidway_dict = {'询价': '询价', '竞争性谈判': '竞争性谈判',
  403. '公开比选': '其他', '国内竞争性磋商': '竞争性磋商',
  404. '招标方式:t公开': '公开招标', '竞价': '竞价',
  405. '竞标': '竞价', '电子竞价': '竞价',
  406. '电子书面竞投': '竞价', '单一来源': '单一来源',
  407. '网上竞价': '竞价', '公开招标': '公开招标',
  408. '询比': '询价', '定点采购': '其他',
  409. '招标方式:■公开': '公开招标', '交易其他,付款其他': '其他',
  410. '竞争性评审': '竞争性磋商', '公开招租': '其他', '\\N': '',
  411. '比选': '其他', '比质比价': '其他', '分散采购': '其他',
  412. '内部邀标': '邀请招标', '邀请招标': '邀请招标',
  413. '网上招标': '公开招标', '非定向询价': '询价',
  414. '网络竞价': '竞价', '公开询价': '询价',
  415. '定点采购议价': '其他', '询单': '询价',
  416. '网上挂牌': '其他', '网上直购': '其他',
  417. '定向询价': '询价', '采购方式:公开': '公开招标',
  418. '磋商': '竞争性磋商', '公开招投标': '公开招标',
  419. '招标方式:√公开': '公开招标', '公开选取': '公开招标',
  420. '网上电子投标': '公开招标', '公开竞谈': '竞争性谈判',
  421. '竞争性磋商': '竞争性磋商', '采购方式:邀请': '邀请招标',
  422. '公开竞价': '竞价', '其他': '其他', '公开招募': '其他',
  423. '网上询价': '询价', '框架协议': '框架协议', '谈判':'竞争性谈判'}
  424. # bidway名称统一规范
  425. def bidway_integrate(bidway):
  426. integrate_name = bidway_dict.get(bidway,"其他")
  427. return integrate_name
  428. def bidway_normalize(key):
  429. if re.search('公开招标|公开发包', key):
  430. return '公开招标'
  431. elif re.search('单一来源', key):
  432. return '单一来源'
  433. elif re.search('磋商', key):
  434. return '竞争性磋商'
  435. elif re.search('谈判', key):
  436. return '竞争性谈判'
  437. elif re.search('竞谈|竞价|竞投|竞标', key):
  438. return '竞价'
  439. elif re.search('询价|询比|比价|询单', key):
  440. return '询价'
  441. elif re.search('邀请|邀标', key):
  442. return '邀请招标'
  443. else:
  444. return bidway_dict.get(key, '其他')
  445. def test_csv():
  446. df = pd.read_csv("C:\\Users\\Administrator\\Desktop\\bidway_text.csv")
  447. predict_list = []
  448. for index, row in df.iterrows():
  449. word, text_index = re_bidway(row["text"], "")
  450. if word:
  451. predict = [word, text_index]
  452. else:
  453. predict = []
  454. print("predict", predict)
  455. predict_list.append(str(predict))
  456. predict_df = pd.DataFrame(predict_list)
  457. df = pd.concat([df, predict_df], axis=1)
  458. df.to_csv("C:\\Users\\Administrator\\Desktop\\bidway_result.csv")
  459. print("finish write!")
  460. def test_str():
  461. s = '政府采购项目招标方式:公开招标,联系人:黎明。代理机构地址:广州市天河区'
  462. s = '''
  463. ,关于人防工程技术咨询服务项目【重新招标】单一来源谈判的通知,各投标人:深圳市国际招标有限公司受中共
  464. 深圳市委军民融合发展委员会办公室委托,就人防工程技术咨询服务项目【重新招标】(项目编号:0658-2171
  465. 1A60965),进行公开招标,因投标单位不足三家,公开招标失败,现经采购单位同意,采用单一来源谈判方式
  466. 确定中标供应商,邀请中国建筑标准设计研究院有限公司前来谈判,一、项目编号:0658-21711A60965,二
  467. 、项目名称:人防工程技术咨询服务项目【重新招标】,三、凡被邀请参加谈判的供应商必须按照原招标文件第
  468. 六章要求制作谈判文件正本一本,副本二本,按规定的时间密封递交并参加谈判,四、谈判内容:投标价格、项
  469. 目实施方案、售后服务方案和其它相关事项,五、地点及时间:1、因疫情影响本项目谈判响应文件采用邮寄方
  470. 式接收文件,2、文件接收截止时间:2021年11月5日14:30(北京时间),3、谈判响应文件邮寄地址:深圳
  471. 市罗湖区嘉宾路2018号深华商业大厦裙楼6层600A。收件人:郑工,电话:18806665013,3、谈判地点:
  472. 线上谈判,六、谈判的相关规则按原招标文件的相应规定执行;有关谈判事宜详见招标文件第六章《公开招标失
  473. 败后后续采购程序和投标须知》,1、采购人信息,名称:中共深圳市委军民融合发展委员会办公室,地址:深
  474. 圳市福田区新洲路5008号,联系方式:刘先生,电话:0755-88100332,2、采购代理机构信息,名称:深
  475. 圳市国际招标有限公司,地址:罗湖总部:深圳市罗湖区嘉宾路2018号深华商业大厦裙楼6层,深圳湾总部:深
  476. 圳市南山区沙河西路与白石路交汇处深圳湾科技生态园9栋B4座6楼,联系方式:0755-22918634,监督举报
  477. 电话:0755-22965602、0755-86660475,特此通知,深圳市国际招标有限公司,2021年11月1日,更多
  478. 咨询报价请点击:http://zbcloud.net/bidbulletin/69495.htm,
  479. '''
  480. print(extract_bidway(s, title=""))
  481. def test_html():
  482. # html_path = "C:/Users/Administrator/Desktop/3.html"
  483. html_path = 'd:/html/2.html'
  484. with open(html_path, "r", encoding='utf-8') as f:
  485. s = f.read()
  486. print(extract_bidway(s, title=""))
  487. def get_valuate():
  488. import psycopg2
  489. conn = psycopg2.connect(host='192.168.2.103', port='5432', user='postgres', password='postgres', dbname='iepy')
  490. cursor = conn.cursor()
  491. sql = "select c1.docid, c1.doctitle, c1.extract_json, c2.text from corpus_otherinput c1 left join corpus_iedocument c2 on c1.docid=c2.human_identifier where c1.new_extract notnull;" # where docid='110635873'
  492. # sql = "select c1.docid, c1.doctitle from corpus_otherinput c1;"
  493. # sql = "select text from corpus_iedocument limit 50000;"
  494. cursor.execute(sql)
  495. datas = []
  496. olds = []
  497. news = []
  498. label_old = []
  499. label_new = []
  500. labels = []
  501. for row in cursor.fetchall():
  502. docid = row[0]
  503. doctitle = row[1]
  504. ex = row[2]
  505. text = row[3]
  506. ser = re.search('"bidway": "(\w{,6})"', ex)
  507. # print('ser:', ser)
  508. old = ser.group(1) if ser else ""
  509. pred = extract_bidway(text, title=doctitle)
  510. # list_bidway = extract_bidway(text, title=doctitle)
  511. # print('list_bidway', list_bidway)
  512. # if list_bidway:
  513. # bidway = list_bidway[0].get("body")
  514. # # bidway名称统一规范
  515. # bidway = bidway_integrate(bidway)
  516. # else:
  517. # bidway = ""
  518. # print('bidway: ', bidway)
  519. pred = pred[0]['body'] if len(pred) > 0 else ""
  520. new = bidway_dict.get(pred, "其他") if pred!="" else ""
  521. sql2 = "select value from brat_bratannotation where document_id='{0}' and value like '%bidway%' limit 4;".format(docid)
  522. cursor.execute(sql2)
  523. lb_new = docid + "_"
  524. lb_old = docid + "_"
  525. tmp_l = []
  526. for row in cursor.fetchall():
  527. lb = row[0].split()[-1]
  528. lb = bidway_dict.get(lb, "其他") # 新准确率:0.9642, 召回率: 0.9642, F1: 0.8965
  529. # lb = bidway_normalize(lb) # 旧准确率:0.9287, 召回率: 0.9287, F1: 0.8011 新准确率:0.9692, 召回率: 0.9692, F1: 0.9105
  530. tmp_l.append(lb)
  531. if lb == new:
  532. lb_new = docid + "_" + lb
  533. if lb == old:
  534. lb_old = docid + "_" + lb
  535. olds.append(docid + "_" + old)
  536. news.append(docid + "_" + new)
  537. label_new.append(lb_new)
  538. label_old.append(lb_old)
  539. labels.append(';'.join(tmp_l))
  540. datas.append((docid, docid + "_" + old, lb_old, docid + "_" + new, lb_new, ';'.join(tmp_l)))
  541. eq_old = len(set(olds)&set(label_old))
  542. eq_new = len(set(news)&set(label_new))
  543. acc_old = eq_old/len(set(olds))
  544. recall_old = eq_old/len(set(label_old))
  545. f1_old = acc_old*recall_old/2*(acc_old+recall_old)
  546. acc_new = eq_new/len(set(news))
  547. recall_new = eq_new/len(set(label_new))
  548. f1_new = acc_new*recall_new/2*(acc_new+recall_new)
  549. print('旧准确率:%.4f, 召回率: %.4f, F1: %.4f'%(acc_old, recall_old, f1_old))
  550. print('新准确率:%.4f, 召回率: %.4f, F1: %.4f'%(acc_new, recall_new, f1_new))
  551. df = pd.DataFrame(datas, columns=['docid', 'pred_old', 'label_old', 'pred_new', 'label_new', 'labels'])
  552. df['old_pos'] = df.apply(lambda x:1 if x['pred_old']==x['label_old'] else 0, axis=1)
  553. df['new_pos'] = df.apply(lambda x:1 if x['pred_new']==x['label_new'] else 0, axis=1)
  554. df.to_csv('E:/其他数据/招标方式预测结果.csv', index=False)
  555. if __name__ == "__main__":
  556. # extract_bidway(s)
  557. # test_csv()
  558. test_str()
  559. # test_html()
  560. pass