【发布时间】:2020-03-06 14:33:28
【问题描述】:
我正在尝试使用 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 em>图表实例。
问题出在这一行graphdb.cypher.begin()
我尝试阅读docs for cypher 并发现Graph 类中存在Cypher 成员;以及 py2neo 密码中的 begin 函数。
我正在使用 py2neo v 4.3 和 python 3.7 和 neo4j v 1.2.4 提前致谢。
【问题讨论】:
标签: neo4j graphql python-3.7