Search code examples
pythonnlpigraphsna

How do you save textnets (python) to gml / gexf or access dataframe of graph?


I have been using textnets (python) to analyse a corpus. I need to export the resulting graph for further analysis / layout editing in Gephi. Having read the docs I am still confused on how to either save the resulting igraph Graph in the appropriate format or to access the pandas dataframe which could then be exported. For example using the tutorial from docs, if using:

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

print(tn)

I had thought I could either return a pandas data frame by calling 'tn' though this returns a 'Textnet' object.

I had also thought I could return an igraph.Graph object and then subsequently use Graph.write_gml() using something like tn.project(node_type='doc').write_gml('test.gml') to save the file in an appropriate format but this returns a ProjectedTextnet.

Any advise would be most welcome.


Solution

  • For the second part of your question, you can convert the textnet object to an igraph:

    g = tn.graph
    

    Then save as gml:

    g.write_gml("test.gml")