GML and Lua

Graph Modelling Language (GML) is a declarative format that is accepted by a variety of network analysis packages. I’ve recently found myself in a position where I want to do a variety of processing and translation tasks with GML files. For example, I really like yEd for graph layout, so I wanted to use yEd to import a GML file describing a graph, make a nice layout, export the result back to GML, and then produce a nice picture with TikZ for use in a presentation. Along the way, I also wanted to generate the adjacency matrix for the graph in a form that I could load into MATLAB.

Unfortunately, when I read a GML file into yEd and then write out a GML file, I lose any information that yEd doesn’t care about. And while it’s easy enough to write stupid scripts to do things like turning a GML file into a MATLAB adjacency matrix, it’s decidedly messier to do something that involves combining a source GML file, some MATLAB vectors representing node properties, and an output GML file from yEd.

Fortunately for me, the syntax of a configuration file in GML reminded me an awful lot of the syntax of configuration files written in Lua. I’ve been a fan of the Lua programming language for a long time, and have used it as the input language for a couple of my finite element codes. It’s a small, fast language that was built for embedding into bigger codes. It grew out of a configuration language for finite element codes, and it still makes an excellent configuration language. And, as it turns out, it makes an excellent language for the sorts of processing tasks that I wanted to do with the GML files on my drive.

Enter gmllua, an extremely simple Lua-based system for processing GML files. It didn’t take much time to write, because there’s not much to it: just a parser to convert GML files to Lua data structures, and some functions that walk over the resulting tree and produce useful output. But that’s all I really needed.

Comments

blog comments powered by Disqus
Fork me on GitHub