public LatticeRescorer(Lattice lattice, LanguageModel model)
 {
     this.languageWeigth = 8f;
     this.__lattice      = lattice;
     this.__model        = model;
     this.depth          = model.getMaxDepth();
 }
示例#2
0
        public static Lattice readSlf(string fileName)
        {
            FileInputStream fileInputStream = new FileInputStream(fileName);
            Lattice         result          = Lattice.readSlf(fileInputStream);

            fileInputStream.close();
            return(result);
        }
示例#3
0
        private static void createEdge(string text, Lattice lattice)
        {
            string[] array = String.instancehelper_split(text, "\\s");
            string   id    = String.instancehelper_substring(array[3], 1, String.instancehelper_length(array[3]) - 1);
            string   id2   = String.instancehelper_substring(array[5], 1, String.instancehelper_length(array[5]) - 1);
            string   text2 = String.instancehelper_substring(array[7], 1, String.instancehelper_length(array[7]) - 1);

            string[] array2 = String.instancehelper_split(text2, ",");
            lattice.addEdge(lattice.getNode(id), lattice.getNode(id2), Double.parseDouble(array2[0]), Double.parseDouble(array2[1]));
        }
示例#4
0
        internal static void load(Lattice lattice, StringTokenizer stringTokenizer)
        {
            string text  = stringTokenizer.nextToken();
            string text2 = stringTokenizer.nextToken();
            long   num   = Long.parseLong(stringTokenizer.nextToken());
            long   num2  = Long.parseLong(stringTokenizer.nextToken());
            Word   word  = new Word(text2, new Pronunciation[0], String.instancehelper_startsWith(text2, "<") || String.instancehelper_startsWith(text2, "["));

            lattice.addNode(text, word, num, num2);
        }
示例#5
0
        public static Lattice getLattice(string gdlFile, Dictionary dictionary)
        {
            Lattice        lattice        = new Lattice();
            BufferedReader bufferedReader = new BufferedReader(new FileReader(gdlFile));
            string         text;

            while ((text = bufferedReader.readLine()) != null)
            {
                if (String.instancehelper_startsWith(text, "node"))
                {
                    GDLLatticeFactory.createNode(text, lattice, dictionary);
                }
                else if (String.instancehelper_startsWith(text, "edge"))
                {
                    GDLLatticeFactory.createEdge(text, lattice);
                }
            }
            bufferedReader.close();
            return(lattice);
        }
示例#6
0
        private static void createNode(string text, Lattice lattice, Dictionary dictionary)
        {
            string[] array = String.instancehelper_split(text, "\\s");
            string   id    = String.instancehelper_substring(array[3], 1, String.instancehelper_length(array[3]) - 1);
            string   text2 = String.instancehelper_substring(array[5], 1);
            string   text3 = String.instancehelper_substring(array[6], 2, String.instancehelper_length(array[6]) - 2);
            string   text4 = String.instancehelper_substring(text2, 0, String.instancehelper_indexOf(text2, 91));

            text2 = String.instancehelper_substring(text2, String.instancehelper_indexOf(text2, 91) + 1);
            string text5 = String.instancehelper_substring(text2, 0, String.instancehelper_indexOf(text2, 44));
            string text6 = String.instancehelper_substring(text2, String.instancehelper_indexOf(text2, 44) + 1);
            Node   node  = lattice.addNode(id, dictionary.getWord(text4), (long)Integer.parseInt(text5), (long)Integer.parseInt(text6));

            node.setPosterior(Double.parseDouble(text3));
            if (String.instancehelper_equals(text4, "<s>"))
            {
                lattice.setInitialNode(node);
            }
            else if (String.instancehelper_equals(text4, "</s>"))
            {
                lattice.setTerminalNode(node);
            }
        }
示例#7
0
        internal static void load(Lattice lattice, StringTokenizer stringTokenizer)
        {
            string text  = stringTokenizer.nextToken();
            string text2 = stringTokenizer.nextToken();
            double num   = Double.parseDouble(stringTokenizer.nextToken());
            double num2  = Double.parseDouble(stringTokenizer.nextToken());
            Node   node  = lattice.getNode(text);

            if (node == null)
            {
                string text3 = new StringBuilder().append("Edge fromNode \"").append(text).append("\" does not exist").toString();

                throw new Error(text3);
            }
            Node node2 = lattice.getNode(text2);

            if (node2 == null)
            {
                string text4 = new StringBuilder().append("Edge toNode \"").append(text2).append("\" does not exist").toString();

                throw new Error(text4);
            }
            lattice.addEdge(node, node2, num, num2);
        }
示例#8
0
 public LatticeOptimizer(Lattice lattice)
 {
     this.__lattice = lattice;
 }
示例#9
0
 public virtual bool isEquivalent(Lattice other)
 {
     return(this.checkNodesEquivalent(this.initialNode, other.getInitialNode()));
 }
示例#10
0
        public static Lattice readSlf(InputStream stream)
        {
            Lattice          lattice          = new Lattice();
            LineNumberReader lineNumberReader = new LineNumberReader(new InputStreamReader(stream));
            int    num  = 0;
            int    num2 = 0;
            int    num3 = 0;
            int    num4 = 1;
            double num5 = 9.5;
            string text;

            while ((text = lineNumberReader.readLine()) != null)
            {
                string       text2        = text;
                object       obj          = "Node definitions";
                CharSequence charSequence = CharSequence.Cast(obj);
                if (String.instancehelper_contains(text2, charSequence))
                {
                    num2 = 0;
                    num  = 1;
                }
                else
                {
                    string text3 = text;
                    obj          = "Link definitions";
                    charSequence = CharSequence.Cast(obj);
                    if (String.instancehelper_contains(text3, charSequence))
                    {
                        num2 = 1;
                        num  = 0;
                    }
                    else if (!String.instancehelper_startsWith(text, "#"))
                    {
                        if (num != 0)
                        {
                            string[] array = String.instancehelper_split(text, "\\s+");
                            if (array.Length != 3 || !String.instancehelper_startsWith(array[0], "I=") || !String.instancehelper_startsWith(array[1], "t=") || !String.instancehelper_startsWith(array[2], "W="))
                            {
                                lineNumberReader.close();
                                string text4 = new StringBuilder().append("Unknown node definition: ").append(text).toString();

                                throw new IOException(text4);
                            }
                            int    num6      = Integer.parseInt(String.instancehelper_substring(array[0], 2));
                            long   beginTime = ByteCodeHelper.d2l(Double.parseDouble(String.instancehelper_substring(array[1], 2)) * 1000.0);
                            string text5     = String.instancehelper_substring(array[2], 2);
                            int    isFiller  = 0;
                            if (num6 == num3 || String.instancehelper_equals(text5, "!ENTER"))
                            {
                                text5    = "<s>";
                                isFiller = 1;
                            }
                            if (num6 == num4 || String.instancehelper_equals(text5, "!EXIT"))
                            {
                                text5    = "</s>";
                                isFiller = 1;
                            }
                            if (String.instancehelper_equals(text5, "!NULL"))
                            {
                                text5    = "<sil>";
                                isFiller = 1;
                            }
                            if (String.instancehelper_startsWith(text5, "["))
                            {
                                isFiller = 1;
                            }
                            Word word = new Word(text5, new Pronunciation[0], isFiller != 0);
                            Node node = lattice.addNode(Integer.toString(num6), word, beginTime, -1L);
                            if (String.instancehelper_equals(text5, "<s>"))
                            {
                                lattice.setInitialNode(node);
                            }
                            if (String.instancehelper_equals(text5, "</s>"))
                            {
                                lattice.setTerminalNode(node);
                            }
                        }
                        else if (num2 != 0)
                        {
                            string[] array = String.instancehelper_split(text, "\\s+");
                            if (array.Length != 5 || !String.instancehelper_startsWith(array[1], "S=") || !String.instancehelper_startsWith(array[2], "E=") || !String.instancehelper_startsWith(array[3], "a=") || !String.instancehelper_startsWith(array[4], "l="))
                            {
                                lineNumberReader.close();
                                string text6 = new StringBuilder().append("Unknown edge definition: ").append(text).toString();

                                throw new IOException(text6);
                            }
                            string text7         = String.instancehelper_substring(array[1], 2);
                            string text8         = String.instancehelper_substring(array[2], 2);
                            double acousticScore = Double.parseDouble(String.instancehelper_substring(array[3], 2));
                            double lmScore       = Double.parseDouble(String.instancehelper_substring(array[4], 2)) * num5;
                            lattice.addEdge((Node)lattice.nodes.get(text7), (Node)lattice.nodes.get(text8), acousticScore, lmScore);
                        }
                        else
                        {
                            if (String.instancehelper_startsWith(text, "start="))
                            {
                                string text9 = text;
                                object obj2  = "start=";
                                obj = "";
                                object obj3 = obj2;
                                charSequence = CharSequence.Cast(obj3);
                                CharSequence charSequence2 = charSequence;
                                obj3         = obj;
                                charSequence = CharSequence.Cast(obj3);
                                num3         = Integer.parseInt(String.instancehelper_replace(text9, charSequence2, charSequence));
                            }
                            if (String.instancehelper_startsWith(text, "end="))
                            {
                                string text10 = text;
                                object obj4   = "end=";
                                object obj3   = "";
                                obj          = obj4;
                                charSequence = CharSequence.Cast(obj);
                                CharSequence charSequence3 = charSequence;
                                obj          = obj3;
                                charSequence = CharSequence.Cast(obj);
                                num4         = Integer.parseInt(String.instancehelper_replace(text10, charSequence3, charSequence));
                            }
                            if (String.instancehelper_startsWith(text, "lmscale="))
                            {
                                string text11 = text;
                                object obj5   = "lmscale=";
                                obj = "";
                                object obj3 = obj5;
                                charSequence = CharSequence.Cast(obj3);
                                CharSequence charSequence4 = charSequence;
                                obj3         = obj;
                                charSequence = CharSequence.Cast(obj3);
                                num5         = Double.parseDouble(String.instancehelper_replace(text11, charSequence4, charSequence));
                            }
                        }
                    }
                }
            }
            Iterator iterator = lattice.nodes.values().iterator();

            while (iterator.hasNext())
            {
                Node     node2     = (Node)iterator.next();
                Iterator iterator2 = node2.getLeavingEdges().iterator();
                while (iterator2.hasNext())
                {
                    Edge edge = (Edge)iterator2.next();
                    if (node2.getEndTime() < 0L || node2.getEndTime() > edge.getToNode().getBeginTime())
                    {
                        node2.setEndTime(Math.max(edge.getToNode().getBeginTime(), node2.getBeginTime()));
                    }
                }
            }
            return(lattice);
        }
示例#11
0
 public Nbest(Lattice lattice)
 {
     this.lattice = lattice;
 }