Можно ли использовать элементы списка для свойств узла графа? - PullRequest
0 голосов
/ 11 мая 2018

Я все еще новичок в использовании Neo4j и Python.Я хочу знать, возможно ли использовать элементы списка в качестве свойств узла графа в Python и Neo4j.

Я попытался создать узел рецепта, но я получаю ошибку в переменной '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 голосов
/ 11 мая 2018

Cypher-запросы не используют = для присвоения свойства, но :,

createNode = tx.run("CREATE (theNode:Recipe {recipeName: {recipeName}, serveTime: {serveTime}, mainIngrediant: {mainIngrediant}, givenBy: {givenBy}"
 ,recipeName=recipeName,serveTime=serveTime,mainIngrediant=mainIngrediant,givenBy=givenBy)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...