neo4j desktop的使用(python連接並創建一個小示例)


一、neo4j的連接方式

 內部導入數據可以使用HTTP服務(端口7474),外部訪問使用瀏覽器(端口7687)

 

二、neo4j基本的cypher語句

match 匹配圖模式。這是從圖中獲取數據最常見的方法

where 不是獨立的語句,而是match、optinal match和with的一部分,用於給模式添加約束或者過濾傳遞給with的中間結果

return 定義返回的結果

create(和 delete) 創建(和刪除)節點、關系

set(和remove) 使用set設置屬性值和給節點添加標簽,使用remove移除它們

merge 匹配已經存在的或創建新節點和模式,這對於有唯一性約束的時候非常有用

 

三、使用py2neo創建一個示例圖

from py2neo import Node, Graph, Relationship, NodeMatcher


# 創建連接
graph = Graph('http://127.0.0.1:7474', name="test", password="23615")

# 創建節點
node3 = Node('animal', name='cat')
node4 = Node('animal', name='dog')
node2 = Node('Person', name='Alice')
node1 = Node('Person', name='Bob')

# 創建關系
r1 = Relationship(node2, 'know', node1)
r2 = Relationship(node1, 'know', node3)
r3 = Relationship(node2, 'has', node3)
r4 = Relationship(node4, 'has', node2)

# 將節點和關系在圖中創建
graph.create(node1)
graph.create(node2)
graph.create(node3)
graph.create(node4)
graph.create(r1)
graph.create(r2)
graph.create(r3)
graph.create(r4)

# 查詢某節點,一般在腳本中很少出現
matcher = NodeMatcher(graph)
print(list(matcher.match('animal')))

 

參考:

《neo4j權威指南》


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM