Ejemplo n.º 1
0
        /**
         * /// given edges e1 and e2 from node n to nodes n1 and n2
         * /// <p/>
         * /// merge e1 and e2, that is, merge the scores of e1 and e2 create n' that is a merge of n1 and n2 add n' add edge e'
         * /// from n to n'
         * /// <p/>
         * /// remove n1 and n2 and all associated edges
         *
         * /// @param n
         * /// @param e1
         * /// @param e2
         */
        protected void mergeNodesAndEdgesForward(Node n, Edge e1, Edge e2)
        {
            Trace.Assert(lattice.hasNode(n));
            Trace.Assert(lattice.hasEdge(e1));
            Trace.Assert(lattice.hasEdge(e2));

            Trace.Assert(e1.getFromNode() == n);
            Trace.Assert(e2.getFromNode() == n);

            Node n1 = e1.getToNode();
            Node n2 = e2.getToNode();

            Trace.Assert(n1.hasEquivalentEnteringEdges(n1));
            Trace.Assert(n1.getWord().Equals(n2.getWord()));

            // merge the scores of e1 and e2 into e1
            e1.setAcousticScore(mergeAcousticScores
                                    (e1.getAcousticScore(), e2.getAcousticScore()));
            e1.setLMScore(mergeLanguageScores(e1.getLMScore(),
                                              e2.getLMScore()));

            // add n2's edges to n1
            foreach (Edge e in n2.getLeavingEdges())
            {
                e2 = n1.getEdgeToNode(e.getToNode());
                if (e2 == null)
                {
                    lattice.addEdge(n1, e.getToNode(),
                                    e.getAcousticScore(), e.getLMScore());
                }
                else
                {
                    // if we got here then n1 and n2 had edges to the same node
                    // choose the edge with best score
                    e2.setAcousticScore
                        (mergeAcousticScores
                            (e.getAcousticScore(), e2.getAcousticScore()));
                    e2.setLMScore(mergeLanguageScores(e.getLMScore(),
                                                      e2.getLMScore()));
                }
            }

            // remove n2 and all associated edges
            lattice.removeNodeAndEdges(n2);
        }
Ejemplo n.º 2
0
        /**
         * /// Internal routine used when creating a Lattice from a .LAT file
         *
         * /// @param lattice
         * /// @param tokens
         */
        public static void load(Lattice lattice, StringTokenizer tokens)
        {
            String from  = tokens.nextToken();
            String to    = tokens.nextToken();
            int    score = int.Parse(tokens.nextToken());

            Node fromNode = lattice.getNode(from);

            if (fromNode == null)
            {
                throw new Exception("Edge fromNode \"" + from + "\" does not exist");
            }

            Node toNode = lattice.getNode(to);

            if (toNode == null)
            {
                throw new Exception("Edge toNode \"" + to + "\" does not exist");
            }

            lattice.addEdge(fromNode, toNode, score, 0.0);
        }