MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / add_graph_element

Method add_graph_element

easygraph/readwrite/graphml.py:621–658  ·  view source on GitHub ↗

Serialize graph G in GraphML to the stream.

(self, G)

Source from the content-addressed store, hash-verified

619 graph_element.append(edge_element)
620
621 def add_graph_element(self, G):
622 """
623 Serialize graph G in GraphML to the stream.
624 """
625 if G.is_directed():
626 default_edge_type = "directed"
627 else:
628 default_edge_type = "undirected"
629
630 graphid = G.graph.pop("id", None)
631 if graphid is None:
632 graph_element = self.myElement("graph", edgedefault=default_edge_type)
633 else:
634 graph_element = self.myElement(
635 "graph", edgedefault=default_edge_type, id=graphid
636 )
637 default = {}
638 data = {
639 k: v
640 for (k, v) in G.graph.items()
641 if k not in ["node_default", "edge_default"]
642 }
643 self.add_attributes("graph", graph_element, data, default)
644 self.add_nodes(G, graph_element)
645 self.add_edges(G, graph_element)
646
647 # self.attributes contains a mapping from XML Objects to a list of
648 # data that needs to be added to them.
649 # We postpone processing in order to do type inference/generalization.
650 # See self.attr_type
651 for xml_obj, data in self.attributes.items():
652 for k, v, scope, default in data:
653 xml_obj.append(
654 self.add_data(
655 str(k), self.attr_type(k, scope, v), str(v), scope, default
656 )
657 )
658 self.xml.append(graph_element)
659
660 def add_graphs(self, graph_list):
661 """Add many graphs to this GraphML document."""

Callers 4

write_graphml_xmlFunction · 0.95
generate_graphmlFunction · 0.95
__init__Method · 0.95
add_graphsMethod · 0.95

Calls 8

add_attributesMethod · 0.95
add_nodesMethod · 0.95
add_edgesMethod · 0.95
add_dataMethod · 0.95
attr_typeMethod · 0.95
popMethod · 0.80
appendMethod · 0.80
is_directedMethod · 0.45

Tested by

no test coverage detected