如何将Python节点字典导入neo4j? [英] How do I import Python node dicts into neo4j?

查看:741
本文介绍了如何将Python节点字典导入neo4j?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在for循环中产生大约一百万次以下节点和关系数据.这个想法是investor节点通过relationship边缘连接到company节点:

I produce the following node and relationship data in a for loop about 1 million times. The idea is that investor nodes connect to company nodes by relationship edges:

investor = {'name': owner['name'],
            'CIK': owner['CIK']}

relationship = {'isDirector': owner['isDirector'],
                'isOfficer': owner['isOfficer'],
                'isOther': owner['isOther'],
                'isTenPercentOwner': owner['isTenPercentOwner'],
                'title': owner['title']}

company = {'Name': json['issuerName'],
           'SIC': json['issuerSIC'],
           'Ticker Symbol': json['issuerTradingSymbol'],
           'CIK': json['issuerCIK'],
           'EIN': json['issuerEIN']}

我如何完成以下代码以将上述命令纳入neo4j社区版?

How do I complete the following code to get the dicts above into neo4j community edition?

from py2neo import Graph, authenticate 

authenticate("localhost:7474", "neo4j", "neo")
graph = Graph()

for json in long_list_of_dicts:
    investor = {...}
    company = {...}
    relationship  = {...}

    # Code to import investor, company, relationship data into neo4j

推荐答案

您可以使用UNWIND子句.像

WITH {json} AS document
UNWIND document AS company
MERGE (c:company {c_id:company.id})
 SET c.sic=company.issuerSIC

如果再次列出了一些json项目,则可以根据需要使用UNWIND:UNWIND document.list_of_some_property

If some of your json items is list again, you can use UNWIND as much as you like: UNWIND document.list_of_some_property

这篇关于如何将Python节点字典导入neo4j?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆