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

相关推荐
chengxuyuan6666611 分钟前
python基础语句整理
java·windows·python
清弦墨客37 分钟前
【蓝桥杯】43691.拉马车
python·蓝桥杯·程序算法
null_equals1 小时前
你还在用idea吗
java·ide·intellij-idea
我想学LINUX2 小时前
【2024年华为OD机试】(C/D卷,200分)- 5G网络建设 (JavaScript&Java & Python&C/C++)
java·c语言·javascript·网络·python·5g·华为od
chengxuyuan666662 小时前
JAVA基础语句整理
java·开发语言·python
别人家的孩子3802 小时前
EE213 Lab2 hspice simulation R/C-V Characteristics
开发语言·python
蹦蹦跳跳真可爱5892 小时前
Python----Python高级(正则表达式:语法规则,re库)
python·正则表达式
大哥喝阔落2 小时前
图片专栏——曝光度调整相关
人工智能·python·opencv
Channing Lewis2 小时前
vscode如何选用不同的python的解释器
ide·vscode·python