def finalize_graph(self): """Convert from FtM graph model to NetworkX directed graph.""" digraph = nx.MultiDiGraph() for node in self.graph.iternodes(): attributes = self.get_attributes(node) attributes['schema'] = node.type.name if node.caption is not None: attributes['label'] = node.caption if node.is_entity: attributes['schema'] = node.schema.name digraph.add_node(node.id, **attributes) for edge in self.graph.iteredges(): attributes = self.get_attributes(edge) attributes['schema'] = edge.type_name attributes['weight'] = edge.weight digraph.add_edge(edge.source_id, edge.target_id, key=edge.id, **attributes) for line in generate_gexf(digraph, prettyprint=True): self.fh.write(line) self.fh.write('\n')
def export_gexf(): stdin = click.get_text_stream('stdin') stdout = click.get_text_stream('stdout') graph = nx.MultiDiGraph() exporter = NXGraphExport(graph) try: while True: entity = read_entity(stdin) if entity is None: break exporter.write(entity) except BrokenPipeError: raise click.Abort() for line in generate_gexf(graph, prettyprint=False): stdout.write(line)
def finalize(self): for line in generate_gexf(self.graph, prettyprint=False): self.fh.write(line)