我正在尝试使用Py2neo连接到Neo4j实例
from py2neo import Graph
import re, string
# default uri for local Neo4j instance
graphdb = Graph('http://neo4j:neo4j@localhost:7474/db/data')
# parameterized Cypher query for data insertion
# t is a query parameter. a list with two elements: [word1, word2]
INSERT_QUERY = '''
FOREACH (t IN {wordPairs} |
MERGE (w0:Word {word: t[0]})
MERGE (w1:Word {word: t[1]})
CREATE (w0)-[:NEXT_WORD]->(w1)
)
'''
并加载数据,然后在加载的数据上应用一些密码命令
# load our text corpus into Neo4j
def loadFile():
tx = graphdb.cypher.begin()
with open('data/ceeaus.dat', encoding='ISO-8859-1') as f:
count = 0
for l in f:
params = {'wordPairs': arrifySentence(l)}
tx.append(INSERT_QUERY, params)
tx.process()
count += 1
# process in batches of 100 insertion queries
if count > 100:
tx.commit()
tx = graphdb.cypher.begin()
count = 0
f.close()
tx.commit()
现在,问题在于vscode无法将cypher识别为Graph的成员,或者不能将graphdb识别为Graph实例。
问题出在此行graphdb.cypher.begin()
我尝试阅读docs for cypher,发现Graph类中存在Cypher成员;以及py2neo密码中的begin函数。
我正在使用py2neo v 4.3和python 3.7和neo4j v 1.2.4预先感谢。
py2neo 4.3
,因此需要使用v4 API。您正在查看v2文档。在py2neo v4中,Graph没有cypher
方法。相反,您可能想使用run
方法。