用于存储图形的格式



我正在进行一个项目,该项目涉及使用从其他来源提取的图形。目前,我们正在使用python的networkx模块来分析该图。

我现在面临的任务是选择一种存储图形的格式。对于纯粹基于python的解决方案来说,Pickle似乎是一个不错的选择。然而,我们现在正处于原型设计阶段,由于性能和可扩展性问题,我们很有可能不得不改用C++。

因此,我希望以大多数图库广泛支持的格式存储我的图,以最大限度地减少项目中未来贡献者面临的麻烦。

关于我应该使用哪种格式,你能给我一些建议吗?

TGF是您的解决方案。

python示例:

 #!/usr/bin/python
import fileinput, re
depends = {}
for line in fileinput.input():
    m = re.match('(.+):s*(.*)',line) # find every depenency line of the form "<item>: <dependencies>"
    if m:
        item = m.group(1)
        dependency_list = m.group(2)
        print item,item # node definition
        if dependency_list: # there are dependencies
            depends[item] = dependency_list.split() # store the list into a dictionary for later
print "#" # end of node list, start of edge list
for item in depends:
    for dependency in depends[item]:
        print item,dependency # edge definition

我不确定这里是否非常相关,但基于图的数据库不能胜任这项工作吗?

例如,您有两个选项,如Neo4j或AllegroGraph,您可以很容易地找到用于python或任何其他语言的两个绑定,而且大多数解决方案也提供了REST API。

请注意我提供的第一个链接不是最新的,现在有更多的解决方案,而且即使编写了Python的API,它也可以使用。您也可以看看这里(图形数据库部分(。

edit我发现查看它可能也很有趣,它似乎是处理和存储JSON风格或分隔文本中的图形的合适格式:

  • Geoff,简易图形格式

此外,你可能想看看这里:

  • Bulbflow,一个用于图形数据库的Python框架,使用查询语言Gremlin,并与多个数据库系统兼容
  • Gremlin,一种图形遍历语言(另请参阅关于Gremlin、Bulb Gremlin API doc和neo4j的Gremlin插件的演示(

相关内容

最新更新