handle_person.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. 关键点检索工具 - 根据输入的点在图数据库中查找所有关联的点
  3. 用于 Agent 执行时自主调取关联关键点数据。
  4. """
  5. import json
  6. import os
  7. from pathlib import Path
  8. from typing import Any, Dict, Optional
  9. # 完整图数据库文件路径(包含 edges)
  10. GRAPH_FULL_DATA_PATH = os.getenv(
  11. "GRAPH_FULL_DATA_PATH",
  12. # str(Path(__file__).parent.parent / "data/library/item_graph/item_graph_full_all_levels.json")
  13. str(Path(__file__).parent.parent / "data/家有大志/topic_point_data/point_classification_results.json")
  14. )
  15. # 缓存图数据,避免重复加载
  16. _graph_full_cache: Optional[Dict[str, Any]] = None
  17. def _load_graph_full() -> Dict[str, Any]:
  18. """加载完整图数据(带缓存,包含 edges)"""
  19. global _graph_full_cache
  20. if _graph_full_cache is None:
  21. with open(GRAPH_FULL_DATA_PATH, 'r', encoding='utf-8') as f:
  22. _graph_full_cache = json.load(f)
  23. return _graph_full_cache
  24. if __name__ == "__main__":
  25. graph = _load_graph_full()
  26. data = {}
  27. for post, value1 in graph.items():
  28. for point_type, points_list in value1.items():
  29. for point_item in points_list:
  30. for dimension, dimension_list in point_item.items():
  31. if dimension in ["实质", "形式", "意图"] and isinstance(dimension_list, list):
  32. for point in dimension_list:
  33. name = point.get("名称")
  34. if name:
  35. data[name] = {
  36. "名称": name,
  37. "类型": point_type,
  38. "维度": dimension
  39. }
  40. # 输出到文件
  41. output_path = Path(__file__).parent.parent / "data/家有大志/topic_point_data/point_classification_results_trans.json"
  42. with open(output_path, 'w', encoding='utf-8') as f:
  43. json.dump(data, f, ensure_ascii=False, indent=2)
  44. print(f"数据已输出到: {output_path}")