如何将 networkX 图导入到 neo4j? [英] How to import a networkX graph to neo4j?
本文介绍了如何将 networkX 图导入到 neo4j?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用 networkX
创建的图形,我正在使用 neonx 将它导入到本地主机上的 neo4j
.我有一个名为 G
的 networkX
类型图.代码如下:
I have a graph created with networkX
and I am using neonx to import it to neo4j
on localhost. I have a networkX
type graph called G
. Below is the code:
data1 = json_graph.node_link_data(G)
H = json_graph.node_link_graph(data1)
results = neonx.write_to_neo("http://localhost:7474/db/data/", H, 'LINKS_TO')
我得到的错误是:
Traceback (most recent call last):
File "/Users/aman/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-0d401e8987b7>", line 31, in <module>
results = neonx.write_to_neo("http://localhost:7474/db/data/", H, 'LINKS_TO')
File "/Users/aman/venv/lib/python3.7/site-packages/neonx/neo.py", line 86, in write_to_neo
batch_url = all_server_urls['batch']
KeyError: 'batch'
推荐答案
最好的方法是转储 networkx 图并将其导入 Neo4j.
Best way is to dump networkx graph and import it into Neo4j.
优点:
- 您不需要与 Neo4j 服务器建立工作连接
- 转储一次即可随时随地加载.您已保存版本/备份.
转储 networkx 图:
Dump networkx graph:
nx.write_graphml(g, 'path/to/file.graphml')
加载到 Neo4j:
- 从此处 为 Neo4j 安装 apoc 插件
- 在 conf/neo4j.conf 中启用
apoc.import.file.enabled=true
- 将您的图形转储
file.graphml
放在import/
文件夹中
- Install apoc plugin for Neo4j from here
- Enable
apoc.import.file.enabled=true
in conf/neo4j.conf - Place your graph dump
file.graphml
inimport/
folder
cypher-shell -a bolt://localhost:7687 "call apoc.import.graphml('file.graphml', {})"
或在浏览器中:
call apoc.import.graphml('file.graphml', {})
欲知更多详情:
这篇关于如何将 networkX 图导入到 neo4j?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文