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

查看:192
本文介绍了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和一个rest客户.

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/reference/readwrite.graphml.html

使用非常简单:

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

要在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.

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

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天全站免登陆