Created
May 4, 2012 12:26
-
-
Save rbramley/2594516 to your computer and use it in GitHub Desktop.
Quick & dirty Groovy scripts for processing Freemind leaf nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copying and distribution of this file, with or without modification, | |
* are permitted in any medium without royalty provided the copyright | |
* notice and this notice are preserved. This file is offered as-is, | |
* without any warranty. | |
* | |
* @author Robin Bramley (c) 2012 | |
* | |
* Groovy script to walk a Freemind node tree and count occurrences of leaf terms. | |
*/ | |
// increment counters | |
def assessNode(node, map) { | |
if(node.toString() == 'Small') { map.small++ } | |
else if (node.toString() == 'Medium') { map.medium++ } | |
else if (node.toString() == 'Large') { map.large++ } | |
} | |
// recurse and process leaf nodes | |
def walkNodeChildren(node, map) { | |
if (node.hasChildren()) { | |
def children = node.childrenUnfolded() | |
children.each { child -> | |
walkNodeChildren(child, map) | |
} | |
} else { | |
assessNode(node, map) | |
} | |
} | |
// counters | |
def counterMap = [small:0, medium:0, large:0] | |
// run | |
walkNodeChildren(node, counterMap) | |
// prepare node text update | |
def nT = node.getText() | |
def output = "Small: ${counterMap.small}\nMedium: ${counterMap.medium}\nLarge: ${counterMap.large}" | |
def crPos = nT.indexOf('\n') | |
if(crPos == -1) { | |
node.setText("${nT}\n${output}") | |
} else { | |
nLabel = nT.substring(0,crPos) | |
node.setText("${nLabel}\n${output}") | |
} | |
// repaint | |
c.nodeChanged(node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copying and distribution of this file, with or without modification, | |
* are permitted in any medium without royalty provided the copyright | |
* notice and this notice are preserved. This file is offered as-is, | |
* without any warranty. | |
* | |
* @author Robin Bramley (c) 2012 | |
* | |
* Groovy script to walk a Freemind node tree and sum attributes from leaf nodes. | |
*/ | |
// increment counters | |
def assessNode(node, map) { | |
// get the table model | |
def atts = node.getAttributes() | |
def c = atts.rowCount | |
for (i=0; i<c; i++) { | |
def rowName = atts.getName(i) | |
def rowValue = Integer.parseInt(atts.getValue(i)) | |
map[rowName] += rowValue | |
} | |
} | |
// recurse and process leaf nodes | |
def walkNodeChildren(node, map) { | |
if (node.hasChildren()) { | |
def children = node.childrenUnfolded() | |
children.each { child -> | |
walkNodeChildren(child, map) | |
} | |
} else { | |
assessNode(node, map) | |
} | |
} | |
// counters | |
def counterMap = ["50":0, "90":0] | |
// run | |
walkNodeChildren(node, counterMap) | |
// update totals | |
node.attributes.setValue(0,counterMap['50']) | |
node.attributes.setValue(1,counterMap['90']) | |
// repaint | |
c.nodeChanged(node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment