赞
踩
我尝试以下,并得到的结果我想你想:
from py2neo import neo4j, node, rel
graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
alice, = graph.create(node(name="Alice")) # Comma unpacks length-1 tuple.
bob, = graph.create(node(name="Bob"))
carol, = graph.create(node(name="Carol Smith"))
dev, = graph.create(node(name="Dev"))
graph.create(rel(alice, "KNOWS", bob))
graph.create(rel(dev, "KNOWS", carol))
graph.create(rel(alice, "KNOWS", carol))
My图表现在看起来像这样在浏览器:
或者,您可以创建图形在一个graph.create()声明中:
from py2neo import neo4j, node, rel
graph = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
graph.create(
node(name="Alice"), #0
node(name="Bob"), #1
node(name="Carol Smith"), #2
node(name="Dev"), #3
rel(0, "KNOWS", 1),
rel(3, "KNOWS", 2),
rel(0, "KNOWS", 2)
)
和输出是一样的。希望这可以帮助。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。