GraphML Module
GraphML (Graph Markup Language) serialization support.
Provides functions to serialize and deserialize graphs in the GraphML format, an XML-based format widely supported by graph visualization and analysis tools like Gephi, yEd, Cytoscape, and NetworkX.
Example
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
|
<summary> Core graph data structures and basic operations for the yog library. This module defines the fundamental `Graph` type and provides all basic operations for creating and manipulating graphs. The graph uses an adjacency list representation with dual indexing (both outgoing and incoming edges) for efficient traversal in both directions. </summary>
<summary> Creates a new empty graph of the specified type. ## Example let graph = Model.empty Directed ## Parameters - `graphType`: The type of the graph. ## Returns A new empty graph. </summary>
<summary> A directed graph where edges have a direction from source to destination. </summary>
<summary> Adds a node to the graph with the given ID and data. If a node with this ID already exists, its data will be replaced. ## Example graph |> addNode 1 "Node A" |> addNode 2 "Node B" ## Parameters - `id`: The unique identifier for the node. - `data`: The data to store at the node. - `graph`: The graph to add the node to. ## Returns A new graph with the node added. </summary>
<summary> Adds an edge to the graph with the given weight. For directed graphs, adds a single edge from src to dst. For undirected graphs, adds edges in both directions. ## Example graph |> addEdge 1 2 10 **Note:** If `src` or `dst` have not been added via `addNode`, an `ArgumentException` is thrown. To automatically create missing endpoints when adding an edge, use `addEdgeEnsured` or `addEdgeEnsuredWith`. ## Parameters - `src`: The source node ID. - `dst`: The destination node ID. - `weight`: The weight of the edge. - `graph`: The graph to add the edge to. ## Returns A new graph with the edge added. </summary>
<summary> GraphML (Graph Markup Language) serialization support. Provides functions to serialize and deserialize graphs in the GraphML format, an XML-based format widely supported by graph visualization and analysis tools like Gephi, yEd, Cytoscape, and NetworkX. ## Example open Yog.IO open Yog.Model // Create a simple graph let graph = empty Directed |> addNode 1 "Alice" |> addNode 2 "Bob" |> addEdge 1 2 5 // Serialize to GraphML let xml = GraphML.serialize graph File.WriteAllText("graph.graphml", xml) // Deserialize from GraphML let loaded = File.ReadAllText("graph.graphml") |> GraphML.deserialize </summary>
<summary> Serializes a graph to a GraphML string. This is a simplified version of `serializeWith` for graphs where node data and edge data are already strings. **Time Complexity:** O(V + E) ## Example let graph = empty Directed |> addNode 1 "Alice" |> addNode 2 "Bob" |> addEdge 1 2 "5" let xml = GraphML.serialize graph // <?xml version="1.0" encoding="utf-8"?> // <graphml xmlns="http://graphml.graphdrawing.org/xmlns"> // <key id="label" for="node" attr.name="label" attr.type="string" /> // <key id="weight" for="edge" attr.name="weight" attr.type="string" /> // <graph id="G" edgedefault="directed"> // <node id="1"><data key="label">Alice</data></node> // <node id="2"><data key="label">Bob</data></node> // <edge source="1" target="2"><data key="weight">5</data></edge> // </graph> // </graphml> </summary>
<summary> Deserializes a GraphML string to a graph. This is a simplified version of `deserializeWith` for graphs where you want node data and edge data as string maps containing all attributes. **Time Complexity:** O(V + E) ## Example let xml = File.ReadAllText("graph.graphml") let graph = GraphML.deserialize xml // Access node data let node1Data = graph.Nodes.[1] // Map<string, string> let label = Map.tryFind "label" node1Data </summary>
Functions and values
| Function or value |
Description
|
||
|
Deserializes a GraphML string to a graph. This is a simplified version of Time Complexity: O(V + E)
Example
val xml: obj
val graph: obj
val node1Data: Map<string,obj>
val label: obj option
Multiple items
module Map from Microsoft.FSharp.Collections -------------------- type Map<'Key,'Value (requires comparison)> = interface IReadOnlyDictionary<'Key,'Value> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable interface IStructuralEquatable interface IComparable interface IEnumerable<KeyValuePair<'Key,'Value>> interface ICollection<KeyValuePair<'Key,'Value>> interface IDictionary<'Key,'Value> new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> member Add: key: 'Key * value: 'Value -> Map<'Key,'Value> ... -------------------- new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> val tryFind: key: 'Key -> table: Map<'Key,'T> -> 'T option (requires comparison)
|
||
|
Deserializes GraphML string back into a Yog Graph with custom data mappers. This function allows you to control how GraphML attributes are converted
to your node and edge data types. Use Time Complexity: O(V + E)
Example
type Person =
{
Name: string
Age: int
}
Multiple items
val string: value: 'T -> string -------------------- type string = System.String Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val nodeFolder: data: Map<string,string> -> Person
val data: Map<string,string>
Multiple items
module Map from Microsoft.FSharp.Collections -------------------- type Map<'Key,'Value (requires comparison)> = interface IReadOnlyDictionary<'Key,'Value> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable interface IStructuralEquatable interface IComparable interface IEnumerable<KeyValuePair<'Key,'Value>> interface ICollection<KeyValuePair<'Key,'Value>> interface IDictionary<'Key,'Value> new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> member Add: key: 'Key * value: 'Value -> Map<'Key,'Value> ... -------------------- new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> val tryFind: key: 'Key -> table: Map<'Key,'T> -> 'T option (requires comparison)
module Option
from Microsoft.FSharp.Core
val defaultValue: value: 'T -> option: 'T option -> 'T
val map: mapping: ('T -> 'U) -> option: 'T option -> 'U option
val edgeFolder: data: Map<string,string> -> string
val xml: obj
val graph: obj
|
||
|
Reads a graph from a GraphML file.
Example
val graph: obj
Multiple items
module Map from Microsoft.FSharp.Collections -------------------- type Map<'Key,'Value (requires comparison)> = interface IReadOnlyDictionary<'Key,'Value> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable interface IStructuralEquatable interface IComparable interface IEnumerable<KeyValuePair<'Key,'Value>> interface ICollection<KeyValuePair<'Key,'Value>> interface IDictionary<'Key,'Value> new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> member Add: key: 'Key * value: 'Value -> Map<'Key,'Value> ... -------------------- new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> Multiple items
val string: value: 'T -> string -------------------- type string = System.String val id: int
val data: obj
val toSeq: table: Map<'Key,'T> -> ('Key * 'T) seq (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
|
||
|
Reads a graph from a GraphML file with custom data mappers.
Example
type Person =
{
Name: string
Age: int
}
Multiple items
val string: value: 'T -> string -------------------- type string = System.String Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val nodeFolder: data: Map<string,string> -> Person
val data: Map<string,string>
Multiple items
module Map from Microsoft.FSharp.Collections -------------------- type Map<'Key,'Value (requires comparison)> = interface IReadOnlyDictionary<'Key,'Value> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable interface IStructuralEquatable interface IComparable interface IEnumerable<KeyValuePair<'Key,'Value>> interface ICollection<KeyValuePair<'Key,'Value>> interface IDictionary<'Key,'Value> new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> member Add: key: 'Key * value: 'Value -> Map<'Key,'Value> ... -------------------- new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> val tryFind: key: 'Key -> table: Map<'Key,'T> -> 'T option (requires comparison)
module Option
from Microsoft.FSharp.Core
val defaultValue: value: 'T -> option: 'T option -> 'T
val map: mapping: ('T -> 'U) -> option: 'T option -> 'U option
val edgeFolder: data: Map<string,string> -> int
val graph: obj
|
||
|
Serializes a graph to a GraphML string. This is a simplified version of Time Complexity: O(V + E)
Example
val graph: obj
val xml: obj
|
||
Full Usage:
serializeWith nodeAttr edgeAttr graph
Parameters:
'n -> (string * string) list
edgeAttr : 'e -> (string * string) list
graph : Graph<'n, 'e>
Returns: string
|
Renders a graph to a GraphML string with custom attribute mappers. This function allows you to control how node and edge data are converted
to GraphML attributes. Use Time Complexity: O(V + E)
Example
Use Cases
type Person =
{
Name: string
Age: int
}
Multiple items
val string: value: 'T -> string -------------------- type string = System.String Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type Connection =
{
Weight: int
Type: string
}
val graph: obj
val nodeAttrs: p: Person -> (string * string) list
val p: Person
Person.Name: string
Person.Age: int
val edgeAttrs: c: Connection -> (string * string) list
val c: Connection
Connection.Weight: int
Connection.Type: string
val xml: obj
|
||
|
Writes a graph to a GraphML file.
Example
val graph: obj
|
||
Full Usage:
writeFileWith nodeAttr edgeAttr path graph
Parameters:
'n -> (string * string) list
edgeAttr : 'e -> (string * string) list
path : string
graph : Graph<'n, 'e>
|
Writes a graph to a GraphML file with custom attribute mappers.
Example
type Person =
{
Name: string
Age: int
}
Multiple items
val string: value: 'T -> string -------------------- type string = System.String Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val graph: obj
|