【问题标题】:py2neo 2.x, "Local entity is not bound to a remote entity"py2neo 2.x,“本地实体未绑定到远程实体”
【发布时间】:2015-07-31 07:44:43
【问题描述】:

在将 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

我做错了什么?

谢谢!

【问题讨论】:

    标签: neo4j py2neo


    【解决方案1】:

    我认为您必须先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)
    

    【讨论】:

    • 谢谢!它创建节点。但是如果使用批处理(在代码中取消注释),它会一个接一个地创建节点。那你知道怎么处理吗?
    • 您应该使用 Cypher 交易而不是批量交易:py2neo.org/2.0/cypher.html。查看 Cypher 任务 py2neo.org/2.0/cypher.html#tasks
    猜你喜欢
    • 2017-10-25
    • 2015-06-21
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多