Program: 19526
Project: 19526
Buggy source:
/** 
 * Determinizes an fst. The result will be an equivalent fst that has the property that no state has two transitions with the same input label. For this algorithm, epsilon transitions are treated as regular symbols.
 * @param fst the fst to determinize
 * @return the determinized fst
 */
public static Fst get(Fst fst){
  if (fst.getSemiring() == null) {
    return null;
  }
  Semiring semiring=fst.getSemiring();
  Fst res=new Fst(semiring);
  res.setIsyms(fst.getIsyms());
  res.setOsyms(fst.getOsyms());
  Queue<ArrayList<Pair<State,Float>>> queue=new LinkedList<ArrayList<Pair<State,Float>>>();
  HashMap<String,State> stateMapper=new HashMap<String,State>();
  State s=new State(semiring.zero());
  String stateString="String_Node_Str" + fst.getStart() + "String_Node_Str"+ semiring.one()+ "String_Node_Str";
  queue.add(new ArrayList<Pair<State,Float>>());
  queue.peek().add(new Pair<State,Float>(fst.getStart(),semiring.one()));
  res.addState(s);
  stateMapper.put(stateString,s);
  res.setStart(s);
  while (!queue.isEmpty()) {
    ArrayList<Pair<State,Float>> p=queue.remove();
    State pnew=getStateLabel(p,stateMapper);
    queue.remove(0);
    ArrayList<Integer> labels=getUniqueLabels(fst,p);
    for (    int label : labels) {
      Float wnew=semiring.zero();
      for (      Pair<State,Float> ps : p) {
        State old=ps.getLeft();
        Float u=ps.getRight();
        int numArcs=old.getNumArcs();
        for (int j=0; j < numArcs; j++) {
          Arc arc=old.getArc(j);
          if (label == arc.getIlabel()) {
            wnew=semiring.plus(wnew,semiring.times(u,arc.getWeight()));
          }
        }
      }
      ArrayList<Pair<State,Float>> forQueue=new ArrayList<Pair<State,Float>>();
      for (      Pair<State,Float> ps : p) {
        State old=ps.getLeft();
        Float u=ps.getRight();
        Float wnewRevert=semiring.divide(semiring.one(),wnew);
        int numArcs=old.getNumArcs();
        for (int j=0; j < numArcs; j++) {
          Arc arc=old.getArc(j);
          if (label == arc.getIlabel()) {
            State oldstate=arc.getNextState();
            Pair<State,Float> pair=getPair(forQueue,oldstate,semiring.zero());
            pair.setRight(semiring.plus(pair.getRight(),semiring.times(wnewRevert,semiring.times(u,arc.getWeight()))));
          }
        }
      }
      String qnewid="String_Node_Str";
      for (      Pair<State,Float> ps : forQueue) {
        State old=ps.getLeft();
        Float unew=ps.getRight();
        if (!qnewid.equals("String_Node_Str")) {
          qnewid=qnewid + "String_Node_Str";
        }
        qnewid=qnewid + "String_Node_Str" + old+ "String_Node_Str"+ unew+ "String_Node_Str";
      }
      if (stateMapper.get(qnewid) == null) {
        State qnew=new State(semiring.zero());
        res.addState(qnew);
        stateMapper.put(qnewid,qnew);
        Float fw=qnew.getFinalWeight();
        for (        Pair<State,Float> ps : forQueue) {
          fw=semiring.plus(fw,semiring.times(ps.getLeft().getFinalWeight(),ps.getRight()));
        }
        qnew.setFinalWeight(fw);
        queue.add(forQueue);
      }
      pnew.addArc(new Arc(label,label,wnew,stateMapper.get(qnewid)));
    }
  }
  return res;
}

Fixed version (ground truth):
/** 
 * Determinizes an fst. The result will be an equivalent fst that has the property that no state has two transitions with the same input label. For this algorithm, epsilon transitions are treated as regular symbols.
 * @param fst the fst to determinize
 * @return the determinized fst
 */
public static Fst get(Fst fst){
  if (fst.getSemiring() == null) {
    return null;
  }
  Semiring semiring=fst.getSemiring();
  Fst res=new Fst(semiring);
  res.setIsyms(fst.getIsyms());
  res.setOsyms(fst.getOsyms());
  Queue<ArrayList<Pair<State,Float>>> queue=new LinkedList<ArrayList<Pair<State,Float>>>();
  HashMap<String,State> stateMapper=new HashMap<String,State>();
  State s=new State(semiring.zero());
  String stateString="String_Node_Str" + fst.getStart() + "String_Node_Str"+ semiring.one()+ "String_Node_Str";
  queue.add(new ArrayList<Pair<State,Float>>());
  queue.peek().add(new Pair<State,Float>(fst.getStart(),semiring.one()));
  res.addState(s);
  stateMapper.put(stateString,s);
  res.setStart(s);
  while (!queue.isEmpty()) {
    ArrayList<Pair<State,Float>> p=queue.remove();
    State pnew=getStateLabel(p,stateMapper);
    ArrayList<Integer> labels=getUniqueLabels(fst,p);
    for (    int label : labels) {
      Float wnew=semiring.zero();
      for (      Pair<State,Float> ps : p) {
        State old=ps.getLeft();
        Float u=ps.getRight();
        int numArcs=old.getNumArcs();
        for (int j=0; j < numArcs; j++) {
          Arc arc=old.getArc(j);
          if (label == arc.getIlabel()) {
            wnew=semiring.plus(wnew,semiring.times(u,arc.getWeight()));
          }
        }
      }
      ArrayList<Pair<State,Float>> forQueue=new ArrayList<Pair<State,Float>>();
      for (      Pair<State,Float> ps : p) {
        State old=ps.getLeft();
        Float u=ps.getRight();
        Float wnewRevert=semiring.divide(semiring.one(),wnew);
        int numArcs=old.getNumArcs();
        for (int j=0; j < numArcs; j++) {
          Arc arc=old.getArc(j);
          if (label == arc.getIlabel()) {
            State oldstate=arc.getNextState();
            Pair<State,Float> pair=getPair(forQueue,oldstate,semiring.zero());
            pair.setRight(semiring.plus(pair.getRight(),semiring.times(wnewRevert,semiring.times(u,arc.getWeight()))));
          }
        }
      }
      String qnewid="String_Node_Str";
      for (      Pair<State,Float> ps : forQueue) {
        State old=ps.getLeft();
        Float unew=ps.getRight();
        if (!qnewid.equals("String_Node_Str")) {
          qnewid=qnewid + "String_Node_Str";
        }
        qnewid=qnewid + "String_Node_Str" + old+ "String_Node_Str"+ unew+ "String_Node_Str";
      }
      if (stateMapper.get(qnewid) == null) {
        State qnew=new State(semiring.zero());
        res.addState(qnew);
        stateMapper.put(qnewid,qnew);
        Float fw=qnew.getFinalWeight();
        for (        Pair<State,Float> ps : forQueue) {
          fw=semiring.plus(fw,semiring.times(ps.getLeft().getFinalWeight(),ps.getRight()));
        }
        qnew.setFinalWeight(fw);
        queue.add(forQueue);
      }
      pnew.addArc(new Arc(label,label,wnew,stateMapper.get(qnewid)));
    }
  }
  return res;
}