(self, graph_xml)
| 728 | raise nx.NetworkXError("No <graph> element in GEXF file.") |
| 729 | |
| 730 | def make_graph(self, graph_xml): |
| 731 | # start with empty DiGraph or MultiDiGraph |
| 732 | edgedefault = graph_xml.get("defaultedgetype", None) |
| 733 | if edgedefault == "directed": |
| 734 | G = nx.MultiDiGraph() |
| 735 | else: |
| 736 | G = nx.MultiGraph() |
| 737 | |
| 738 | # graph attributes |
| 739 | graph_name = graph_xml.get("name", "") |
| 740 | if graph_name != "": |
| 741 | G.graph["name"] = graph_name |
| 742 | graph_start = graph_xml.get("start") |
| 743 | if graph_start is not None: |
| 744 | G.graph["start"] = graph_start |
| 745 | graph_end = graph_xml.get("end") |
| 746 | if graph_end is not None: |
| 747 | G.graph["end"] = graph_end |
| 748 | graph_mode = graph_xml.get("mode", "") |
| 749 | if graph_mode == "dynamic": |
| 750 | G.graph["mode"] = "dynamic" |
| 751 | else: |
| 752 | G.graph["mode"] = "static" |
| 753 | |
| 754 | # timeformat |
| 755 | self.timeformat = graph_xml.get("timeformat") |
| 756 | if self.timeformat == "date": |
| 757 | self.timeformat = "string" |
| 758 | |
| 759 | # node and edge attributes |
| 760 | attributes_elements = graph_xml.findall(f"{{{self.NS_GEXF}}}attributes") |
| 761 | # dictionaries to hold attributes and attribute defaults |
| 762 | node_attr = {} |
| 763 | node_default = {} |
| 764 | edge_attr = {} |
| 765 | edge_default = {} |
| 766 | for a in attributes_elements: |
| 767 | attr_class = a.get("class") |
| 768 | if attr_class == "node": |
| 769 | na, nd = self.find_gexf_attributes(a) |
| 770 | node_attr.update(na) |
| 771 | node_default.update(nd) |
| 772 | G.graph["node_default"] = node_default |
| 773 | elif attr_class == "edge": |
| 774 | ea, ed = self.find_gexf_attributes(a) |
| 775 | edge_attr.update(ea) |
| 776 | edge_default.update(ed) |
| 777 | G.graph["edge_default"] = edge_default |
| 778 | else: |
| 779 | raise # unknown attribute class |
| 780 | |
| 781 | # Hack to handle Gephi0.7beta bug |
| 782 | # add weight attribute |
| 783 | ea = {"weight": {"type": "double", "mode": "static", "title": "weight"}} |
| 784 | ed = {} |
| 785 | edge_attr.update(ea) |
| 786 | edge_default.update(ed) |
| 787 | G.graph["edge_default"] = edge_default |
no test coverage detected