Friday, March 7, 2008

Freemind map <--> lisp (perl, python) list convertion (I,II)


Intro:


I am using Freemind on regular basis, for storing ideas, notes, and planning.It is an ideal tool for the manipulating tree like structures as simple, as it can be done with plain text, and even simpler, due to the Freemind intuitive shortcuts.

In fact, file in Freemind .mm can be processed as XML (if ignore some details, like header, and html that can present inside nodes, maybe something another can be also) using XSLT transform, or in any programming language with access to XML parsing.

I want lists structures being presented by Freemind, and back,
Freemind trees being presented in list-like structures, like following: ((1 2 ) 3 (4 (5 6)) 7 8).

Part I. list to freemind converter.



I have simply modified one of previously presented programs, there : nested list implementation

Instead of writing "[" I wrote <node> tag with empty TEXT attribute, simply for anonymous fork inside Freemind:
$ret .= "<node ID=\"Perl_GEN".$id."\" TEXT=\"".$listp."\" />\n";


Also beginning and header of freemind map written in corresponding places of program.
That is
<map version="0.9.0_Beta_8">
and closing of the tag.

For the list:
$al = [1, [2, [3], 4], 5];


I have obtained:


Part II. Freemind to plain list converter.


Lets start from presentation of Freemind tree nodes in one not nested lisp list (no round brackets, '(' and ')' inside list):

Lets look inside of Freemind map:
$ cat map.mm | head
First too lines describe program and format.
Than <node> tags follow.
We need only the text field from node.

So XSLT transformer of mm to plain list, ignoring tree structure can look like following:
xslt simple.

$ xsltproc map_lisp_list_s.xsl ~/map.mm | perl -e "<>; while(<>){print;}"
(
"map"
"check"
"check1"
"check2"
"check3"
"ch3ch1"
"node"
"subnode1"
"subnode2"
"trnode" )

Perl was simply used to strip one line from beginning.

Part III,

that is Freemind to tree list will be described further.

No comments: