| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- """
- 关键点检索工具 - 根据输入的点在图数据库中查找所有关联的点
- 用于 Agent 执行时自主调取关联关键点数据。
- """
- import json
- import os
- from pathlib import Path
- from typing import Any, Dict, Optional
- # 完整图数据库文件路径(包含 edges)
- GRAPH_FULL_DATA_PATH = os.getenv(
- "GRAPH_FULL_DATA_PATH",
- # str(Path(__file__).parent.parent / "data/library/item_graph/item_graph_full_all_levels.json")
- str(Path(__file__).parent.parent / "data/家有大志/topic_point_data/point_classification_results.json")
- )
- # 缓存图数据,避免重复加载
- _graph_full_cache: Optional[Dict[str, Any]] = None
- def _load_graph_full() -> Dict[str, Any]:
- """加载完整图数据(带缓存,包含 edges)"""
- global _graph_full_cache
- if _graph_full_cache is None:
- with open(GRAPH_FULL_DATA_PATH, 'r', encoding='utf-8') as f:
- _graph_full_cache = json.load(f)
- return _graph_full_cache
- if __name__ == "__main__":
- graph = _load_graph_full()
- data = {}
- for post, value1 in graph.items():
- for point_type, points_list in value1.items():
- for point_item in points_list:
- for dimension, dimension_list in point_item.items():
- if dimension in ["实质", "形式", "意图"] and isinstance(dimension_list, list):
- for point in dimension_list:
- name = point.get("名称")
- if name:
- data[name] = {
- "名称": name,
- "类型": point_type,
- "维度": dimension
- }
- # 输出到文件
- output_path = Path(__file__).parent.parent / "data/家有大志/topic_point_data/point_classification_results_trans.json"
- with open(output_path, 'w', encoding='utf-8') as f:
- json.dump(data, f, ensure_ascii=False, indent=2)
- print(f"数据已输出到: {output_path}")
-
|