Yog.IO.GEXF (YogEx v1.0.0)

Copy Markdown View Source

GEXF (Graph Exchange XML Format) serialization support.

Provides functions to serialize and deserialize graphs in GEXF format, the native format of Gephi and supported by many other graph visualization tools.

GEXF is an XML-based format that supports:

  • Nodes with typed attributes
  • Edges with typed attributes and weights
  • Directed and undirected graphs
  • Visual attributes (viz namespace): color, size, position
  • Dynamic graphs (not yet supported)

Performance

Uses Saxy for fast streaming SAX parsing when available (same as GraphML). Falls back to :xmerl otherwise.

Summary

Functions

Returns default GEXF serialization options.

Deserializes a GEXF string to a graph using default conversion.

Deserializes a GEXF string into a graph with custom data mappers.

Creates GEXF options with custom formatters.

Reads a graph from a GEXF file using default conversion.

Reads a graph from a GEXF file with custom data mappers.

Serializes a graph to GEXF format using default attribute conversion.

Serializes a graph to GEXF format with custom attribute mappers.

Serializes a graph to GEXF format with custom attribute mappers and options.

Writes a graph to a GEXF file using default attribute conversion.

Writes a graph to a GEXF file with custom attribute mappers.

Functions

default_options()

@spec default_options() :: tuple()

Returns default GEXF serialization options.

The options control data formatting:

  • node_formatter: Function to convert node IDs to strings (default: safe_string/1)
  • edge_formatter: Function to convert edge IDs to strings (default: safe_string/1)

Time complexity: $\mathcal{O}(1)$

deserialize(xml)

@spec deserialize(String.t()) :: {:ok, Yog.graph()} | {:error, term()}

Deserializes a GEXF string to a graph using default conversion.

Raises ArgumentError if xml is not a binary string.

Time complexity: $\mathcal{O}(V + E)$

deserialize_with(node_folder, edge_folder, xml)

@spec deserialize_with((map() -> any()), (map() -> any()), String.t()) ::
  {:ok, Yog.graph()} | {:error, term()}

Deserializes a GEXF string into a graph with custom data mappers.

Raises ArgumentError if xml or data mappers are invalid.

Time complexity: $\mathcal{O}(V + E)$

options_with(node_fmt, edge_fmt)

@spec options_with((any() -> any()), (any() -> any())) :: tuple()

Creates GEXF options with custom formatters.

Raises ArgumentError if formatters are invalid.

Time complexity: $\mathcal{O}(1)$

read(path)

@spec read(String.t()) :: {:ok, Yog.graph()} | {:error, term()}

Reads a graph from a GEXF file using default conversion.

Raises ArgumentError if path is not a binary string.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

read_with(path, node_folder, edge_folder)

@spec read_with(String.t(), (map() -> any()), (map() -> any())) ::
  {:ok, Yog.graph()} | {:error, term()}

Reads a graph from a GEXF file with custom data mappers.

Raises ArgumentError if path is not a binary string or mappers are invalid.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

serialize(graph)

@spec serialize(Yog.graph() | Yog.DAG.t()) :: String.t()

Serializes a graph to GEXF format using default attribute conversion.

Raises ArgumentError if graph is invalid.

Time complexity: $\mathcal{O}(V + E)$

serialize_with(node_attr, edge_attr, graph)

@spec serialize_with((any() -> map()), (any() -> map()), Yog.graph() | Yog.DAG.t()) ::
  String.t()

Serializes a graph to GEXF format with custom attribute mappers.

Raises ArgumentError if mappers or graph are invalid.

Time complexity: $\mathcal{O}(V + E)$

serialize_with_options(node_attr, edge_attr, options, graph)

@spec serialize_with_options(
  (any() -> map()),
  (any() -> map()),
  tuple(),
  Yog.graph() | Yog.DAG.t()
) ::
  String.t()

Serializes a graph to GEXF format with custom attribute mappers and options.

Raises ArgumentError if arguments or options are invalid.

Time complexity: $\mathcal{O}(V + E)$

write(path, graph)

@spec write(String.t(), Yog.graph() | Yog.DAG.t()) :: {:ok, nil} | {:error, atom()}

Writes a graph to a GEXF file using default attribute conversion.

Raises ArgumentError if path is not a binary string or graph is invalid.

Time complexity: $\mathcal{O}(V + E)$ + file I/O

write_with(path, node_attr, edge_attr, graph)

@spec write_with(
  String.t(),
  (any() -> map()),
  (any() -> map()),
  Yog.graph() | Yog.DAG.t()
) ::
  {:ok, nil} | {:error, atom()}

Writes a graph to a GEXF file with custom attribute mappers.

Raises ArgumentError if path is not a binary string or graph/mappers are invalid.

Time complexity: $\mathcal{O}(V + E)$ + file I/O