py2no 2.x, "Local entity is not bound to a remote entity"
py2neo 2.x, "Local entity is not bound to a remote entity"
将 Neo4j 和 py2neo 更新到最新版本(分别为 2.2.3 和 2.0.7)时,我遇到了一些导入脚本的问题。
例如这里,只是一些代码。
graph = py2neo.Graph()
graph.bind("http://localhost:7474/db/data/")
batch = py2neo.batch.PushBatch(graph)
pp.pprint(batch)
relationshipmap={}
def create_go_term(line):
if(line[6]=='1'):
relationshipmap[line[0]]=line[1]
goid = line[0]
goacc = line[3]
gotype = line[2]
goname = line[1]
term = py2neo.Node.cast( {
"id": goid, "acc": goacc, "term_type": gotype, "name": goname
})
term.labels.add("GO_TERM")
pp.pprint(term)
term.push()
#batch.append( term )
return True
logging.info('creating terms')
reader = csv.reader(open(opts.termfile),delimiter="\t")
iter = 0
for row in reader:
create_go_term(row)
iter = iter + 1
if ( iter > 5000 ):
# batch.push()
iter = 0
# batch.push()
当使用批处理或不使用批处理直接推送时,出现此错误:
py2neo.error.BindError: Local entity is not bound to a remote entity
我做错了什么?
谢谢!
我认为您首先必须 create
节点,然后才能添加标签并使用 push
:
term = py2neo.Node.cast( {
"id": goid, "acc": goacc, "term_type": gotype, "name": goname
})
graph.create(term) # now the node should be bound to a remote entity
term.labels.add("GO_TERM")
term.push()
或者,您可以创建带有标签的节点:
term = Node("GO_TERM", id=goid, acc=goacc, ...)
graph.create(term)
将 Neo4j 和 py2neo 更新到最新版本(分别为 2.2.3 和 2.0.7)时,我遇到了一些导入脚本的问题。
例如这里,只是一些代码。
graph = py2neo.Graph()
graph.bind("http://localhost:7474/db/data/")
batch = py2neo.batch.PushBatch(graph)
pp.pprint(batch)
relationshipmap={}
def create_go_term(line):
if(line[6]=='1'):
relationshipmap[line[0]]=line[1]
goid = line[0]
goacc = line[3]
gotype = line[2]
goname = line[1]
term = py2neo.Node.cast( {
"id": goid, "acc": goacc, "term_type": gotype, "name": goname
})
term.labels.add("GO_TERM")
pp.pprint(term)
term.push()
#batch.append( term )
return True
logging.info('creating terms')
reader = csv.reader(open(opts.termfile),delimiter="\t")
iter = 0
for row in reader:
create_go_term(row)
iter = iter + 1
if ( iter > 5000 ):
# batch.push()
iter = 0
# batch.push()
当使用批处理或不使用批处理直接推送时,出现此错误:
py2neo.error.BindError: Local entity is not bound to a remote entity
我做错了什么?
谢谢!
我认为您首先必须 create
节点,然后才能添加标签并使用 push
:
term = py2neo.Node.cast( {
"id": goid, "acc": goacc, "term_type": gotype, "name": goname
})
graph.create(term) # now the node should be bound to a remote entity
term.labels.add("GO_TERM")
term.push()
或者,您可以创建带有标签的节点:
term = Node("GO_TERM", id=goid, acc=goacc, ...)
graph.create(term)