예제 #1
0
        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);
        }
예제 #2
0
        private void printQueue(BoundedPriorityQueue boundedPriorityQueue)
        {
            [email protected]();
            Iterator iterator = boundedPriorityQueue.iterator();

            while (iterator.hasNext())
            {
                Nbest.NBestPath nbestPath = (Nbest.NBestPath)iterator.next();
                [email protected](nbestPath);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
 public int compareTo(Nbest.NBestPath nbestPath)
 {
     return(Double.compare(this.score, nbestPath.score));
 }