| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- """
- 关键点检索工具 - 根据输入的点在图数据库中查找所有关联的点
- 用于 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/library/item_graph/item_graph_full_max.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 class_path, value in graph.items():
- if class_path == '_post_ids_index':
- continue
- meta = value.get("meta", {})
- point_type = meta.get("point_type")
- dimension = meta.get("dimension")
- elements = meta.get("elements", {})
- if not point_type or not dimension:
- continue
- for element in elements.keys():
- data[point_type][dimension][element] = class_path
- # 输出到文件
- output_path = Path(__file__).parent.parent / "data/library/item_graph/item_graph_full_max_map.json"
- with open(output_path, 'w', encoding='utf-8') as f:
- json.dump(data, f, ensure_ascii=False, indent=2)
- print(f"数据已输出到: {output_path}")
-
|