Skip to main content

write_graphml

Function write_graphml 

Source
pub fn write_graphml(
    nodes: &[NodeInfo],
    edges: &[ExportEdge],
    dest: &Path,
) -> Result<PathBuf, CliError>
Expand description

Write a single GraphML file describing nodes and edges.

Nodes carry label plus every property (lists/maps JSON-encoded as string-typed text). Edges carry type, derived, and — when present — rule and weight. <key> elements are declared once per (for, name) pair, node keys before edge keys, each block sorted by attribute name. Key ids are XML-name-safe (n_<prop> / e_<prop>, sanitized); the original name is preserved in attr.name. A node property literally named label shares the n_label key (and <data> slot) with the built-in label field — an accepted collision, since mushroomdb’s schema reserves label for the node’s type name.

Type declaration: a node property’s attr.type is [value_gml_type] of its value where every node reporting that property name agrees on the Value variant; if two nodes disagree (e.g. one has Value::Int under score, another Value::Str), the key declares attr.type="string" for every node — a safe fallback, since string can hold any value’s text form — rather than picking one node’s type and risking a value that doesn’t fit it. Value::Int (a 64-bit i64) declares attr.type="long", not "int", since GraphML’s informal convention treats "int" as 32-bit and "long" is the interoperable choice for the full range.

nodes must be sorted by key and edges by (edge_type, src, dst) — same precondition as write_jsonl. Two runs on the same sorted input produce byte-identical output: edge ids (e0, e1, …) are assigned in that sorted order.

Rules have no GraphML representation; only nodes and edges are exported. See [resolve_graphml_dest] for how dest maps to the output file path.