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

Method get_attr_id

easygraph/readwrite/gexf.py:346–376  ·  view source on GitHub ↗
(self, title, attr_type, edge_or_node, default, mode)

Source from the content-addressed store, hash-verified

344 graph_element.append(nodes_element)
345
346 def get_attr_id(self, title, attr_type, edge_or_node, default, mode):
347 # find the id of the attribute or generate a new id
348 try:
349 return self.attr[edge_or_node][mode][title]
350 except KeyError:
351 # generate new id
352 new_id = str(next(self.attr_id))
353 self.attr[edge_or_node][mode][title] = new_id
354 attr_kwargs = {"id": new_id, "title": title, "type": attr_type}
355 attribute = Element("attribute", **attr_kwargs)
356 # add subelement for data default value if present
357 default_title = default.get(title)
358 if default_title is not None:
359 default_element = Element("default")
360 default_element.text = str(default_title)
361 attribute.append(default_element)
362 # new insert it into the XML
363 attributes_element = None
364 for a in self.graph_element.findall("attributes"):
365 # find existing attributes element by class and mode
366 a_class = a.get("class")
367 a_mode = a.get("mode", "static")
368 if a_class == edge_or_node and a_mode == mode:
369 attributes_element = a
370 if attributes_element is None:
371 # create new attributes element
372 attr_kwargs = {"mode": mode, "class": edge_or_node}
373 attributes_element = Element("attributes", **attr_kwargs)
374 self.graph_element.insert(0, attributes_element)
375 attributes_element.append(attribute)
376 return new_id
377
378 def add_edges(self, G, graph_element):
379 def edge_key_data(G):

Callers 1

add_attributesMethod · 0.95

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected