public String toRTEDString(){ return treeRTED(fRoot, new StringBuffer()); } }
/** * Returns an AST Representation suited for using the RTED, Robust Tree Edit Distance Algorithm * (http://www.inf.unibz.it/dis/projects/tree-edit-distance/documentation.php) * Format of Tree Structure : {root{node{node}}{node}...} */ private String treeRTED(Node n, StringBuffer buffer){ if(n!= null){ //Root Node if(n.isRoot()){ buffer.append("{" +n.getValue().toString().replaceAll("\\s+", "")); } for (int i=0; i < n.getChildCount(); i++){ Node node = (Node)n.getChildAt(i); //Remove the spaces from the name of node labels buffer.append("{" +node.getValue().toString().replaceAll("\\s+", "")); if(!node.isLeaf()){ treeRTED(node,buffer); buffer.append("}"); } else buffer.append("}}"); } } return buffer.toString(); }