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

Function parse_graphml

easygraph/readwrite/graphml.py:313–383  ·  view source on GitHub ↗

Read graph in GraphML format from string. Parameters ---------- graphml_string : string String containing graphml information (e.g., contents of a graphml file). node_type: Python type (default: str) Convert node ids to this type edge_key_type: Python type

(
    graphml_string, node_type=str, edge_key_type=int, force_multigraph=False
)

Source from the content-addressed store, hash-verified

311
312
313def parse_graphml(
314 graphml_string, node_type=str, edge_key_type=int, force_multigraph=False
315):
316 """Read graph in GraphML format from string.
317
318 Parameters
319 ----------
320 graphml_string : string
321 String containing graphml information
322 (e.g., contents of a graphml file).
323
324 node_type: Python type (default: str)
325 Convert node ids to this type
326
327 edge_key_type: Python type (default: int)
328 Convert graphml edge ids to this type. Multigraphs use id as edge key.
329 Non-multigraphs add to edge attribute dict with name "id".
330
331 force_multigraph : bool (default: False)
332 If True, return a multigraph with edge keys. If False (the default)
333 return a multigraph when multiedges are in the graph.
334
335
336 Returns
337 -------
338 graph: EasyGraph graph
339 If no parallel edges are found a Graph or DiGraph is returned.
340 Otherwise a MultiGraph or MultiDiGraph is returned.
341
342 Examples
343 --------
344 >>> G = eg.path_graph(4)
345 >>> linefeed = chr(10) # linefeed = \n
346 >>> s = linefeed.join(eg.generate_graphml(G))
347 >>> H = eg.parse_graphml(s)
348
349 Notes
350 -----
351 Default node and edge attributes are not propagated to each node and edge.
352 They can be obtained from `G.graph` and applied to node and edge attributes
353 if desired using something like this:
354
355 >>> default_color = G.graph["node_default"]["color"] # doctest: +SKIP
356 >>> for node, data in G.nodes(data=True): # doctest: +SKIP
357 ... if "color" not in data:
358 ... data["color"] = default_color
359 >>> default_color = G.graph["edge_default"]["color"] # doctest: +SKIP
360 >>> for u, v, data in G.edges(data=True): # doctest: +SKIP
361 ... if "color" not in data:
362 ... data["color"] = default_color
363
364 This implementation does not support mixed graphs (directed and unidirected
365 edges together), hypergraphs, nested graphs, or ports.
366
367 For multigraphs the GraphML edge "id" will be used as the edge
368 key. If not specified then they "key" attribute will be used. If
369 there is no "key" attribute a default EasyGraph multigraph edge key
370 will be provided.

Callers

nothing calls this directly

Calls 1

GraphMLReaderClass · 0.85

Tested by

no test coverage detected