0
我是py2neo的全新品牌,所以我想我會從一個簡單的程序開始。它返回一個TypeError:Index是不可迭代的。無論如何,我試圖添加一組節點,然後爲它們創建關係,同時避免重複。不知道我做錯了什麼。py2neo中的索引錯誤,Neo4j
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)
感謝薛明,很有幫助!我也發現你在幻燈片上的演示文稿也很有用 –