Gephi脚本控制台未显示节点

3

我是否遗漏了什么,还是Gephi脚本控制台中存在奇怪的错误?

控制台显示边缘但没有节点。

例如:

>>> len(g.edges)
4314
>>> len(g.nodes)
1

>>> g.edges
set([e8926, e8794, e7024 ......])
>>> g.nodes
set([None])

您可以使用Gephi提供的数据集Power Grid.gml来复制错误。 我在这里举个例子测试了几个数据集,都出现了相同的错误。
我做错了什么吗?

无论发生了什么,这不仅仅是与节点有关:除非我漏掉了什么,应该有4941个节点和6594条边。 - DSM
3个回答

3

有一个名为“Data Table”的插件,安装后可以查看数据集的结构。 我曾经遇到过类似的问题,我了解到节点ID是字符串而不是数字。如果您想在脚本插件中执行g.nodes()命令并查看插件之间的差异,可以从“Data Table”插件中看到新创建节点的ID是数字而不是字符串。当您在Gephi控制台中执行g.nodes或len(g.nodes)时,您可以看到新创建的节点。 我通过以下方式解决了这个问题: 我安装了一个名为“Data Table”的插件,在其中可以选择“导出表格”,它会告诉您需要导出哪些列,您可以选择任何您想要的列但不包括ID,然后选择一个分隔符并按下“确定”,它将保存。创建一个新项目,打开“Data Table”插件,然后单击“导入电子表格”,从这里您可以插入带有名为“Id”的新列的数据集,Gephi会自动将其添加到您的数据集中。


谢谢。我安装了“数据实验室助手”,它确实允许重新设置列(从字符串到整数)。可惜的是,您需要导出和重新导入表格(没有覆盖Id的方法)。另一种策略 - 我将使用的是 - 将图形导入python NetworkX,并将其保存为gexf。 - user1043144

1

现在距离最初的问题已经过去两年了,在Gephi的Jython控制台中仍存在一个bug,其中:

>>> g.nodes
set([None])

然而,我发现了一种解决方法,可以通过脚本控制台直接操作节点,就像这样:
>>> graph = g.getUnderlyingGraph()
>>> nodes = [node for node in graph.nodes]
>>> nodes
[n0, n1, n2, n3, n4, n5, n6, n7, ...

通过这样做,我能够像这样操作节点属性:
>>> node = nodes[0]
>>> attr = node.attributes
>>> value = attr.getValue('attribute_name')
>>> new_value = do_something(value)
>>> attr.setValue('attribute_name', new_value)

0

这是我用Python编写的脚本,如果您在完成用户1290329在此处所做的操作后无法将边缘放回原位,则可以使用它[https://dev59.com/k3DXa4cB1Zd3GeqP_mLO#15827459]

基本上,它将把您的新创建的Gephi整数ID列映射到一个边缘表中。

    import pandas as pd

    # Once you have re-imported your CSV, and your ID is an Int, 
    # but your edge table is still messed up
    nodes = pd.read_csv('nodes_table.csv')
    edges = pd.read_csv('edges_table.csv')

    # delete any unnecessary cols
    del edges['Label']


    # Create a dictionary with your Node name as the key, 
    # and its Gephi int Id as the value
    # To do this Set index to be col you want the dict keys to be
    # and the dict values will be col you specifiy in the brackets after 'ie ['Id']
    node_dict = nodes.set_index('Label')['Id'].to_dict()

    # Then use the map function, col you are mapping with should have they keys
    # And will fill with value of key when matched
    # In this case we just over-write the Source and Target cols
    edges['Source'] = edges['Source'].map(node_dict)
    edges['Target'] = edges['Target'].map(node_dict)

    edges.to_csv('edges_formatted_for_gephi.csv', index=False)
    edges.head()

现在在 Gephi 数据实验室中,导入电子表格时,请确保选择边选项,并单击选择“edges_formatted_for_gephi.csv”,取消选中“创建缺少的节点”,然后您的边应该会重新出现在 Gephi 图中。 :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接