Python networkx 和持久性(可能在 neo4j 中) [英] Python networkx and persistence (perhaps in neo4j)

查看:27
本文介绍了Python networkx 和持久性(可能在 neo4j 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,每秒在内存中创建数千个图形.我希望找到一种方法来保留这些以供后续查询.它们并不是特别大(也许最大 ~1k 个节点).

I have an application that creates many thousands of graphs in memory per second. I wish to find a way to persist these for subsequent querying. They aren't particularly large (perhaps max ~1k nodes).

我需要能够存储整个图形对象,包括节点属性和边属性.然后,我需要能够根据节点中的时间属性在特定时间窗口内搜索图形.

I need to be able to store the entire graph object including node attributes and edge attributes. I then need to be able to search for graphs within specific time windows based on a time attribute in a node.

是否有一种简单的方法可以将这些数据强制转换为 neo4j ?我还没有找到任何这方面的例子.虽然我发现了几个 python 库,包括一个嵌入式 neo4j 和一个休息客户端.

Is there a simple way to coerce this data into neo4j ? I've yet to find any examples of this. Though I have found several python libs including an embedded neo4j and a rest client.

手动遍历图形并以这种方式存储它的常用方法是什么?

Is the common approach to manually traverse the graph and store it in that manner?

有没有更好的持久化替代方案?

Are there any better persistence alternatives?

推荐答案

Networkx 有几种序列化方法.

Networkx has several serialization method.

在你的情况下,我会选择 graphml 序列化:

In your case, I would choose graphml serialization :

http://networkx.github.io/documentation/latest/参考/readwrite.graphml.html

使用起来非常简单:

import networkx as nx
nx.write_graphml('/path/to/file')

要在 Neo4j 中加载它,如果你有 Neo4j<2.0,你可以使用 Tinkerpop Gremlin 在 Neo4J 中加载你的 graphml 转储

To load it in Neo4j, provided you have Neo4j<2.0, you could use Tinkerpop Gremlin to load your graphml dump in Neo4J

g.loadGraphML('/path/to/file')

Tinkerpop 非常有用 - 不仅用于序列化/反序列化.

The Tinkerpop are quite useful - not only for serialization/deserialization.

它将允许您使用具有commion方言"的不同图形数据库(前提是他们有大多数人都有的蓝图"驱动程序)

It will allow you to use different graph database with a commion "dialect" (provided they have a "Blueprint" driver which most of them do)

这篇关于Python networkx 和持久性(可能在 neo4j 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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