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

 1、安裝驅動

pip install py2neo

2、插入數據

# -*- coding: UTF-8 -*-

from py2neo import Graph, Node, Relationship

# 連接neo4j數據庫,輸入地址、用戶名、密碼
graph = Graph('http://192.168.25.223:7474', 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結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章