python - 如何将 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。
任何建议都将受到欢迎。
解决方案
对于问题的第二部分,您可以将 textnet 对象转换为 igraph:
g = tn.graph
然后另存为gml:
g.write_gml("test.gml")
推荐阅读
- javascript - 需要在表单验证中忽略引导模式验证
- javascript - Socket.IO 无法从服务器向客户端发送消息
- java - 如何在没有 NullPointerException 的情况下更改 JLabel 中显示的图像?
- python - 只阅读未读邮件
- python-3.x - 如果(未请求的)数据库不存在,则通过 python3 访问 postgresql 服务器失败
- android - 包含布局时的Android视图绑定问题
带有直接孩子的标签 - android - 显示弹出窗口时禁用键盘焦点
- css - Chrome 使某些颜色的字体变薄
- python - 对这种 Python 集合行为感到困惑
- entity-framework-core - 尽管使用 EF Core HasConversion 我有一个 InvalidCastException