Ejemplo n.º 1
0
 /** Remove all Nodes that have no Edges to them (but not <s>) */
 protected void removeHangingNodes()
 {
     foreach (Node n in lattice.getCopyOfNodes())
     {
         if (lattice.hasNode(n))
         {
             if (n == lattice.getInitialNode())
             {
             }
             else if (n == lattice.getTerminalNode())
             {
             }
             else
             {
                 if (n.getLeavingEdges().Count == 0 ||
                     n.getEnteringEdges().Count == 0)
                 {
                     lattice.removeNodeAndEdges(n);
                     removeHangingNodes();
                     return;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
 /**
  * /// Returns true if the given Lattice is equivalent to this Lattice. Two lattices are equivalent if all their nodes
  * /// and edges are equivalent.
  *
  * /// @param other the Lattice to compare this Lattice against
  * /// @return true if the Lattices are equivalent; false otherwise
  */
 public Boolean isEquivalent(Lattice other)
 {
     return(checkNodesEquivalent(initialNode, other.getInitialNode()));
 }