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

Function read_gml

easygraph/readwrite/gml.py:579–658  ·  view source on GitHub ↗

Read graph in GML format from `path`. Parameters ---------- path : filename or filehandle The filename or filehandle to read from. label : string, optional If not None, the parsed nodes will be renamed according to node attributes indicated by `label`. Defau

(path, label="label", destringizer=None)

Source from the content-addressed store, hash-verified

577
578@open_file(0, mode="rb")
579def read_gml(path, label="label", destringizer=None):
580 """Read graph in GML format from `path`.
581
582 Parameters
583 ----------
584 path : filename or filehandle
585 The filename or filehandle to read from.
586
587 label : string, optional
588 If not None, the parsed nodes will be renamed according to node
589 attributes indicated by `label`. Default value: 'label'.
590
591 destringizer : callable, optional
592 A `destringizer` that recovers values stored as strings in GML. If it
593 cannot convert a string to a value, a `ValueError` is raised. Default
594 value : None.
595
596 Returns
597 -------
598 G : EasyGraph graph
599 The parsed graph.
600
601 Raises
602 ------
603 EasyGraphError
604 If the input cannot be parsed.
605
606 See Also
607 --------
608 write_gml, parse_gml
609 literal_destringizer
610
611 Notes
612 -----
613 GML files are stored using a 7-bit ASCII encoding with any extended
614 ASCII characters (iso8859-1) appearing as HTML character entities.
615 Without specifying a `stringizer`/`destringizer`, the code is capable of
616 writing `int`/`float`/`str`/`dict`/`list` data as required by the GML
617 specification. For writing other data types, and for reading data other
618 than `str` you need to explicitly supply a `stringizer`/`destringizer`.
619
620 For additional documentation on the GML file format, please see the
621 `GML url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_.
622
623 See the module docstring :mod:`easygraph.readwrite.gml` for more details.
624
625 Examples
626 --------
627 >>> G = eg.path_graph(4)
628 >>> eg.write_gml(G, "test.gml")
629
630 GML values are interpreted as strings by default:
631
632 >>> H = eg.read_gml("test.gml")
633 >>> H.nodes
634 NodeView(('0', '1', '2', '3'))
635
636 When a `destringizer` is provided, GML values are converted to the provided type.

Callers

nothing calls this directly

Calls 2

parse_gml_linesFunction · 0.85
filter_linesFunction · 0.85

Tested by

no test coverage detected