| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- 检查节点 2272 的关系
- """
- import sys
- from pathlib import Path
- # 修复 Windows 控制台编码问题
- if sys.platform == "win32":
- import io
- sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
- sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")
- # 添加项目根目录到Python路径
- PROJECT_ROOT = Path(__file__).parent.parent
- sys.path.insert(0, str(PROJECT_ROOT))
- # 设置环境变量以使用 production 配置
- import os
- from app.config.config import config
- if "NEO4J_URI" not in os.environ:
- prod_config = config.get("production")
- if prod_config:
- os.environ["NEO4J_URI"] = prod_config.NEO4J_URI
- os.environ["NEO4J_USER"] = prod_config.NEO4J_USER
- os.environ["NEO4J_PASSWORD"] = prod_config.NEO4J_PASSWORD
- from app.services.neo4j_driver import neo4j_driver
- def check_node_2272():
- """检查节点 2272 的详细信息"""
- print("=" * 60)
- print("检查节点 2272 的关系")
- print("=" * 60)
-
- with neo4j_driver.get_session() as session:
- # 检查节点 2272 的基本信息
- node_query = """
- MATCH (n)
- WHERE id(n) = 2272
- RETURN n, labels(n) as labels
- """
- result = session.run(node_query)
- record = result.single()
-
- if not record:
- print("节点 2272 不存在")
- return
-
- node = record["n"]
- labels = record["labels"]
- props = dict(node)
-
- print(f"节点ID: 2272")
- print(f"节点类型: {labels}")
- print(f"节点属性: {props.get('name_zh', 'N/A')} ({props.get('name_en', 'N/A')})")
- print()
-
- # 检查所有输出关系(OUTPUT)
- output_query = """
- MATCH (n)-[r:OUTPUT]->(target)
- WHERE id(n) = 2272
- RETURN type(r) as rel_type, id(r) as rel_id,
- id(target) as target_id, labels(target) as target_labels,
- target.name_zh as target_name_zh, target.name_en as target_name_en
- """
- output_results = session.run(output_query)
-
- output_count = 0
- print("OUTPUT 关系:")
- for record in output_results:
- output_count += 1
- target_id = record["target_id"]
- target_labels = record["target_labels"]
- target_name_zh = record["target_name_zh"] or "N/A"
- target_name_en = record["target_name_en"] or "N/A"
- rel_id = record["rel_id"]
- print(f" [OUTPUT] 2272 -> {target_id} ({target_labels[0] if target_labels else 'Unknown'}): {target_name_zh} ({target_name_en})")
-
- if output_count == 0:
- print(" 没有找到 OUTPUT 关系")
- print()
-
- # 检查所有输入关系(INPUT,反向)
- input_query = """
- MATCH (source)-[r:INPUT]->(n)
- WHERE id(n) = 2272
- RETURN type(r) as rel_type, id(r) as rel_id,
- id(source) as source_id, labels(source) as source_labels,
- source.name_zh as source_name_zh, source.name_en as source_name_en
- """
- input_results = session.run(input_query)
-
- input_count = 0
- print("INPUT 关系(反向):")
- for record in input_results:
- input_count += 1
- source_id = record["source_id"]
- source_labels = record["source_labels"]
- source_name_zh = record["source_name_zh"] or "N/A"
- source_name_en = record["source_name_en"] or "N/A"
- rel_id = record["rel_id"]
- print(f" [INPUT] {source_id} ({source_labels[0] if source_labels else 'Unknown'}) -> 2272: {source_name_zh} ({source_name_en})")
-
- if input_count == 0:
- print(" 没有找到 INPUT 关系")
- print()
- if __name__ == "__main__":
- check_node_2272()
|