testMoney.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #coding:utf8
  2. import psycopg2
  3. import codecs
  4. import re
  5. def havelook():
  6. conn = psycopg2.connect(dbname="BiddingKM_test_10000",user="postgres",password="postgres",host="192.168.2.101")
  7. cursor = conn.cursor()
  8. sql = " select A.entity_text,A.begin_index,A.end_index,B.tokens from entity_mention A,sentences B where A.entity_type='money' and A.doc_id=B.doc_id and A.sentence_index=B.sentence_index "
  9. cursor.execute(sql)
  10. rows = cursor.fetchmany(1000)
  11. MAX_NUM = 7
  12. with codecs.open("look.txt", "w", encoding="utf8") as f:
  13. while(rows):
  14. for row in rows:
  15. entity_text = row[0]
  16. begin_index = row[1]
  17. end_index = row[2]
  18. tokens = row[3]
  19. if begin_index>MAX_NUM:
  20. begin = begin_index-MAX_NUM
  21. else:
  22. begin = 0
  23. if end_index+MAX_NUM<len(tokens):
  24. end = end_index+MAX_NUM+1
  25. else:
  26. end = -1
  27. f.write("".join(tokens[begin:begin_index]))
  28. f.write("\t")
  29. f.write(entity_text)
  30. f.write("\t")
  31. f.write("".join(tokens[begin_index:end_index+1]))
  32. f.write("\t")
  33. f.write("".join(tokens[end_index+1:end]))
  34. f.write("\n")
  35. rows = cursor.fetchmany(1000)
  36. f.flush()
  37. f.close()
  38. conn.close()
  39. def moneySupervice():
  40. text = "地址:全椒县襄河镇港口路96号,投标报价:"
  41. pattern_tenderee = re.compile("报价上限|限价|造价|控制总?价|预算|概算|(?:造?价|投资|规模)预?估?算|预?估算?(?:造?价|投资|规模)|(?:总|项目|计划)(?:[估预概]算|投资)|(?:投资|采购)(?:单价|总)?(?:额|金额)+")
  42. pattern_wintenderer = re.compile("(?:中标|成交)(?:价|金额)|报价")
  43. if re.search(pattern_tenderee,text) is not None:
  44. print(0)
  45. elif re.search(pattern_wintenderer,text) is not None:
  46. print(1)
  47. else:
  48. print(2)
  49. if __name__=="__main__":
  50. moneySupervice()