Read graph in GraphML format from path. Parameters ---------- path : file or string File or filename to write. Filenames ending in .gz or .bz2 will be compressed. node_type: Python type (default: str) Convert node ids to this type edge_key_type: Python typ
(path, node_type=str, edge_key_type=int, force_multigraph=False)
| 239 | |
| 240 | @open_file(0, mode="rb") |
| 241 | def read_graphml(path, node_type=str, edge_key_type=int, force_multigraph=False): |
| 242 | """Read graph in GraphML format from path. |
| 243 | |
| 244 | Parameters |
| 245 | ---------- |
| 246 | path : file or string |
| 247 | File or filename to write. |
| 248 | Filenames ending in .gz or .bz2 will be compressed. |
| 249 | |
| 250 | node_type: Python type (default: str) |
| 251 | Convert node ids to this type |
| 252 | |
| 253 | edge_key_type: Python type (default: int) |
| 254 | Convert graphml edge ids to this type. Multigraphs use id as edge key. |
| 255 | Non-multigraphs add to edge attribute dict with name "id". |
| 256 | |
| 257 | force_multigraph : bool (default: False) |
| 258 | If True, return a multigraph with edge keys. If False (the default) |
| 259 | return a multigraph when multiedges are in the graph. |
| 260 | |
| 261 | Returns |
| 262 | ------- |
| 263 | graph: EasyGraph graph |
| 264 | If parallel edges are present or `force_multigraph=True` then |
| 265 | a MultiGraph or MultiDiGraph is returned. Otherwise a Graph/DiGraph. |
| 266 | The returned graph is directed if the file indicates it should be. |
| 267 | |
| 268 | Notes |
| 269 | ----- |
| 270 | Default node and edge attributes are not propagated to each node and edge. |
| 271 | They can be obtained from `G.graph` and applied to node and edge attributes |
| 272 | if desired using something like this: |
| 273 | |
| 274 | >>> default_color = G.graph["node_default"]["color"] # doctest: +SKIP |
| 275 | >>> for node, data in G.nodes(data=True): # doctest: +SKIP |
| 276 | ... if "color" not in data: |
| 277 | ... data["color"] = default_color |
| 278 | >>> default_color = G.graph["edge_default"]["color"] # doctest: +SKIP |
| 279 | >>> for u, v, data in G.edges(data=True): # doctest: +SKIP |
| 280 | ... if "color" not in data: |
| 281 | ... data["color"] = default_color |
| 282 | |
| 283 | This implementation does not support mixed graphs (directed and unidirected |
| 284 | edges together), hypergraphs, nested graphs, or ports. |
| 285 | |
| 286 | For multigraphs the GraphML edge "id" will be used as the edge |
| 287 | key. If not specified then they "key" attribute will be used. If |
| 288 | there is no "key" attribute a default EasyGraph multigraph edge key |
| 289 | will be provided. |
| 290 | |
| 291 | Files with the yEd "yfiles" extension can be read. The type of the node's |
| 292 | shape is preserved in the `shape_type` node attribute. |
| 293 | |
| 294 | yEd compressed files ("file.graphmlz" extension) can be read by renaming |
| 295 | the file to "file.graphml.gz". |
| 296 | |
| 297 | """ |
| 298 | reader = GraphMLReader(node_type, edge_key_type, force_multigraph) |
nothing calls this directly
no test coverage detected