什么是正确的Cypher语法?

时间:2018-03-09 02:00:43

标签: python neo4j cypher py2neo

我参考Neo4j create nodes and relationships from pandas dataframe with py2neo并在下面编写代码。 但是我得到了py2neo.database.status.CypherSyntaxError。请验证以下是正确的方法,让我知道什么是正确的Cypher语法。

我的代码:

for line in reader:
    print(line['word'], line['similar_word'], line['probability'] )
    w1 = Node("Word", name = line['word'])
    w2 = Node("Word", name = line['similar_word'])
    graph.merge(w1|w2)
    graph.run('''
      MATCH (a:Paper),(b:Word)
      WHERE (a.name = 'Paper10' AND b.name = {$word1})
      CREATE (a)<-[o:ORIGINAL]-(b)
      ''', parameters = {'word1':line['word']})

py2neo.database.status.CypherSyntaxError:

Traceback (most recent call last):   File "test.py", line 24, in <module>
    ''', parameters = {'word1':line['word']})   File "/root/miniconda3/lib/python3.6/site-packages/py2neo/database/__init__.py", line 731, in run
    return self.begin(autocommit=True).run(statement, parameters, **kwparameters)   File "/root/miniconda3/lib/python3.6/site-packages/py2neo/database/__init__.py", line 1277, in run
    self.finish()   File "/root/miniconda3/lib/python3.6/site-packages/py2neo/database/__init__.py", line 1296, in finish
    self._sync()   File "/root/miniconda3/lib/python3.6/site-packages/py2neo/database/__init__.py", line 1286, in _sync
    connection.fetch()   File "/root/miniconda3/lib/python3.6/site-packages/py2neo/packages/neo4j/v1/bolt.py", line 344, in fetch
    handler(*fields)   File "/root/miniconda3/lib/python3.6/site-packages/py2neo/database/__init__.py", line 961, in on_failure
    raise GraphError.hydrate(metadata) py2neo.database.status.CypherSyntaxError: Invalid input '$': expected whitespace, an identifier, UnsignedDecimalInteger, a property key name or '}' (line 3, column 53 (offset: 78)) "      WHERE (a.name = 'Paper10' AND b.name = {$word1})"

1 个答案:

答案 0 :(得分:1)

要引用参数,您可以使用$语法或{},但不能同时使用两者。只需$word1即可尝试。