Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

json - How do I import Python node dicts into neo4j?

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']}

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In py2neo a Node is defined in following manner:

class Node(*labels, **properties)

Each node has a label and can have many properties. In this case, Investor node can de defined by setting the label investor and properties of the node to be name and CIK.

investor_node = Node('investor', name = owner['name'], CIK = owner['CIK'])

Similarly, company node would look like:

company_node = Node('company', name = json['issuerName'], SIC = json['issuerSIC'])

Relationship are defined in following manner :

class Relationship(start_node, type, end_node, **properties)

In this case Relationship can be defined using:

investor_company_relationship = Relationship(investor_node, "is_director", company_node)

You can find one sample implementation of neo4j graph here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...