test_graph.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import sys,os
  2. current_path = os.getcwd()
  3. sys.path.append(current_path)
  4. from libs.graph_helper import GraphHelper
  5. graph_helper = GraphHelper()
  6. user_input = "腹痛 发热 腹泻"
  7. try:
  8. keywords = user_input.split(" ")
  9. start_nodes = []
  10. for keyword in keywords:
  11. results = graph_helper.node_search(
  12. keyword, limit=10, node_type="word"
  13. )
  14. for item in results:
  15. if item['score']>1.9:
  16. start_nodes.append(item['id'])
  17. print("cdss start from :", start_nodes)
  18. result = graph_helper.cdss_travel(start_nodes,max_hops=2)
  19. for item in result["details"]:
  20. name, data = item
  21. print(f"{name} {data['score'] *100:.2f} %")
  22. for disease in data["diseases"]:
  23. print(f"\t疾病:{disease[0]} ")
  24. for check in data["checks"]:
  25. print(f"\t检查:{check[0]} ")
  26. for drug in data["drugs"]:
  27. print(f"\t药品:{drug[0]} ")
  28. print("最终推荐的检查和药品如下:")
  29. for item in result["checks"][:5]:
  30. print(f"\t检查:{item[0]} {item[1]['count'] / result["total_checks"] * 100:.2f} %")
  31. for item in result["drugs"][:5]:
  32. print(f"\t药品:{item[0]} {item[1]['count'] / result["total_drugs"] * 100:.2f} %")
  33. #print(results)
  34. # results = graph_helper.node_search(
  35. # keyword,
  36. # limit=limit,
  37. # node_type=node_type,
  38. # min_degree=min_degree
  39. # )
  40. except Exception as e:
  41. raise e