private List<ParseResult> findBestParses(List<ParseResult> all, Exp e) { List<ParseResult> best = new LinkedList<ParseResult>(); double bestScore = -Double.MAX_VALUE; for (ParseResult p : all) { if (p.getExp().inferType() != null) { if ((e == null || p.getExp().equals(e))) { if (p.getScore() == bestScore) best.add(p); if (p.getScore() > bestScore) { bestScore = p.getScore(); best.clear(); best.add(p); } } } } return best; }
public static List tokenize(String input) { // first tokenize the string List tokens = new LinkedList(); StringTokenizer st = new StringTokenizer(input); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); } return tokens; }
private List<ParseResult> removeRepeats(List<ParseResult> all) { System.out.println("----------------------- all.size equals to --------------" + all.size()); List<ParseResult> bestList = new LinkedList<ParseResult>(); for (int i = 0; i < all.size(); i++) { ParseResult e_i = all.get(i); boolean best = true; for (int j = i + 1; j < all.size(); j++) { ParseResult e_j = all.get(j); if (e_i.getExp().equals(e_j.getExp()) && e_i.getScore() <= e_j.getScore()) { best = false; break; } } if (best) bestList.add(e_i); } return bestList; }