test4.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. '''
  2. Created on 2019年1月4日
  3. @author: User
  4. '''
  5. from bs4 import BeautifulSoup, Comment
  6. import copy
  7. import re
  8. import sys
  9. import os
  10. import codecs
  11. import requests
  12. import time
  13. _time1 = time.time()
  14. sys.path.append(os.path.abspath("../.."))
  15. import fool
  16. from BiddingKG.dl.interface.Connection import *
  17. from BiddingKG.dl.common.Utils import *
  18. from BiddingKG.dl.interface.Connection import getConnection
  19. import BiddingKG.dl.interface.predictor as predictor
  20. import BiddingKG.dl.interface.Preprocessing as Preprocessing
  21. import BiddingKG.dl.interface.getAttributes as getAttributes
  22. import BiddingKG.dl.entityLink.entityLink as entityLink
  23. import BiddingKG.dl.complaint.punish_rule as punish_rule
  24. import json
  25. '''
  26. doc_id = '3537ed94-9c7e-11e8-aed5-44a84246dbba'
  27. conn = psycopg2.connect(dbname="BiddingKG",user="postgres",password="postgres",host="192.168.2.101")
  28. cursor = conn.cursor()
  29. cursor.execute(" select content from articles where id='"+doc_id+"' ")
  30. row = cursor.fetchall()[0]
  31. #text = codecs.open("C:\\Users\\User\\Desktop\\1.html","r",encoding="utf8").read()
  32. #content = segment(tableToText(BeautifulSoup(row[0],"lxml")))
  33. '''
  34. ''''''
  35. codeNamePredict = predictor.CodeNamePredict()
  36. premPredict = predictor.PREMPredict()
  37. epcPredict = predictor.EPCPredict()
  38. roleRulePredict = predictor.RoleRulePredictor()
  39. timePredict = predictor.TimePredictor()
  40. punish = punish_rule.Punish_Extract()
  41. #自定义jsonEncoder
  42. class MyEncoder(json.JSONEncoder):
  43. def default(self, obj):
  44. if isinstance(obj, np.ndarray):
  45. return obj.tolist()
  46. elif isinstance(obj, bytes):
  47. return str(obj, encoding='utf-8')
  48. elif isinstance(obj, (np.float_, np.float16, np.float32,
  49. np.float64)):
  50. return float(obj)
  51. elif isinstance(obj,str):
  52. return obj
  53. return json.JSONEncoder.default(self, obj)
  54. def predict(doc_id,text):
  55. list_articles,list_sentences,list_entitys,_ = Preprocessing.get_preprocessed([[doc_id,text,"","",""]],useselffool=True)
  56. for articles in list_articles:
  57. print(articles.content)
  58. ''''''
  59. codeName = codeNamePredict.predict(list_sentences,list_entitys=list_entitys)
  60. print(codeName)
  61. premPredict.predict(list_sentences,list_entitys)
  62. # roleRulePredict.predict(list_articles,list_sentences, list_entitys,codeName)
  63. print("epcPredict")
  64. epcPredict.predict(list_sentences,list_entitys)
  65. print("entityLink")
  66. timePredict.predict(list_sentences, list_entitys)
  67. print("timePredict")
  68. entityLink.link_entitys(list_entitys)
  69. print("getPREMs")
  70. prem = getAttributes.getPREMs(list_sentences,list_entitys,list_articles)
  71. print("getPREMs")
  72. list_punish_dic = punish.get_punish_extracts(list_articles,list_sentences, list_entitys)
  73. for entitys in list_entitys:
  74. for entity in entitys:
  75. print(entity.entity_text,entity.entity_type,entity.label,entity.values,entity.sentence_index,entity.begin_index,entity.end_index,entity.wordOffset_begin,entity.wordOffset_end)
  76. #print(prem)
  77. return json.dumps(Preprocessing.union_result(Preprocessing.union_result(codeName, prem),list_punish_dic)[0],cls=MyEncoder,sort_keys=True,indent=4,ensure_ascii=False)
  78. def test(name,content):
  79. user = {
  80. "content": content,
  81. "id":name
  82. }
  83. myheaders = {'Content-Type': 'application/json'}
  84. _resp = requests.post("http://192.168.2.101:15015" + '/article_extract', json=user, headers=myheaders, verify=True)
  85. resp_json = _resp.content.decode("utf-8")
  86. print(resp_json)
  87. return resp_json
  88. if __name__=="__main__":
  89. # filename = "比地_52_79929693.html"
  90. #text = codecs.open("C:\\Users\\User\\Desktop\\数据20191014\\"+filename,"r",encoding="utf8").read()
  91. text = codecs.open("C:\\Users\\User\\Desktop\\2.html","r",encoding="utf8").read()
  92. content = str(BeautifulSoup(text).find("div",id="pcontent"))
  93. # df_a = {"html":[]}
  94. # df_a["html"].append(re.sub('\r|\n|\r\n',"",content))
  95. # import pandas as pd
  96. # df = pd.DataFrame(df_a)
  97. # df.to_csv("C:\\Users\\User\\Desktop\\ba.csv")
  98. # print()
  99. #text = codecs.open("C:\\Users\\User\\Desktop\\a.html","r",encoding="utf8").read()
  100. # text = "张家港保税区宏宇建设咨询有限公司受张家港市给排水公司委托,就二次供水泵房浊度仪进行国内组织公开招标采购,欢迎符合条件的供应商参加投标。"
  101. # text = 'a建设资金来源及性质:资本金40%,自筹60%,,xx.=建设资金来源自筹,项目出资比例为100%,as,建设资金来自呜呜呜。'
  102. # text = '张家港保税区宏宇建设咨询有限公司受张家港市给排水公司委托,就二次供水泵房浊度仪进行国内组织公开招标采购,时间:2020-05-26,15:15:00,竞价结束时间:2020-05-26,15:45:00允许延时:是,延时规则:在剩余数量小于最小购买数量时,竞价进'
  103. # text = '''大庆禾工煤炭分质清洁利用项目-临时用电二期工程设备、物资采购中标候选人公示,更多咨询报价请点击:http://bulletin.cebpubservice.com/candidateBulletin/2020-03-31/2678597.html,大庆禾工煤炭分质清洁利用顶目-临时用电二期工程设备、物资釆购中标候选人,(招标编号:XYwZ-20200309-5),公示结束时间:2020年04月03日,、评标情况,标段(包)[001大庆禾工煤嶽分质清洁利用项目-临时用屯二期工程设备、物资采购,中标候选人基本情况,
  104. # 中标候选人第1名:哈尔滨龙网电力设备有限公司,投标报价:19.98万元,质量,合格,工期/交货期/服务期:30天,中标候选人第2名:
  105. # 哈尔滨昊龙电气没备制造有限公司,投标报价:19.87万元,质,量:合格,工期/交货期/服务期:30天,'''
  106. # text = '中标候选人第1名:哈尔滨龙网电力设备有限公司,投标报价:19.98万元,质量,合格,工期/交货期/服务期:30天。\
  107. # 投诉处理公告,投诉人:张三。文章编号:京财采投字(2018)第42号。政府采购项目招标方式:公开招标,联系人:黎明。\
  108. # 建设资金来源及性质:资本金40%,自筹60%,,xx.=建设资金来源自筹,项目出资比例为100%,\
  109. # 二次供水泵房浊度仪进行国内组织公开招标采购,时间:2020-05-26,15:15:00,竞价结束时间:2020-05-26,15:45:00允许延时:是,'
  110. a = time.time()
  111. # text = '''
  112. # ,光大证券统一认证系统服务器硬件设备更新项目中标候选人公示,项目名称:光大证券统一认证系统服务器硬件设备更新项目,招标编号:CG-202011-030-001,公告日期:2020年12月3日,评标日期:2020年11月30日13时32分,评标地点:光大证券集中采购管理平台,推荐中标候选人:上海致为信息技术有限公司,联系人:殷志超,联系电话:021-22169419
  113. # '''
  114. print("start")
  115. print(predict("12",content))
  116. # print(predict("投诉处理公告", text))
  117. #test("12",text)
  118. print("takes",time.time()-a)
  119. pass