2016-10-30 8 views
0

私はNeo4jとPythonで始まる初心者です。私はいくつかのデータをPythonドライバを使ってNeo4jに移植しようとしています。Python辞書をNeo4jリテラルマップとして渡すことはできますか?

Neo4jのドキュメントに記載されているリテラルマップとしてPython辞書を渡すことが可能かどうかは疑問でした。

これにより、アプリノードのプロパティを一度に設定できます。プロパティはノードによって異なるので、コードは醜いものになります。

例はがサイファークエリにパラメータを渡すことができ

node1 = { 
    'def': '"A protein transport process that contributes to protein import into the nucleus, and that results in the vectorial transfer of a cargo-carrier protein complex through the nuclear pore complex from the cytoplasmic side to the nucleoplasmic side of the nuclear envelope." [GOC:curators, ISBN:019 8506732, PMID:14570049, PMID:9126736]', 
    'id': 'GO:0000060', 
    'is_a': ['GO:0006886'], 
    'name': 'protein import into nucleus, translocation', 
    'namespace': 'biological_process', 
    'relationship': ['part_of GO:0006606'], 
    'synonym': [ '"protein import into cell nucleus, translocation" EXACT []' ] 
} 

node2 = { 
    'def': '"A protein complex disassembly process that contributes to protein import into the nucleus, and that results in the dissociation of the cargo protein and the carrier (such as an importin alpha/beta heterodimer) from each other and from the nuclear pore complex." [GOC:mah, PMID:14570049, PMID:9126736, PMID:9687515]', 
    'id': 'GO:0000061', 
    'is_a': ['GO:0043624'], 
    'name': 'protein import into nucleus, substrate release', 
    'namespace': 'biological_process', 
    'relationship': ['part_of GO:0006606'], 
    'is_obselete' : True 
} 

session.run下に与えられているが、Pythonの辞書は、クエリに渡されることができ、そしてのNeo4jとしてアクセスリテラルマップ

答えて

3

dict にすると、パラメータがマップに変わり、これはCypherで宣言したマップとまったく同じように動作します。私はあなたが存在しない区別を引き出していると思います。

some_python_dict = {'a': 1, 'b': 2} 
session.run(
    statement="CREATE (x) SET x = {dict_param}", 
    parameters={'dict_param': some_python_dict} 
) 

これは、通常、言語ドライバからノードを設定する方法と同じです。いくつか作成している場合は、代わりにdictsのリストであるパラメータを渡してから、UNWINDそのパラメータを開始すると、最高のパフォーマンスが得られます。

関連する問題