如何使用 Corpus.slice 添加带有日期的列

How to add column with dates by using Corpus.slice

我真的是编程新手,这就是为什么我的问题可能很无聊或愚蠢,对此深表歉意!我正在尝试在 Gephi 中构建合着图(graphml 格式)。一切都很好,但我不明白如何在同一个文件中导入日期。我的代码如下:

from tethne.readers import wos
MyCorpus = wos.corpus_from_dir(datapath)
from tethne.networks import authors
ca_graph = authors.coauthors(MyCorpus.all_papers())
from tethne.writers import graph
graph.to_graphml(ca_graph, './file.graphml')`

因此,在这个 file.graphml 中,我有 authorsinstitutions,但我没有任何 (当这项工作发表时)。我找到了一段代码 here

MyCorpus.slice('date', 'time_period', window_size=1, cumulative=True)

但我不知道如何将所有内容写入一个文件。我会感谢所有的帮助!

由于 tethne.writers.graph 使用 networkx 图表,您的问题归结为 writing attributes to networkx nodes

您可以尝试类似的方法:

for author, attribs in ca_graph:
    # somehow calculate a year_value
    ca_graph.node[author]['year'] = year_value