我想将gremlinpython图(gremlin_python.structure.graph.Graph)转换为networkx图。
我发现,使用package ipython-gremlin (https://github.com/davebshow/ipython-gremlin),可以将顶点转换为熊猫数据,边缘转换为networkx.classes.multidigraph.MultiDiGraph,但是包已经过时,我无法找到它们进行转换的代码位置。有办法进行转换吗?
谢谢!
发布于 2021-02-19 17:04:15
您可能需要编写一些代码才能做到这一点。在使用subgraph步骤返回我感兴趣的图的部分之前,我已经这样做了,然后迭代它,创建NetworkX顶点和边。这相当简单。唯一需要注意的问题是,当前Gremlin客户端使用默认的“旋风”最大结果帧大小,我认为这是10 an,因此如果您的子图结果超过该值,您将遇到异常。下面是一个简单的示例,它在航空航线数据集中找到了来自SAF机场的航线星图,并由此创建了一个NetworkX DiGraph。
import networkx as nx
G = nx.DiGraph()
sg = g.V().has('code','SAF').outE().subgraph('sg').cap('sg').next()
for e in sg['@value']['edges']:
G.add_edge(e.outV.id,e.inV.id,elabel=e.label)
print(G.nodes())
print(G.edges())运行时,结果是
['44', '13', '20', '31', '8']
[('44', '13'), ('44', '20'), ('44', '31'), ('44', '8')]https://stackoverflow.com/questions/66281752
复制相似问题