def main(args): inputfolder = args.inputfolder outputfolder = args.outputfolder project = CProject(os.getcwd(), inputfolder) if len(args.plugin) == 2: filename = "-".join(args.plugin) complete_graph, fact_graph, paper_graph, fact_nodes, paper_nodes = create_network( project, args.plugin[0], args.plugin[1] ) nx.write_gml(complete_graph, os.path.join(outputfolder, "-".join([filename, "complete_graph.gml"]))) nx.write_gml(fact_graph, os.path.join(outputfolder, "-".join([filename, "fact_graph.gml"]))) nx.write_gml(paper_graph, os.path.join(outputfolder, "-".join([filename, "paper_graph.gml"]))) print("The number of papers in the network: ", len(paper_nodes)) print("The number of facts: ", len(fact_nodes)) if "completeGraph" in args.action: filename = "complete-graph" complete_graph, fact_graph, paper_graph, fact_nodes, paper_nodes = create_complete_graph(project) nx.write_gml(complete_graph, os.path.join(outputfolder, "complete_graph.gml")) nx.write_gml(fact_graph, os.path.join(outputfolder, "fact_graph.gml")) nx.write_gml(paper_graph, os.path.join(outputfolder, "paper_graph.gml")) print("The number of papers in the network: ", len(paper_nodes)) print("The number of facts: ", len(fact_nodes)) if "plotFactNetwork" in args.action: save_graph(fact_graph, color="blue", filename=os.path.join(outputfolder, "-".join([filename, "fact-graph"]))) if "plotPaperNetwork" in args.action: save_graph(paper_graph, color="blue", filename=os.path.join(outputfolder, "-".join([filename, "paper-graph"]))) if "plotSubgraphs" in args.action: print("Exporting subgraphs.") export_subgraphs(fact_graph, 5) if "visualizeTimeline" in args.action: print("Visualizing paper count timeline.")
def export_subgraphs(graph, how_many): start_with = 0 # pick a number between 1 and 50 how_many = ( how_many ) # choose the number of communities you want to plot between 1 and 5. More takes a lot of space in your notebook subgraphs = sorted(nx.connected_component_subgraphs(graph), key=len, reverse=True)[ start_with : start_with + how_many ] for sg in subgraphs: degreeCent = nx.algorithms.degree_centrality(sg) maxdegreenode = max(degreeCent, key=degreeCent.get) print(maxdegreenode) # plotGraph(sg, "orange").show() # choose a color, e.g. red, blue, green, ... save_graph(sg, "orange", figsize=(12, 12), filename=os.path.join(args.outputfolder, maxdegreenode))