首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python字典可以作为Neo4j文字映射传递吗?

Python字典可以作为Neo4j文字映射传递吗?
EN

Stack Overflow用户
提问于 2016-10-30 19:23:09
回答 1查看 2K关注 0票数 4

我是一个新手,从Neo4j和Python开始。我正在尝试使用Python驱动程序将一些数据填充到Neo4j中。

我想知道是否可以将Python字典作为Neo4j文档中描述的文字映射传递。

这将使我能够立即设置应用程序节点属性。属性因节点而异,因此代码会变得丑陋。

下面给出一个例子

代码语言:javascript
复制
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允许将参数传递到Cypher查询,但是可以将python字典传递到查询中,并作为Neo4j 文字映射访问。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-30 21:32:06

将dict作为参数传递将将其转换为Map,它的行为与您在Cypher中声明的Map完全相同。我觉得你在画一个不存在的区别。

代码语言:javascript
复制
some_python_dict = {'a': 1, 'b': 2}
session.run(
    statement="CREATE (x) SET x = {dict_param}",
    parameters={'dict_param': some_python_dict}
)

这正是您通常从语言驱动程序中设置节点的方式。如果您正在制作几个参数,则传递一个参数,它是一个dicts列表,然后UNWIND该参数启动,您将获得最好的性能。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40332698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档