You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.4 KiB
61 lines
2.4 KiB
from py2neo import Graph
|
|
import json
|
|
from Config import *
|
|
|
|
def query_all_questions():
|
|
# Neo4j连接配置
|
|
neo4j_config = {
|
|
"uri": NEO4J_URI, # 从Config导入
|
|
"auth": NEO4J_AUTH # 从Config导入
|
|
}
|
|
|
|
# 初始化图数据库连接
|
|
graph = Graph(**neo4j_config)
|
|
|
|
try:
|
|
# 获取所有试题ID
|
|
question_ids = graph.run(
|
|
"MATCH (q:Question) RETURN q.id AS question_id"
|
|
).data()
|
|
|
|
results = []
|
|
|
|
# 遍历每个试题
|
|
for record in question_ids:
|
|
qid = record['question_id']
|
|
# 修改查询部分
|
|
data = graph.run("""
|
|
MATCH (q:Question {id: $qid})
|
|
OPTIONAL MATCH (q)-[:REQUIRES_KNOWLEDGE]->(kp:KnowledgePoint)
|
|
OPTIONAL MATCH (q)-[:DEVELOPS_LITERACY]->(lp:LiteracyNode)
|
|
RETURN
|
|
q.content AS content,
|
|
collect(DISTINCT {id: kp.id, name: kp.name}) AS knowledge_points,
|
|
collect(DISTINCT {id: lp.value, title: lp.title}) AS literacy_points
|
|
""", qid=qid).data()
|
|
|
|
if data:
|
|
result = {
|
|
"question_id": qid,
|
|
"content": data[0]['content'],
|
|
"knowledge_points": data[0]['knowledge_points'],
|
|
"literacy_points": data[0]['literacy_points']
|
|
}
|
|
results.append(result)
|
|
|
|
# 增强版输出展示
|
|
print(f"\n{'=' * 40} 题目详情 {'=' * 40}")
|
|
print(f"📚 试题ID: {qid}")
|
|
print(f"📝 内容全文: {result['content']}") # 新增完整内容输出
|
|
print(f"🔍 内容摘要: {result['content'][:50]}...") # 保留摘要显示
|
|
print(f"🧠 知识点: {[kp['name'] for kp in result['knowledge_points']]}")
|
|
print(f"🆔 知识点ID: {[kp['id'] for kp in result['knowledge_points']]}")
|
|
print(f"🌟 素养点: {[lp['title'] for lp in result['literacy_points']]}")
|
|
print(f"🔢 素养点ID: {[lp['id'] for lp in result['literacy_points']]}")
|
|
print('=' * 90)
|
|
except Exception as e:
|
|
print(f"❌ 查询失败: {str(e)}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
query_all_questions() |