public virtual Collection getNbest(int n) { HashSet hashSet = new HashSet(); BoundedPriorityQueue boundedPriorityQueue = new BoundedPriorityQueue(n); boundedPriorityQueue.add(new Nbest.NBestPath(this, "<s>", this.lattice.getInitialNode(), (double)0f, (double)0f)); while (hashSet.size() < n && boundedPriorityQueue.size() > 0) { Nbest.NBestPath nbestPath = (Nbest.NBestPath)boundedPriorityQueue.poll(); if (nbestPath.node.equals(this.lattice.terminalNode)) { hashSet.add(nbestPath.path); } else { Iterator iterator = nbestPath.node.getLeavingEdges().iterator(); while (iterator.hasNext()) { Edge edge = (Edge)iterator.next(); Node toNode = edge.getToNode(); double num = nbestPath.forwardScore + edge.getAcousticScore() + edge.getLMScore(); double num2 = num + toNode.getBackwardScore(); string newPathString = this.getNewPathString(nbestPath, toNode); Nbest.NBestPath item = new Nbest.NBestPath(this, newPathString, toNode, num2, num); boundedPriorityQueue.add(item); } } } return(hashSet); }
private void printQueue(BoundedPriorityQueue boundedPriorityQueue) { [email protected](); Iterator iterator = boundedPriorityQueue.iterator(); while (iterator.hasNext()) { Nbest.NBestPath nbestPath = (Nbest.NBestPath)iterator.next(); [email protected](nbestPath); } }
private string getNewPathString(Nbest.NBestPath nbestPath, Node node) { string result; if (node.getWord().isSentenceEndWord()) { result = new StringBuilder().append(nbestPath.path).append(" </s>").toString(); } else if (node.getWord().isFiller()) { result = nbestPath.path; } else { result = new StringBuilder().append(nbestPath.path).append(" ").append(node.getWord()).toString(); } return(result); }
public int compareTo(Nbest.NBestPath nbestPath) { return(Double.compare(this.score, nbestPath.score)); }