@@ -0,0 +1,1624 @@
+package joshua.decoder.hypergraph;%0A%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Stack;%0A%0Aimport joshua.decoder.chart_parser.SourcePath;%0Aimport joshua.decoder.ff.state_maintenance.DPState;%0Aimport joshua.decoder.ff.tm.Rule;%0A%0Apublic class StringToTreeConverter %7B%0A%09%0A%09static private final String beginSymbol = %22(b%22; %0A%09static private final String nodeSymbol =%22node%22;%0A%09%0A%09HyperGraph convert(String inputStr)%7B%0A%0A%09%09HyperGraph tree = null;%0A%09%09%0A%09%09Stack%3CString%3E stack = new Stack%3CString%3E();%0A%09%09for(int i=0; i%3CinputStr.length(); i++)%7B%0A%09%09%09char curChar = inputStr.charAt(i);%0A%09%09%09%0A%09%09%09if(curChar ==')' && inputStr.charAt(i-1)!=' ')%7B//end of a rule%0A%09%09%09%09StringBuffer ruleString = new StringBuffer();%0A%09%09%09%09List%3CHGNode%3E antNodes = null;%0A%09%09%09%09%0A%09%09%09%09while(stack.empty()==false)%7B%0A%09%09%09%09%09String cur = stack.pop();%09%09%09%09%09%0A%09%09%09%09%09if(cur.equals(beginSymbol))%7B//stop%0A%09%09%09%09%09%09//setup a node%0A%09%09%09%09%09%09//HGNode(int i, int j, int lhs, HashMap%3CInteger,DPState%3E dpStates, HyperEdge initHyperedge, double estTotalLogP)%0A%09%09%09%09%09%09//public HyperEdge(Rule rule, double bestDerivationLogP, Double transitionLogP, List%3CHGNode%3E antNodes, SourcePath srcPath)%0A%09%09%09%09%09%09//%09public BilingualRule(int lhs, int%5B%5D sourceRhs, int%5B%5D targetRhs, float%5B%5D featureScores, int arity, int owner, float latticeCost, int ruleID)%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09stack.add(nodeSymbol);//TODO: should be lHS+id%0A%09%09%09%09%09%09break;%0A%09%09%09%09%09%7Delse if(cur.equals(nodeSymbol))%7B%0A%09%09%09%09%09%09%0A%09%09%09%09%09%7Delse%7B%0A%09%09%09%09%09%09ruleString.append(cur);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7Delse if(curChar =='(' && inputStr.charAt(i+1) != ' ')%7B//begin of a rule%0A%09%09%09%09stack.add(beginSymbol);%0A%09%09%09%7Delse%7B%0A%09%09%09%09stack.add(%22%22+curChar);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09%0A%09%09%0A%09%09return tree;%0A%09%7D%0A%0A%7D%0A

add stringtotree converter