re_ratio.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import re
  2. # ratio = '([((]?(上浮|下浮)(率|)(报价|)([((]?%[))]?|)[))]?[:: ,]{0,3}[0-9]+.?[0-9]*[((]?%?[))]?)'
  3. ratio = '(([((]?(上浮|下浮)费?(率|)(报价|)[))]?|([中投]标|报价|总价)费率|折扣率)([((]?%[))]?|)[为:: ,]{0,3}[0-9]+\.?[0-9]{0,3}[((]?%?[))]?)'
  4. # ratio = re.compile('(([((]?(上浮|下浮)费?(率|)(报价|)[))]?|([中投]标|报价|总价)费率|折扣率)([((]?%[))]?|)[为:: ,]{0,3}[0-9]+\.?[0-9]{0,3}[((]?%?[))]?)')
  5. # 基准利率上浮率):大写:百分之叁拾点零零,小写:30.00%,
  6. # 基准利率上浮率:百分之三十(30%)
  7. # 租金上浮率
  8. # 上浮率活期20%
  9. # 上浮率:活期20%、一年定期35%
  10. # 下浮率报价0.5%
  11. def re_standard_ratio(_str):
  12. reg_standard = "(?P<value>" + ratio + ")"
  13. match = re.finditer(reg_standard, _str)
  14. ratio_list = []
  15. if match:
  16. for m in match:
  17. m_dict = m.groupdict()
  18. m_span = m.span()
  19. keyword_index = [m_span[0], m_span[1]]
  20. keyword = m_dict.get("value")
  21. ratio_list.append([keyword, keyword_index])
  22. return ratio_list
  23. def re_ratio(text):
  24. # 查找符合标准形式的 总价
  25. ratio_list = re_standard_ratio(text)
  26. return ratio_list
  27. def extract_ratio(text):
  28. result_list = []
  29. total_money_list = re_ratio(text)
  30. if total_money_list:
  31. for word, text_index in total_money_list:
  32. d = {"body": word, "begin_index": text_index[0],
  33. "end_index": text_index[1]}
  34. result_list.append(d)
  35. return result_list
  36. def test_str():
  37. s = '政府采购项目招标方式:公开招标,联系人:黎明。代理机构地址:广州市天河区'
  38. s = '年利率较基准利率的上浮率(%): 30 活期存款下浮率:0.455% 协定存的下浮率,(1-下浮率)' \
  39. ' 上浮率.... 上浮率30(%) (下浮率%):43 下浮率报价0.5%'
  40. print(extract_ratio(s))
  41. def test_html():
  42. html_path = "C:/Users/Administrator/Desktop/3.html"
  43. with open(html_path, "r") as f:
  44. s = f.read()
  45. print(extract_ratio(s))
  46. if __name__ == "__main__":
  47. # extract_bidway(s)
  48. # path = "D:\\BIDI_DOC\\比地_文档\\比率_result.csv"
  49. test_str()
  50. # test_html(path)
  51. pass