yEd is a nice free editor for drawing flow charts and other diagrams. For example this very simple drawing.
yEd saves, usually, it’s drawing in graphML format (for example). Which provides us with a nice chance to chew on the drawing for other purposes. For example we might convert charts into programs, rdf, ontologies, etc.
Inspired by Paul Tarvydas’ short lightning talk at ILC 2004 I thought it would be fun to write some code that eats the graphml files.
The code here loads the graphML, creating a reasonably clean sexpr; that looks something like this:
(:graphml ((:schemalocation . 1.1))
(:key ((:yfiles.type "resources") (:id . 0) (:for . :graphml)))
...
(:graph ((:id "G") (:edgedefault "directed"))
...
(:node ((:id . 0)) (:data ((:key . 5)))
(:data ((:key . 6))
(:shapenode nil
(:geometry ((:y . 36.0) ...))
(:fill (...))
(:borderstyle (...))
(:nodelabel
((:y . 5.93359375) (:x . 28.8125) (:width . 37.375) ...)
"Alpha"
(:labelmodel ...)
(:modelparameter ...)) ...)))
...
(:edge ((:target . 2) (:source . 0) (:id . 0)) (:data ((:key . 9)))
(:data ((:key . 10))
(:splineedge nil
(:path ((:ty . 0.0) ...))
(:linestyle (...))
(:arrows (...)))))
...))
There is bit of code to extract the topology (nodes and edges) from sexpressions like that.
The shell script topology.sh, which uses cl-launch to print all the edges.
bash-3.2$ ./topology.sh abc.graphml
Alpha -> Beta
Beta -> Cancel
Beta -> Beta
Beta -> Beta
bash-3.2$
You can also eval the function main in file and then run something like this:
> (cl-user::main '("/Users/luser/w/yd-lisp/abc.graphml"))
Alpha -> Beta
Beta -> Cancel
Beta -> Beta
Beta -> Beta
Which illustrates that there are two extra edges in the abc.graphml that do not appear in the drawing. Mysteries[fn:1] abound.
[fn:1] Ah, it’s yEd feature/bug, discussed here.