| 740 | return G |
| 741 | |
| 742 | def add_node(self, G, node_xml, node_attr, node_pid=None): |
| 743 | # add a single node with attributes to the graph |
| 744 | |
| 745 | # get attributes and subattributues for node |
| 746 | data = self.decode_attr_elements(node_attr, node_xml) |
| 747 | data = self.add_parents(data, node_xml) # add any parents |
| 748 | if self.VERSION == "1.1": |
| 749 | data = self.add_slices(data, node_xml) # add slices |
| 750 | else: |
| 751 | data = self.add_spells(data, node_xml) # add spells |
| 752 | data = self.add_viz(data, node_xml) # add viz |
| 753 | data = self.add_start_end(data, node_xml) # add start/end |
| 754 | |
| 755 | # find the node id and cast it to the appropriate type |
| 756 | node_id = node_xml.get("id") |
| 757 | if self.node_type is not None: |
| 758 | node_id = self.node_type(node_id) |
| 759 | |
| 760 | # every node should have a label |
| 761 | node_label = node_xml.get("label") |
| 762 | data["label"] = node_label |
| 763 | |
| 764 | # parent node id |
| 765 | node_pid = node_xml.get("pid", node_pid) |
| 766 | if node_pid is not None: |
| 767 | data["pid"] = node_pid |
| 768 | |
| 769 | # check for subnodes, recursive |
| 770 | subnodes = node_xml.find(f"{{{self.NS_GEXF}}}nodes") |
| 771 | if subnodes is not None: |
| 772 | for node_xml in subnodes.findall(f"{{{self.NS_GEXF}}}node"): |
| 773 | self.add_node(G, node_xml, node_attr, node_pid=node_id) |
| 774 | |
| 775 | G.add_node(node_id, **data) |
| 776 | |
| 777 | def add_start_end(self, data, xml): |
| 778 | # start and end times |