列表的元素可以用于图节点的属性吗?

时间:2018-05-11 11:07:19

标签: python neo4j

我还是使用Neo4j和Python的新手。我想知道是否可以在Python和Neo4j中使用列表元素作为图形节点的属性。

我尝试创建一个Recipe节点但是在'createNode'变量中出现错误。我究竟做错了什么?

这是我的代码:

# a list containing a list of recipes and their respective information 
recipeList = [['Mac and Cheese', 'Anytime', 'Macaroni', 'Terry'], ['Chicken Curry', 'Supper', 'Chicken', 'Anne']]

def print_recipes(self,aList):
    with self._driver.session() as session:
       recipes = session.write_transaction(self.createRecipeNodes,aList)
            print(recipes)


def createRecipeNodes(tx, aRecipeList):

    for allRecipes in aRecipeList:
        #for recipe in allRecipes:
        recipeName = allRecipes[0]
        serveTime = allRecipes[1]
        mainIngrediant = allRecipes[2]
        givenBy =  allRecipes[3]

        createNode = tx.run("CREATE (theNode:Recipe {recipeName = {recipeName}, serveTime = {serveTime}, mainIngrediant = {mainIngrediant}, givenBy = {givenBy}" ,recipeName=recipeName,serveTime=serveTime,mainIngrediant=mainIngrediant,givenBy=givenBy)

我得到的错误是:

neo4j.exceptions.CypherSyntaxError: Invalid input '=': expected whitespace, comment, ':' or '}' (line 1, column 36 (offset: 35)) "CREATE (theNode:Recipe {recipeName = {recipeName}, serveTime = {serveTime}, mainIngrediant = {mainIngrediant}, givenBy = {givenBy}

提前谢谢!

1 个答案:

答案 0 :(得分:0)

Cypher查询不使用=进行属性分配,而是:

createNode = tx.run("CREATE (theNode:Recipe {recipeName: {recipeName}, serveTime: {serveTime}, mainIngrediant: {mainIngrediant}, givenBy: {givenBy}"
 ,recipeName=recipeName,serveTime=serveTime,mainIngrediant=mainIngrediant,givenBy=givenBy)