def graph2pajek(graph): new_graph = graph.copy() for _, node_data in new_graph.nodes(data=True): # Pajek exporter requires attribute with name 'id' to be int # or not existing and all other attributes to be strings. if "id" in node_data: node_data["identifier"] = node_data["id"] del node_data["id"] for attribute in node_data: node_data[attribute] = str(node_data[attribute]) return "\n".join(networkx.generate_pajek(new_graph)) + "\n"
def export_pajek(self): return nx.generate_pajek(self.graph)