我是 py2neo 的新手,所以我想我会从一个简单的程序开始。它返回一个 TypeError: Index is not iterable。无论如何,我正在尝试添加一组节点,然后为它们创建关系,同时避免重复。不知道我做错了什么。
from py2neo import neo4j, cypher
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
happy = "happy"
glad = "glad"
mad = "mad"
irate = "irate"
love = "love"
wordindex = graph_db.get_or_create_index(neo4j.Node, "word")
for node in wordindex:
wordindex.add("word", node["word"], node)
def createnodes(a, b, c, d, e):
nodes = wordindex.get_or_create(
{"word": (a)},
{"word": (b)},
{"word": (c)},
{"word": (d)},
{"word": (e)},
)
def createrel(a, b, c, d, e):
rels = wordindex.get_or_create(
((a), "is", (b)),
((c), "is", (d)),
((e), "is", (a)),
)
createnodes(happy, glad, mad, irate, love)
createrel(happy, glad, mad, irate, love)