#parser #gml

gml_parser

A fast and simple Graph Modeling Language (GML) parser

2 releases

0.1.1 Dec 9, 2022
0.1.0 Nov 24, 2022

#1428 in Data structures

MIT license

22KB
479 lines

Parser for Graph Modeling Language (https://en.wikipedia.org/wiki/Graph_Modelling_Language). This can efficiently read and parse GML files into a Graph data structure containing Nodes and Edges.

Please check out the docs at: https://docs.rs/gml_parser/latest/gml_parser/

I'm open to PRs to improve this if you have ideas.

If you can find a proper specifiation the GML grammar, that would be highly appreciated. I just made up the grammar file to best match what I understand GML to look like.


lib.rs:

This crate allows for reading Graph Modeling Language (GML) files.

This crate first parses the GML into [GMLObject]s and [GMLValue]s. Then the root GMLObject can be transformed into a [Graph] containing [Node]s and [Edge]s.

Examples

use gml_parser::{GMLObject, Graph};

let data = r#"
graph [            
   id 4           
   node [         
       id 0       
   ]              
   node [         
       id 1       
   ]              
   edge [         
       source 1   
       target 0   
       label "Edge"
   ]              
]"#;
let root = GMLObject::from_str(data).unwrap();
let graph = Graph::from_gml(root).unwrap();
assert_eq!(graph.id, Some(4));
assert_eq!(graph.nodes.len(), 2);
assert_eq!(graph.edges.len(), 1);

Limitations

  • This implementation can be fragile and GML is not a very picky standard
  • We duplicate the data when parsing which can have performance impacts on very large graphs

Dependencies

~4–6MB
~109K SLoC