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

Function generate_graphml

easygraph/readwrite/graphml.py:193–237  ·  view source on GitHub ↗

Generate GraphML lines for G Parameters ---------- G : graph A easygraph graph encoding : string (optional) Encoding for text data. prettyprint : bool (optional) If True use line breaks and indenting in output XML. named_key_ids : bool (optional)

(
    G,
    encoding="utf-8",
    prettyprint=True,
    named_key_ids=False,
    edge_id_from_attribute=None,
)

Source from the content-addressed store, hash-verified

191
192
193def generate_graphml(
194 G,
195 encoding="utf-8",
196 prettyprint=True,
197 named_key_ids=False,
198 edge_id_from_attribute=None,
199):
200 """Generate GraphML lines for G
201
202 Parameters
203 ----------
204 G : graph
205 A easygraph graph
206 encoding : string (optional)
207 Encoding for text data.
208 prettyprint : bool (optional)
209 If True use line breaks and indenting in output XML.
210 named_key_ids : bool (optional)
211 If True use attr.name as value for key elements' id attribute.
212 edge_id_from_attribute : dict key (optional)
213 If provided, the graphml edge id is set by looking up the corresponding
214 edge data attribute keyed by this parameter. If `None` or the key does not exist in edge data,
215 the edge id is set by the edge key if `G` is a MultiGraph, else the edge id is left unset.
216
217 Examples
218 --------
219 >>> G = eg.path_graph(4)
220 >>> linefeed = chr(10) # linefeed = \n
221 >>> s = linefeed.join(eg.generate_graphml(G))
222 >>> for line in eg.generate_graphml(G): # doctest: +SKIP
223 ... print(line)
224
225 Notes
226 -----
227 This implementation does not support mixed graphs (directed and unidirected
228 edges together) hyperedges, nested graphs, or ports.
229 """
230 writer = GraphMLWriter(
231 encoding=encoding,
232 prettyprint=prettyprint,
233 named_key_ids=named_key_ids,
234 edge_id_from_attribute=edge_id_from_attribute,
235 )
236 writer.add_graph_element(G)
237 yield from str(writer).splitlines()
238
239
240@open_file(0, mode="rb")

Callers

nothing calls this directly

Calls 2

add_graph_elementMethod · 0.95
GraphMLWriterClass · 0.85

Tested by

no test coverage detected