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

相关推荐
xxyy8883 小时前
关于labelimg安装后在标注过程中闪退和死机的问题处理
开发语言·python
卷Java4 小时前
上下文压缩
开发语言·windows·python
AI技术增长4 小时前
Pytorch图像去噪实战(十二):DDPM图像去噪完整训练流程,构建可复现扩散模型工程
pytorch·python·深度学习
EvenBoy4 小时前
IDEA中使用CodeX
java·ide·intellij-idea
时光之源4 小时前
Visual Studio | Marketplace创建发布者(Create Publisher)时无法创建的问题解决方案
ide·vscode·visual studio·plugin·cursor
本地化文档4 小时前
setuptools-docs-l10n
python·github·gitcode
梦想不只是梦与想4 小时前
Python 属性访问的 MRO 规则
python·mro规则
Ulyanov4 小时前
基于 Python 的三维动态导弹攻防演示系统设计与实现:从架构到实战的深度剖析
开发语言·python·qt·架构·雷达电子对抗
Leinwin4 小时前
Claude 四月宕机七次:从一次事故看企业级 AI 部署的容灾设计
后端·python·flask
棉猴4 小时前
Python海龟绘图之绘制文本
javascript·python·html·write·turtle·海龟绘图·输出文本