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);
        }
예제 #2
0
        private int createNodes(string text)
        {
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(text, true);
            int num = 0;

            while (!extendedStreamTokenizer.isEOF())
            {
                extendedStreamTokenizer.skipwhite();
                string @string = extendedStreamTokenizer.getString();
                if (@string == null)
                {
                    break;
                }
                if (String.instancehelper_equals(@string, "T"))
                {
                    extendedStreamTokenizer.getInt("src id");
                    int @int = extendedStreamTokenizer.getInt("dest id");
                    if (@int > num)
                    {
                        num = @int;
                    }
                    if (extendedStreamTokenizer.getString() != null)
                    {
                        string string2 = extendedStreamTokenizer.getString();
                        extendedStreamTokenizer.getString();
                        string      text2       = new StringBuilder().append("G").append(@int).toString();
                        GrammarNode grammarNode = (GrammarNode)this.nodes.get(text2);
                        if (grammarNode == null)
                        {
                            if (String.instancehelper_equals(string2, ","))
                            {
                                grammarNode = this.createGrammarNode(@int, false);
                            }
                            else
                            {
                                grammarNode = this.createGrammarNode(@int, string2);
                            }
                            this.nodes.put(text2, grammarNode);
                        }
                        else if (!String.instancehelper_equals(string2, ",") && !FSTGrammar.assertionsDisabled && !String.instancehelper_equals(string2, this.getWord(grammarNode)))
                        {
                            throw new AssertionError();
                        }
                    }
                }
            }
            extendedStreamTokenizer.close();
            return(num);
        }
예제 #3
0
        /*
         * Reads Text and converts it into a list of tokens
         */
        public void setText(string text)
        {
            string word;

            try {
                ExtendedStreamTokenizer tok = new ExtendedStreamTokenizer(
                    new java.io.StringReader(text), true);

                tokens.Clear();
                while (!tok.isEOF())
                {
                    while ((word = tok.getString()) != null)
                    {
                        word = word.toLowerCase();
                        tokens.Add(word);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
예제 #4
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);
        }
예제 #5
0
        private void loadPhoneList(PropertySheet propertySheet, bool flag, InputStream inputStream, string text)
        {
            int num  = 0;
            int num2 = 1;
            int num3 = 1;
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(inputStream, 35, false);

            this.meansPool    = new Pool("means");
            this.variancePool = new Pool("variances");
            this.matrixPool   = new Pool("transitionmatrices");
            this.senonePool   = new Pool("senones");
            float @float = propertySheet.getFloat("MixtureComponentScoreFloor");
            float float2 = propertySheet.getFloat("mixtureWeightFloor");
            float num4   = 0f;
            float float3 = propertySheet.getFloat("varianceFloor");

            this.logger.info("Loading phone list file from: ");
            this.logger.info(text);
            string expecting = "0.1";

            extendedStreamTokenizer.expectString("version");
            extendedStreamTokenizer.expectString(expecting);
            extendedStreamTokenizer.expectString("same_sized_models");
            int num5 = String.instancehelper_equals(extendedStreamTokenizer.getString(), "yes") ? 1 : 0;

            if (num5 != 0)
            {
                extendedStreamTokenizer.expectString("n_state");
                num = extendedStreamTokenizer.getInt("numBase");
            }
            extendedStreamTokenizer.expectString("tmat_skip");
            int num6 = String.instancehelper_equals(extendedStreamTokenizer.getString(), "yes") ? 1 : 0;
            int num7 = 0;
            int num8 = 0;

            for (;;)
            {
                string @string = extendedStreamTokenizer.getString();
                if (extendedStreamTokenizer.isEOF())
                {
                    break;
                }
                int num9 = num;
                if (num5 == 0)
                {
                    num9 = extendedStreamTokenizer.getInt("ModelSize");
                }
                this.phoneList.put(@string, Integer.valueOf(num9));
                this.logger.fine(new StringBuilder().append("Phone: ").append(@string).append(" size: ").append(num9).toString());
                int[]  array = new int[num9];
                string rep   = "-";
                int    i     = 0;
                while (i < num9)
                {
                    array[i] = num7;
                    i++;
                    num7++;
                }
                Unit unit = this.unitManager.getUnit(@string, String.instancehelper_equals(@string, "SIL"));
                this.contextIndependentUnits.put(unit.getName(), unit);
                if (this.logger.isLoggable(Level.FINE))
                {
                    this.logger.fine(new StringBuilder().append("Loaded ").append(unit).append(" with ").append(num9).append(" states").toString());
                }
                this.addModelToDensityPool(this.meansPool, array, num2, num3);
                this.addModelToDensityPool(this.variancePool, array, num2, num3);
                this.addModelToTransitionMatrixPool(this.matrixPool, num8, array.Length, num4, num6 != 0);
                this.addModelToSenonePool(this.senonePool, array, @float, float3);
                float[][]      transitionMatrix = (float[][])this.matrixPool.get(num8);
                SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup(rep));
                this.hmmManager.put(hmm);
                num8++;
            }
            this.mixtureWeights = this.initMixtureWeights(num7, num2, num3, float2);
            extendedStreamTokenizer.close();
        }