首页 > 解决方案 > 如何将 textnets (python) 保存到 gml / gexf 或访问图形的数据框?

问题描述

我一直在使用 textnets (python) 来分析语料库。我需要导出结果图以便在 Gephi 中进行进一步分析/布局编辑。阅读文档后,我仍然对如何以适当的格式保存生成的 igraph Graph 或访问然后可以导出的 pandas 数据框感到困惑。例如使用文档中的教程,如果使用:

from textnets import Corpus, Textnet
from textnets import examples
corpus = Corpus(examples.moon_landing)
tn = Textnet(corpus.tokenized(), min_docs=1)

print(tn)

我原以为我可以通过调用“tn”来返回一个熊猫数据框,尽管这会返回一个“Textnet”对象。

我还以为我可以返回一个 igraph.Graph 对象,然后使用 Graph.write_gml() 使用类似 tn.project(node_type='doc').write_gml('test.gml') 的方法以适当的格式保存文件,但这会返回一个 ProjectedTextnet。

任何建议都将受到欢迎。

标签: pythonnlpigraphsna

解决方案


对于问题的第二部分,您可以将 textnet 对象转换为 igraph:

g = tn.graph

然后另存为gml:

g.write_gml("test.gml")

推荐阅读