neo4j初識筆記(一)(python操作篇)

2021-10-06 20:05:48 字數 1835 閱讀 3321

1、安裝驅動

pip install py2neo

2、插入資料

# -*- coding: utf-8 -*-

from py2neo import graph, node, relationship

# 連線neo4j資料庫,輸入位址、使用者名稱、密碼

graph = graph('', username='neo4j', password='123456')

def create_date():

# 建立結點

ts = node('person', name='唐僧')

pt = node('person', name='菩提祖師')

swk = node('person', name='孫悟空')

zbj = node('person', name='豬八戒')

ss = node('person', name='沙僧')

graph.create(ts)

graph.create(pt)

graph.create(swk)

graph.create(zbj)

graph.create(ss)

jgb = node('weapon', name='如意金箍棒')

dp = node('weapon', name='九齒釘耙')

xmc = node('weapon', name='降魔杵')

graph.create(jgb)

graph.create(dp)

graph.create(xmc)

# 建立關係

r1 = relationship(ts, '大徒弟', swk)

r2 = relationship(ts, '二徒弟', zbj)

r3 = relationship(ts, '三徒弟', ss)

r4 = relationship(ts, '徒弟', swk)

r5 = relationship(ts, '徒弟', zbj)

r6 = relationship(ts, '徒弟', ss)

r7 = relationship(swk, '**', ts)

r8 = relationship(zbj, '**', ts)

r9 = relationship(ss, '**', ts)

r10 = relationship(swk, '**', jgb)

r11 = relationship(zbj, '**', dp)

r12 = relationship(ss, '**', xmc)

r13 = relationship(swk, '**', pt)

graph.create(r1)

graph.create(r2)

graph.create(r3)

graph.create(r4)

graph.create(r5)

graph.create(r6)

graph.create(r7)

graph.create(r8)

graph.create(r9)

graph.create(r10)

graph.create(r11)

graph.create(r12)

graph.create(r13)

if __name__ == '__main__':

create_date()

# graph.delete_all()

3、neo4j結果

neo4j初識筆記(一)

1 建立最簡單的唐僧三徒弟和 的圖譜 create ts person pt person swk person zbj person ss person jgb weapon dp weapon xmc weapon ts 大徒弟 swk ts 二徒弟 zbj ts 三徒弟 ss ts 徒弟 sw...

neo4j學習筆記(一)

boss說,你去學一下neo4j 於是我來了 neo4j學習筆記 二 python介面 查詢 neo4j學習筆記 三 python介面 建立刪除結點和關係 neo4j是乙個很好玩的圖資料庫。安裝過程很簡單,不過我沒裝,我用的是伺服器上裝好的,所以不寫了。由於在伺服器上,所以要先配置一下遠端連線。首先...

Neo4j學習筆記

neo4j學習筆記 一.基本知識 1.1 node syntax 節點語法 matrix movie matrix movie matrix movie matrix movie 1 代表乙個節點uncharacterized node 2 matrix 新增了乙個變數為matrix的節點。3 mo...