private void printQueue(BoundedPriorityQueue <NBestPath> queue) { Trace.WriteLine(""); foreach (NBestPath p in queue) { Trace.WriteLine(p); } }
public List <String> getNbest(int n) { lattice.computeNodePosteriors(1.0f); HashSet <String> result = new HashSet <String>(); BoundedPriorityQueue <NBestPath> queue = new BoundedPriorityQueue <NBestPath>(n); queue.add(new NBestPath("<s>", lattice.getInitialNode(), 0, 0)); while (result.Count < n && queue.size() > 0) { NBestPath path = queue.poll(); if (path.node.Equals(lattice.terminalNode)) { result.Add(path.path); continue; } foreach (Edge e in path.node.getLeavingEdges()) { Node newNode = e.getToNode(); double newForwardScore = path.forwardScore + e.getAcousticScore() + e.getLMScore(); double newScore = newForwardScore + newNode.getBackwardScore(); String newPathString = getNewPathString(path, newNode); NBestPath newPath = new NBestPath(newPathString, newNode, newScore, newForwardScore); queue.add(newPath); } // printQueue(queue); } return(result.ToList()); }