Current section
Files
Jump to
Current section
Files
src/yog_io.erl
-module(yog_io).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yog_io.gleam").
-export([read_graphml/1, write_graphml/2, read_gdf/1, write_gdf/2, default_graphml_options/0, default_gdf_options/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Yog IO - Graph file format I/O for the yog graph library.\n"
"\n"
" Provides serialization and deserialization support for popular graph file formats:\n"
" - **GraphML** - XML-based format supported by Gephi, yEd, Cytoscape, and NetworkX\n"
" - **GDF** - Simple CSV-like format used by Gephi\n"
"\n"
" ## Quick Start\n"
"\n"
" ```gleam\n"
" import yog/model.{Directed}\n"
" import yog_io\n"
"\n"
" // Create a graph\n"
" let graph =\n"
" model.new(Directed)\n"
" |> model.add_node(1, \"Alice\")\n"
" |> model.add_node(2, \"Bob\")\n"
"\n"
" let assert Ok(graph) = model.add_edge(graph, from: 1, to: 2, with: \"friend\")\n"
"\n"
" // Write to GraphML\n"
" let assert Ok(Nil) = yog_io.write_graphml(\"graph.graphml\", graph)\n"
"\n"
" // Read from GraphML\n"
" let assert Ok(loaded) = yog_io.read_graphml(\"graph.graphml\")\n"
"\n"
" // Write to GDF\n"
" let assert Ok(Nil) = yog_io.write_gdf(\"graph.gdf\", graph)\n"
" ```\n"
"\n"
" ## Module Structure\n"
"\n"
" - **`yog_io/graphml`** - Full-featured GraphML support with custom attribute mappers\n"
" - **`yog_io/gdf`** - GDF format support with custom attribute mappers\n"
"\n"
" For more control over serialization, use the submodules directly.\n"
).
-file("src/yog_io.gleam", 99).
?DOC(
" Reads a graph from a GraphML file.\n"
"\n"
" This is a convenience function that reads node and edge data as\n"
" string dictionaries. For custom data types, use `graphml.read_with`.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" let assert Ok(graph) = yog_io.read_graphml(\"graph.graphml\")\n"
"\n"
" // Access node data\n"
" import gleam/dict\n"
" let node1_data = dict.get(graph.nodes, 1)\n"
" ```\n"
).
-spec read_graphml(binary()) -> {ok,
yog@model:graph(gleam@dict:dict(binary(), binary()), gleam@dict:dict(binary(), binary()))} |
{error, binary()}.
read_graphml(Path) ->
yog_io@graphml:read(Path).
-file("src/yog_io.gleam", 122).
?DOC(
" Writes a graph to a GraphML file.\n"
"\n"
" This is a convenience function for graphs with string data.\n"
" For custom data types, use `graphml.write_with`.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" import yog/model.{Directed}\n"
"\n"
" let graph =\n"
" model.new(Directed)\n"
" |> model.add_node(1, \"Alice\")\n"
" |> model.add_node(2, \"Bob\")\n"
"\n"
" let assert Ok(graph) = model.add_edge(graph, from: 1, to: 2, with: \"5\")\n"
"\n"
" let assert Ok(Nil) = yog_io.write_graphml(\"graph.graphml\", graph)\n"
" ```\n"
).
-spec write_graphml(binary(), yog@model:graph(binary(), binary())) -> {ok, nil} |
{error, simplifile:file_error()}.
write_graphml(Path, Graph) ->
yog_io@graphml:write(Path, Graph).
-file("src/yog_io.gleam", 139).
?DOC(
" Reads a graph from a GDF file.\n"
"\n"
" This is a convenience function that reads node and edge data as\n"
" string dictionaries. For custom data types, use `gdf.read_with`.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" let assert Ok(graph) = yog_io.read_gdf(\"graph.gdf\")\n"
" ```\n"
).
-spec read_gdf(binary()) -> {ok,
yog@model:graph(gleam@dict:dict(binary(), binary()), gleam@dict:dict(binary(), binary()))} |
{error, binary()}.
read_gdf(Path) ->
yog_io@gdf:read(Path).
-file("src/yog_io.gleam", 162).
?DOC(
" Writes a graph to a GDF file.\n"
"\n"
" This is a convenience function for graphs with string data.\n"
" For custom data types, use `gdf.write_with`.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" import yog/model.{Directed}\n"
"\n"
" let graph =\n"
" model.new(Directed)\n"
" |> model.add_node(1, \"Alice\")\n"
" |> model.add_node(2, \"Bob\")\n"
"\n"
" let assert Ok(graph) = model.add_edge(graph, from: 1, to: 2, with: \"5\")\n"
"\n"
" let assert Ok(Nil) = yog_io.write_gdf(\"graph.gdf\", graph)\n"
" ```\n"
).
-spec write_gdf(binary(), yog@model:graph(binary(), binary())) -> {ok, nil} |
{error, simplifile:file_error()}.
write_gdf(Path, Graph) ->
yog_io@gdf:write(Path, Graph).
-file("src/yog_io.gleam", 174).
?DOC(" Default options for GraphML serialization.\n").
-spec default_graphml_options() -> yog_io@graphml:graph_m_l_options().
default_graphml_options() ->
yog_io@graphml:default_options().
-file("src/yog_io.gleam", 179).
?DOC(" Default options for GDF serialization.\n").
-spec default_gdf_options() -> yog_io@gdf:gdf_options().
default_gdf_options() ->
yog_io@gdf:default_options().