private static string GetNewPathString(NBestPath path, Node newNode) { string newPathString; if (newNode.Word.IsSentenceEndWord) { newPathString = path.Path + " </s>"; } else if (newNode.Word.IsFiller) { newPathString = path.Path; } else { newPathString = path.Path + " " + newNode.Word; } return(newPathString); }
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); }