re_ratio.py 1.9 KB

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