yog_io
Yog IO - Graph file format I/O for the yog graph library.
Provides serialization and deserialization support for popular graph file formats:
- GraphML - XML-based format supported by Gephi, yEd, Cytoscape, and NetworkX
- GDF - Simple CSV-like format used by Gephi
Quick Start
import yog/model.{Directed}
import yog_io
// Create a graph
let graph =
model.new(Directed)
|> model.add_node(1, "Alice")
|> model.add_node(2, "Bob")
let assert Ok(graph) = model.add_edge(graph, from: 1, to: 2, with: "friend")
// Write to GraphML
let assert Ok(Nil) = yog_io.write_graphml("graph.graphml", graph)
// Read from GraphML
let assert Ok(loaded) = yog_io.read_graphml("graph.graphml")
// Write to GDF
let assert Ok(Nil) = yog_io.write_gdf("graph.gdf", graph)
Module Structure
yog_io/graphml- Full-featured GraphML support with custom attribute mappersyog_io/gdf- GDF format support with custom attribute mappers
For more control over serialization, use the submodules directly.
Types
pub type AttributeType =
graphml.AttributeType
pub type AttributedGraph =
model.Graph(
dict.Dict(String, String),
dict.Dict(String, String),
)
pub type EdgeAttributes =
dict.Dict(String, String)
pub type GdfOptions =
gdf.GdfOptions
pub type GraphMLOptions =
graphml.GraphMLOptions
pub type NodeAttributes =
dict.Dict(String, String)
pub type TypedEdgeAttributes =
dict.Dict(String, #(String, graphml.AttributeType))
pub type TypedNodeAttributes =
dict.Dict(String, #(String, graphml.AttributeType))
Values
pub const boolean_type: graphml.AttributeType
pub fn default_gdf_options() -> gdf.GdfOptions
Default options for GDF serialization.
pub fn default_graphml_options() -> graphml.GraphMLOptions
Default options for GraphML serialization.
pub const double_type: graphml.AttributeType
pub const float_type: graphml.AttributeType
pub const int_type: graphml.AttributeType
pub const long_type: graphml.AttributeType
pub fn read_gdf(
path: String,
) -> Result(
model.Graph(
dict.Dict(String, String),
dict.Dict(String, String),
),
String,
)
Reads a graph from a GDF file.
This is a convenience function that reads node and edge data as
string dictionaries. For custom data types, use gdf.read_with.
Example
let assert Ok(graph) = yog_io.read_gdf("graph.gdf")
pub fn read_graphml(
path: String,
) -> Result(
model.Graph(
dict.Dict(String, String),
dict.Dict(String, String),
),
String,
)
Reads a graph from a GraphML file.
This is a convenience function that reads node and edge data as
string dictionaries. For custom data types, use graphml.read_with.
Example
let assert Ok(graph) = yog_io.read_graphml("graph.graphml")
// Access node data
import gleam/dict
let node1_data = dict.get(graph.nodes, 1)
pub const string_type: graphml.AttributeType
pub fn write_gdf(
path: String,
graph: model.Graph(String, String),
) -> Result(Nil, simplifile.FileError)
Writes a graph to a GDF file.
This is a convenience function for graphs with string data.
For custom data types, use gdf.write_with.
Example
import yog/model.{Directed}
let graph =
model.new(Directed)
|> model.add_node(1, "Alice")
|> model.add_node(2, "Bob")
let assert Ok(graph) = model.add_edge(graph, from: 1, to: 2, with: "5")
let assert Ok(Nil) = yog_io.write_gdf("graph.gdf", graph)
pub fn write_graphml(
path: String,
graph: model.Graph(String, String),
) -> Result(Nil, simplifile.FileError)
Writes a graph to a GraphML file.
This is a convenience function for graphs with string data.
For custom data types, use graphml.write_with.
Example
import yog/model.{Directed}
let graph =
model.new(Directed)
|> model.add_node(1, "Alice")
|> model.add_node(2, "Bob")
let assert Ok(graph) = model.add_edge(graph, from: 1, to: 2, with: "5")
let assert Ok(Nil) = yog_io.write_graphml("graph.graphml", graph)