cfpq_data.graphs.readwrite.txt#
Read (and write) a graph from (and to) TXT file.
Functions
|
Returns a graph from text. |
|
Returns a graph loaded from a TXT file. |
|
Turns a graph into its text representation. |
|
Returns a path to the TXT file where the graph will be saved. |
- graph_from_text(text: Iterable[str]) MultiDiGraph[source]#
Returns a graph from text.
- Parameters:
- textIterable[str]
The text with which the graph will be created.
- Returns:
- gMultiDiGraph
Loaded graph.
Examples
>>> from cfpq_data import * >>> g = graph_from_text(["1 A 2"]) >>> g.number_of_nodes() 2 >>> g.number_of_edges() 1
- graph_from_txt(path: Path | str) MultiDiGraph[source]#
Returns a graph loaded from a TXT file.
- Parameters:
- pathUnion[Path, str]
The path to the TXT file with which the graph will be created.
- Returns:
- gMultiDiGraph
Loaded graph.
Examples
>>> from cfpq_data import * >>> g_1 = graph_from_text(["1 A 2"]) >>> p = graph_to_txt(g_1, "test.txt") >>> g = graph_from_txt(p) >>> g.number_of_nodes() 2 >>> g.number_of_edges() 1
- graph_to_text(graph: MultiDiGraph, *, quoting: bool = False) Iterator[str][source]#
Turns a graph into its text representation.
- Parameters:
- graphMultiDiGraph
Graph to text.
- quotingbool
If true, quotes will be added.
- Returns:
- textstr
Generator of graph edges.
Examples
>>> from cfpq_data import * >>> g = labeled_cycle_graph(2) >>> list(graph_to_text(g, quoting=True)) ["'0' 'a' '1'", "'1' 'a' '0'"] >>> list(graph_to_text(g, quoting=False)) ['0 a 1', '1 a 0']
- graph_to_txt(graph: MultiDiGraph, path: Path | str, *, quoting: bool = False) Path[source]#
Returns a path to the TXT file where the graph will be saved.
- Parameters:
- graphMultiDiGraph
Graph to save.
- path: Union[Path, str]
The path to the file where the graph will be saved.
- quotingbool
If true, quotes will be added.
- Returns:
- pathPath
Path to a TXT file where the graph will be saved.
Examples
>>> from cfpq_data import * >>> g = labeled_cycle_graph(42, label="a") >>> path = graph_to_txt(g, "test.txt", quoting=False)