pycharm链接neo4j数据库(简单)

1.安装pycharm

2.安装库

pip install py2neo -i https://pypi.tuna.tsinghua.edu.cn/simple

3.代码试运行

复制代码
from py2neo import Graph, Node, Relationship

# 连接到Neo4j数据库,使用Bolt协议
graph = Graph("bolt://localhost:7687", auth=("neo4j", "password"))

# 创建根节点
greedy_algorithm = Node("GreedyAlgorithm", name="Greedy Algorithm")

# 创建贪心算法的基本概念节点
basic_concept = Node("BasicConcept", name="基本概念")
graph.create(greedy_algorithm)
graph.create(basic_concept)

# 创建贪心算法的特点节点
features = Node("Features", name="特点")
graph.create(features)

# 创建贪心算法适用场景节点
app_scenario = Node("AppScenario", name="适用场景")
graph.create(app_scenario)

# 创建贪心算法示例节点
examples = Node("Examples", name="算法示例")
graph.create(examples)

# 创建贪心算法在优化问题中的应用节点
optimization = Node("Optimization", name="优化问题")
graph.create(optimization)

# 创建与其他算法的比较节点
comparison = Node("Comparison", name="与其他算法的比较")
graph.create(comparison)

# 创建局限性节点
limitations = Node("Limitations", name="局限性")
graph.create(limitations)

# 创建关系
graph.create(Relationship(greedy_algorithm, "INCLUDES", basic_concept))
graph.create(Relationship(greedy_algorithm, "INCLUDES", features))
graph.create(Relationship(greedy_algorithm, "INCLUDES", app_scenario))
graph.create(Relationship(greedy_algorithm, "INCLUDES", examples))
graph.create(Relationship(greedy_algorithm, "INCLUDES", optimization))
graph.create(Relationship(greedy_algorithm, "INCLUDES", comparison))
graph.create(Relationship(greedy_algorithm, "INCLUDES", limitations))

# 查询并打印结果
results = graph.run("MATCH (a:GreedyAlgorithm)-[r]->(b) RETURN a, r, b")
for record in results:
    print(record)

4.打开浏览器中的neo4j

相关推荐
BaoshengTT38 分钟前
2026年双流区汽车贴膜种类及挑选要点保圣威固7V不凡门店
python
zhiSiBuYu05171 小时前
Flask 请求与响应新手实战指南
后端·python·flask
优信电子1 小时前
Raspberry Pi Pico(RP2040)快速入门:Arduino IDE环境搭建与第一个程序
ide
宸津-代码粉碎机1 小时前
告别手动Jar部署!生产级无损热部署方案,彻底解决OOM与更新失效问题
java·大数据·开发语言·人工智能·python
米码收割机1 小时前
【移动】线上购物移动端网站(源码+文档)【独一无二】
java·开发语言·前端·python·django
未知违规用户1 小时前
大模型项目: 学习FastAPI 服务器开发
服务器·人工智能·python·学习·fastapi
想会飞的蒲公英1 小时前
PyTorch reshape、view、transpose、广播到底怎么选?
人工智能·pytorch·python
卷无止境1 小时前
Python装饰器:一层糖衣包裹的函数魔法
后端·python
xlrqx1 小时前
长治家电清洗培训基地如何挑选及行业基本培训标准科普
大数据·python
无敌秋1 小时前
python/c++/java上云
java·c++·python