Beispiel #1
0
        private int expandWordNodes(int num)
        {
            Collection collection = this.nodes.values();

            string[][] alts = new string[][]
            {
                new string[]
                {
                    "<sil>"
                }
            };
            Iterator iterator = collection.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode = (GrammarNode)iterator.next();
                if (grammarNode.getNumAlternatives() > 0)
                {
                    num++;
                    GrammarNode node = this.createGrammarNode(num, false);
                    grammarNode.add(node, 0f);
                    if (this.addOptionalSilence)
                    {
                        num++;
                        GrammarNode grammarNode2 = this.createGrammarNode(num, alts);
                        grammarNode.add(grammarNode2, 0f);
                        grammarNode2.add(node, 0f);
                    }
                    this.expandedNodes.add(grammarNode);
                }
            }
            return(num);
        }
        protected internal override GrammarNode createGrammar()
        {
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(this.path, true);
            GrammarNode             grammarNode             = this.createGrammarNode("<sil>");
            GrammarNode             grammarNode2            = this.createGrammarNode(false);
            GrammarNode             grammarNode3            = this.createGrammarNode("<sil>");

            grammarNode3.setFinalNode(true);
            LinkedList linkedList = new LinkedList();

            while (!extendedStreamTokenizer.isEOF())
            {
                string @string;
                while ((@string = extendedStreamTokenizer.getString()) != null)
                {
                    GrammarNode grammarNode4 = this.createGrammarNode(@string);
                    linkedList.add(grammarNode4);
                }
            }
            grammarNode.add(grammarNode2, 0f);
            float    logProbability = this.logMath.linearToLog((double)1f / (double)linkedList.size());
            Iterator iterator       = linkedList.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode5 = (GrammarNode)iterator.next();
                grammarNode2.add(grammarNode5, logProbability);
                grammarNode5.add(grammarNode3, 0f);
                if (this.isLooping)
                {
                    grammarNode5.add(grammarNode2, 0f);
                }
            }
            return(grammarNode);
        }
Beispiel #3
0
        private void addFillerWords()
        {
            HashSet hashSet = new HashSet(this.getGrammarNodes());

            Word[] interWordFillers = this.getInterWordFillers();
            if (interWordFillers.Length == 0)
            {
                return;
            }
            Iterator iterator = hashSet.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode = (GrammarNode)iterator.next();
                if (!grammarNode.isEmpty() && !grammarNode.getWord().isFiller())
                {
                    GrammarNode grammarNode2 = grammarNode.splitNode(this.maxIdentity + 1);
                    this.add(grammarNode2);
                    GrammarNode grammarNode3 = this.createGrammarNode(false);
                    GrammarNode grammarNode4 = this.createGrammarNode(false);
                    grammarNode4.add(grammarNode3, 0f);
                    grammarNode4.add(grammarNode2, 0f);
                    grammarNode.add(grammarNode3, 0f);
                    Word[] array = interWordFillers;
                    int    num   = array.Length;
                    for (int i = 0; i < num; i++)
                    {
                        Word        word         = array[i];
                        GrammarNode grammarNode5 = this.createGrammarNode(this.maxIdentity + 1, word.getSpelling());
                        grammarNode3.add(grammarNode5, 0f);
                        grammarNode5.add(grammarNode4, 0f);
                    }
                }
            }
        }
Beispiel #4
0
        private void addSilenceWords()
        {
            HashSet  hashSet  = new HashSet(this.getGrammarNodes());
            Iterator iterator = hashSet.iterator();

            while (iterator.hasNext())
            {
                GrammarNode grammarNode = (GrammarNode)iterator.next();
                if (!grammarNode.isEmpty() && !grammarNode.getWord().isFiller())
                {
                    GrammarNode grammarNode2 = this.createGrammarNode(this.maxIdentity + 1, this.dictionary.getSilenceWord().getSpelling());
                    GrammarNode grammarNode3 = grammarNode.splitNode(this.maxIdentity + 1);
                    this.add(grammarNode3);
                    grammarNode.add(grammarNode2, 0f);
                    grammarNode2.add(grammarNode3, 0f);
                    grammarNode2.add(grammarNode2, 0f);
                }
            }
        }
        protected internal override GrammarNode createGrammar()
        {
            this.logger.info("Making Grammar");
            this.initialNode = this.createGrammarNode("<sil>");
            this.finalNode   = this.createGrammarNode(true);
            GrammarNode grammarNode = this.initialNode;
            Iterator    iterator    = this.tokens.iterator();

            while (iterator.hasNext())
            {
                string      word         = (string)iterator.next();
                GrammarNode grammarNode2 = this.createGrammarNode(word);
                GrammarNode grammarNode3 = this.createGrammarNode(false);
                GrammarNode grammarNode4 = this.createGrammarNode(false);
                grammarNode.add(grammarNode2, 0f);
                grammarNode.add(grammarNode3, 0f);
                grammarNode2.add(grammarNode4, 0f);
                grammarNode3.add(grammarNode4, 0f);
                grammarNode = grammarNode4;
            }
            grammarNode.add(this.finalNode, 0f);
            this.logger.info("Done making Grammar");
            return(this.initialNode);
        }
Beispiel #6
0
        protected internal override GrammarNode createGrammar()
        {
            if (this.lattice == null)
            {
                return(this.createGrammarNode("<s>"));
            }
            GrammarNode grammarNode = null;
            HashMap     hashMap     = new HashMap();
            Iterator    iterator    = this.lattice.getNodes().iterator();

            while (iterator.hasNext())
            {
                Node        node         = (Node)iterator.next();
                string      word         = node.getWord().toString();
                GrammarNode grammarNode2 = this.createGrammarNode(word);
                if (node.equals(this.lattice.getInitialNode()))
                {
                    grammarNode = grammarNode2;
                }
                if (node.equals(this.lattice.getTerminalNode()))
                {
                    grammarNode2.setFinalNode(true);
                }
                hashMap.put(node, grammarNode2);
            }
            if (grammarNode == null)
            {
                string text = "No lattice start found";

                throw new Error(text);
            }
            iterator = this.lattice.getEdges().iterator();
            while (iterator.hasNext())
            {
                Edge        edge           = (Edge)iterator.next();
                float       logProbability = (float)edge.getLMScore();
                GrammarNode grammarNode2   = (GrammarNode)hashMap.get(edge.getFromNode());
                GrammarNode node2          = (GrammarNode)hashMap.get(edge.getToNode());
                grammarNode2.add(node2, logProbability);
            }
            return(grammarNode);
        }
Beispiel #7
0
        protected internal virtual GrammarNode createForcedAlignerGrammar(GrammarNode iNode, GrammarNode fNode, string transcript)
        {
            StringTokenizer stringTokenizer = new StringTokenizer(transcript);
            GrammarNode     grammarNode     = null;
            GrammarNode     grammarNode2    = null;

            while (stringTokenizer.hasMoreTokens())
            {
                string      word         = stringTokenizer.nextToken();
                GrammarNode grammarNode3 = grammarNode2;
                grammarNode2 = this.createGrammarNode(word);
                if (grammarNode == null)
                {
                    grammarNode = grammarNode2;
                }
                if (grammarNode3 != null)
                {
                    grammarNode3.add(grammarNode2, 0f);
                }
            }
            iNode.add(grammarNode, 0f);
            grammarNode2.add(fNode, 0f);
            return(grammarNode);
        }
Beispiel #8
0
        protected internal override GrammarNode createGrammar()
        {
            GrammarNode grammarNode = null;
            int         num         = this.createNodes(this.path);

            num++;
            GrammarNode grammarNode2 = this.createGrammarNode(num, "<sil>");

            grammarNode2.setFinalNode(true);
            num = this.expandWordNodes(num);
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(this.path, true);

            while (!extendedStreamTokenizer.isEOF())
            {
                extendedStreamTokenizer.skipwhite();
                string @string = extendedStreamTokenizer.getString();
                if (@string == null)
                {
                    break;
                }
                if (String.instancehelper_equals(@string, "I"))
                {
                    if (!FSTGrammar.assertionsDisabled && grammarNode != null)
                    {
                        throw new AssertionError();
                    }
                    int    @int = extendedStreamTokenizer.getInt("initial ID");
                    string text = new StringBuilder().append("G").append(@int).toString();
                    grammarNode = this.createGrammarNode(@int, "<sil>");
                    this.nodes.put(text, grammarNode);
                    if (this.addInitialSilenceNode)
                    {
                        num++;
                        GrammarNode grammarNode3 = this.createGrammarNode(num, "<sil>");
                        grammarNode.add(grammarNode3, 0f);
                        grammarNode3.add(grammarNode, 0f);
                    }
                }
                else if (String.instancehelper_equals(@string, "T"))
                {
                    int         @int         = extendedStreamTokenizer.getInt("this id");
                    int         int2         = extendedStreamTokenizer.getInt("next id");
                    GrammarNode grammarNode3 = this.get(@int);
                    GrammarNode grammarNode4 = this.get(int2);
                    if (this.hasEndNode(grammarNode3))
                    {
                        grammarNode3 = this.getEndNode(grammarNode3);
                    }
                    float  num2    = 0f;
                    string string2 = extendedStreamTokenizer.getString();
                    if (string2 == null || String.instancehelper_equals(string2, ","))
                    {
                        if (string2 != null && String.instancehelper_equals(string2, ","))
                        {
                            extendedStreamTokenizer.getString();
                            num2 = extendedStreamTokenizer.getFloat("probability");
                        }
                        if (this.hasEndNode(grammarNode4))
                        {
                            grammarNode4 = this.getEndNode(grammarNode4);
                        }
                    }
                    else
                    {
                        string string3 = extendedStreamTokenizer.getString();
                        num2 = extendedStreamTokenizer.getFloat("probability");
                        if (String.instancehelper_equals(string3, "<unknown>"))
                        {
                            continue;
                        }
                        if (!FSTGrammar.assertionsDisabled && !this.hasWord(grammarNode4))
                        {
                            throw new AssertionError();
                        }
                    }
                    grammarNode3.add(grammarNode4, this.convertProbability(num2));
                }
                else if (String.instancehelper_equals(@string, "F"))
                {
                    int         @int         = extendedStreamTokenizer.getInt("this id");
                    float       @float       = extendedStreamTokenizer.getFloat("probability");
                    GrammarNode grammarNode3 = this.get(@int);
                    GrammarNode grammarNode4 = grammarNode2;
                    if (this.hasEndNode(grammarNode3))
                    {
                        grammarNode3 = this.getEndNode(grammarNode3);
                    }
                    grammarNode3.add(grammarNode4, this.convertProbability(@float));
                }
            }
            extendedStreamTokenizer.close();
            if (!FSTGrammar.assertionsDisabled && grammarNode == null)
            {
                throw new AssertionError();
            }
            return(grammarNode);
        }
Beispiel #9
0
        protected internal override GrammarNode createGrammar()
        {
            this.languageModel.allocate();
            TimerPool.getTimer(this, "LMGrammar.create").start();
            GrammarNode grammarNode = null;

            if (this.languageModel.getMaxDepth() > 2)
            {
                [email protected]("Warning: LMGrammar  limited to bigrams");
            }
            ArrayList arrayList  = new ArrayList();
            Set       vocabulary = this.languageModel.getVocabulary();
            Iterator  iterator   = vocabulary.iterator();

            while (iterator.hasNext())
            {
                string      word         = (string)iterator.next();
                GrammarNode grammarNode2 = this.createGrammarNode(word);
                if (grammarNode2 != null && !grammarNode2.isEmpty())
                {
                    if (grammarNode2.getWord().equals(this.getDictionary().getSentenceStartWord()))
                    {
                        grammarNode = grammarNode2;
                    }
                    else if (grammarNode2.getWord().equals(this.getDictionary().getSentenceEndWord()))
                    {
                        grammarNode2.setFinalNode(true);
                    }
                    arrayList.add(grammarNode2);
                }
            }
            if (grammarNode == null)
            {
                string text = "No sentence start found in language model";

                throw new Error(text);
            }
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                GrammarNode grammarNode3 = (GrammarNode)iterator.next();
                if (!grammarNode3.isFinalNode())
                {
                    Iterator iterator2 = arrayList.iterator();
                    while (iterator2.hasNext())
                    {
                        GrammarNode grammarNode4 = (GrammarNode)iterator2.next();
                        string      spelling     = grammarNode3.getWord().getSpelling();
                        string      spelling2    = grammarNode4.getWord().getSpelling();
                        Word[]      words        = new Word[]
                        {
                            this.getDictionary().getWord(spelling),
                            this.getDictionary().getWord(spelling2)
                        };
                        float probability = this.languageModel.getProbability(new WordSequence(words));
                        grammarNode3.add(grammarNode4, probability);
                    }
                }
            }
            TimerPool.getTimer(this, "LMGrammar.create").stop();
            this.languageModel.deallocate();
            return(grammarNode);
        }