private void PrintQueue(BoundedPriorityQueue <NBestPath> queue) { this.LogInfo(""); foreach (NBestPath p in queue) { this.LogInfo(p); } }
public ICollection <String> GetNbest(int n) { Lattice.ComputeNodePosteriors(1.0f); HashSet <String> result = new HashSet <String>(); var queue = new BoundedPriorityQueue <NBestPath>(n); queue.Add(new NBestPath("<s>", Lattice.InitialNode, 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.LeavingEdges) { Node newNode = e.ToNode; double newForwardScore = path.ForwardScore + e.AcousticScore + e.LMScore; double newScore = newForwardScore + newNode.BackwardScore; string newPathString = GetNewPathString(path, newNode); NBestPath newPath = new NBestPath(newPathString, newNode, newScore, newForwardScore); queue.Add(newPath); } // printQueue(queue); } return(result); }