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

相关推荐
阿郎_20112 小时前
python自动化脚本-简化留言
python·自动化
人邮异步社区2 小时前
推荐几本学习计算机语言的书
java·c语言·c++·python·学习·golang
gfdgd xi6 小时前
GXDE 内核管理器 1.0.1——修复bug、支持loong64
android·linux·运维·python·ubuntu·bug
递归不收敛7 小时前
专属虚拟环境:Hugging Face数据集批量下载(无登录+国内加速)完整指南
人工智能·笔记·git·python·学习·pycharm
我是小邵7 小时前
主流数据分析工具全景对比:Excel / Python / R / Power BI / Tableau / Qlik / Snowflake
python·数据分析·excel
Yolo566Q8 小时前
Python驱动的无人机生态三维建模与碳储/生物量/LULC估算全流程实战技术
开发语言·python·无人机
新手村领路人8 小时前
关于jupyter Notebook
ide·python·jupyter
生莫甲鲁浪戴8 小时前
Android Studio新手开发第三十五天
android·ide·android studio
林恒smileZAZ9 小时前
移动端h5适配方案
人工智能·python·tensorflow
含目的基因的质粒9 小时前
Python异常、模块、包
服务器·开发语言·python