예제 #1
0
            /**
             * /// Attaches the given unit to the given tail, expanding the unit if necessary. If an identical unit is already
             * /// attached, then this path is folded into the existing path.
             *
             * /// @param parent       the parent state
             * /// @param tail         the place to attach the unit to
             * /// @param units        the set of units
             * /// @param which        the index into the set of units
             * /// @param leftContext  the left context for the unit
             * /// @param rightContext the right context for the unit
             * /// @return the tail of the added unit (or null if the path was folded onto an already expanded path.
             */
            private SentenceHMMState AttachUnit(PronunciationState parent,
                                                SentenceHMMState tail, Unit[] units, int which,
                                                UnitContext leftContext, UnitContext rightContext)
            {
                Unit[]           lc = GetLC(leftContext, units, which);
                Unit[]           rc = GetRC(units, which, rightContext);
                UnitContext      actualRightContext = UnitContext.Get(rc);
                LeftRightContext context            = LeftRightContext.Get(lc, rc);
                Unit             cdUnit             = _parent.UnitManager.GetUnit(units[which].Name, units[which].IsFiller, context);
                UnitState        unitState          = new ExtendedUnitState(parent, which, cdUnit);
                float            logInsertionProbability;

                if (unitState.Unit.IsSilence)
                {
                    logInsertionProbability = _parent.LogSilenceInsertionProbability;
                }
                else if (unitState.Unit.IsFiller)
                {
                    logInsertionProbability = _parent._logFillerInsertionProbability;
                }
                else if (unitState.GetWhich() == 0)
                {
                    logInsertionProbability = _parent._logWordInsertionProbability;
                }
                else
                {
                    logInsertionProbability = _parent._logUnitInsertionProbability;
                }
                // check to see if this state already exists, if so
                // branch to it and we are done, otherwise, branch to
                // the new state and expand it.
                SentenceHMMState existingState = GetExistingState(unitState);

                if (existingState != null)
                {
                    AttachState(tail, existingState, LogOne, logInsertionProbability);
                    // T(" Folding " + existingState);
                    return(null);
                }
                else
                {
                    AttachState(tail, unitState, LogOne, logInsertionProbability);
                    AddStateToCache(unitState);
                    // T(" Attaching " + unitState);
                    tail = ExpandUnit(unitState);
                    // if we are attaching the last state of a word, then
                    // we add it to the exitPoints table. the exit points
                    // table is indexed by a ContextPair, consisting of
                    // the exiting left context and the right context.
                    if (unitState.IsLast())
                    {
                        UnitContext nextLeftContext = GenerateNextLeftContext(leftContext, units[which]);
                        ContextPair cp = ContextPair.Get(nextLeftContext, actualRightContext);
                        // T(" Adding to exitPoints " + cp);
                        AddExitPoint(cp, tail);
                    }
                    return(tail);
                }
            }
        private void createContextDependentSuccessors()
        {
            this.cdHMMs             = new HashMap();
            this.senonesToUnits     = new HashMap();
            this.fillerHMMs         = new ArrayList();
            this.leftContextSilHMMs = new ArrayList();
            Iterator hmmiterator = this.acousticModel.getHMMIterator();

            while (hmmiterator.hasNext())
            {
                HMM            hmm            = (HMM)hmmiterator.next();
                SenoneSequence senoneSequence = ((SenoneHMM)hmm).getSenoneSequence();
                ArrayList      arrayList;
                if ((arrayList = (ArrayList)this.senonesToUnits.get(senoneSequence)) == null)
                {
                    arrayList = new ArrayList();
                    this.senonesToUnits.put(senoneSequence, arrayList);
                }
                arrayList.add(hmm.getUnit());
                if (hmm.getUnit().isFiller())
                {
                    this.fillerHMMs.add(hmm);
                }
                else if (hmm.getUnit().isContextDependent())
                {
                    LeftRightContext leftRightContext = (LeftRightContext)hmm.getUnit().getContext();
                    Unit             unit             = leftRightContext.getLeftContext()[0];
                    if (unit == UnitManager.__SILENCE)
                    {
                        this.leftContextSilHMMs.add(hmm);
                    }
                    else
                    {
                        Unit    baseUnit = hmm.getUnit().getBaseUnit();
                        HashMap hashMap;
                        if ((hashMap = (HashMap)this.cdHMMs.get(unit)) == null)
                        {
                            hashMap = new HashMap();
                            this.cdHMMs.put(unit, hashMap);
                        }
                        ArrayList arrayList2;
                        if ((arrayList2 = (ArrayList)hashMap.get(baseUnit)) == null)
                        {
                            arrayList2 = new ArrayList();
                            hashMap.put(baseUnit, arrayList2);
                        }
                        arrayList2.add(hmm);
                    }
                }
            }
            this.leftContextSilHMMs.addAll(this.fillerHMMs);
        }
예제 #3
0
        private void CreateContextDependentSuccessors()
        {
            _cdHMMs             = new HashMap <Unit, HashMap <Unit, List <IHMM> > >();
            _senonesToUnits     = new HashMap <SenoneSequence, List <Unit> >();
            _fillerHMMs         = new List <IHMM>();
            _leftContextSilHMMs = new List <IHMM>();
            var hmmIter = AcousticModel.GetHMMIterator();

            while (hmmIter.MoveNext())
            {
                IHMM           hmm = hmmIter.Current;
                List <Unit>    sameSenonesUnits;
                SenoneSequence senoneSeq = ((SenoneHMM)hmm).SenoneSequence;
                if ((sameSenonesUnits = _senonesToUnits.Get(senoneSeq)) == null)
                {
                    sameSenonesUnits = new List <Unit>();
                    _senonesToUnits.Put(senoneSeq, sameSenonesUnits);
                }
                sameSenonesUnits.Add(hmm.Unit as Unit);
                if (hmm.Unit.IsFiller)
                {
                    _fillerHMMs.Add(hmm);
                    continue;
                }
                if (hmm.Unit.IsContextDependent())
                {
                    LeftRightContext context = (LeftRightContext)hmm.Unit.Context;
                    Unit             lc      = context.LeftContext[0] as Unit;
                    if (lc == UnitManager.Silence)
                    {
                        _leftContextSilHMMs.Add(hmm);
                        continue;
                    }
                    Unit baseUnit = hmm.Unit.BaseUnit as Unit;
                    HashMap <Unit, List <IHMM> > lcSuccessors;
                    if ((lcSuccessors = _cdHMMs.Get(lc)) == null)
                    {
                        lcSuccessors = new HashMap <Unit, List <IHMM> >();
                        _cdHMMs.Put(lc, lcSuccessors);
                    }
                    List <IHMM> lcBaseSuccessors;
                    if ((lcBaseSuccessors = lcSuccessors.Get(baseUnit)) == null)
                    {
                        lcBaseSuccessors = new List <IHMM>();
                        lcSuccessors.Put(baseUnit, lcBaseSuccessors);
                    }
                    lcBaseSuccessors.Add(hmm);
                }
            }
            _leftContextSilHMMs.AddRange(_fillerHMMs);
        }
        /**
         * /// Given a unit, search for the HMM associated with this unit by replacing all non-silence filler contexts with the
         * /// silence filler context
         *
         * /// @param unit the unit of interest
         * /// @return the associated hmm or null
         */
        private SenoneHMM GetHMMInSilenceContext(Unit unit, HMMPosition position)
        {
            SenoneHMM hmm     = null;
            var       mgr     = Loader.HMMManager;
            var       context = unit.Context;

            if (context is LeftRightContext)
            {
                var lrContext = (LeftRightContext)context;

                var lc = lrContext.LeftContext;
                var rc = lrContext.RightContext;

                Unit[] nlc;
                Unit[] nrc;

                if (HasNonSilenceFiller(lc))
                {
                    nlc = ReplaceNonSilenceFillerWithSilence(lc);
                }
                else
                {
                    nlc = lc;
                }

                if (HasNonSilenceFiller(rc))
                {
                    nrc = ReplaceNonSilenceFillerWithSilence(rc);
                }
                else
                {
                    nrc = rc;
                }

                if (nlc != lc || nrc != rc)
                {
                    Context newContext = LeftRightContext.Get(nlc, nrc);
                    var     newUnit    = UnitManager.GetUnit(unit.Name,
                                                             unit.IsFiller, newContext);
                    hmm = (SenoneHMM)mgr.Get(position, newUnit);
                    if (hmm == null)
                    {
                        hmm = GetHMMAtAnyPosition(newUnit);
                    }
                }
            }
            return(hmm);
        }
예제 #5
0
            private SentenceHMMState attachUnit(PronunciationState parent, SentenceHMMState sentenceHMMState, Unit[] array, int num, UnitContext unitContext, UnitContext unitContext2)
            {
                Unit[]            lc                = this.getLC(unitContext, array, num);
                Unit[]            rc                = this.getRC(array, num, unitContext2);
                UnitContext       unitContext3      = UnitContext.get(rc);
                LeftRightContext  context           = LeftRightContext.get(lc, rc);
                Unit              unit              = FlatLinguist.access_200(this.this_0).getUnit(array[num].getName(), array[num].isFiller(), context);
                ExtendedUnitState extendedUnitState = new ExtendedUnitState(parent, num, unit);
                float             logInsertionProbablity;

                if (extendedUnitState.getUnit().isSilence())
                {
                    logInsertionProbablity = FlatLinguist.access_300(this.this_0);
                }
                else if (extendedUnitState.getUnit().isFiller())
                {
                    logInsertionProbablity = FlatLinguist.access_400(this.this_0);
                }
                else if (extendedUnitState.getWhich() == 0)
                {
                    logInsertionProbablity = FlatLinguist.access_500(this.this_0);
                }
                else
                {
                    logInsertionProbablity = FlatLinguist.access_600(this.this_0);
                }
                SentenceHMMState existingState = this.getExistingState(extendedUnitState);

                if (existingState != null)
                {
                    this.attachState(sentenceHMMState, existingState, 0f, logInsertionProbablity);
                    return(null);
                }
                this.attachState(sentenceHMMState, extendedUnitState, 0f, logInsertionProbablity);
                this.addStateToCache(extendedUnitState);
                sentenceHMMState = this.expandUnit(extendedUnitState);
                if (extendedUnitState.isLast())
                {
                    UnitContext unitContext4 = this.generateNextLeftContext(unitContext, array[num]);
                    ContextPair contextPair  = ContextPair.get(unitContext4, unitContext3);
                    this.addExitPoint(contextPair, sentenceHMMState);
                }
                return(sentenceHMMState);
            }
예제 #6
0
        public override HMM get(HMMPosition position, Unit unit)
        {
            HMM hmm = base.get(position, unit);

            if (null != hmm)
            {
                return(hmm);
            }
            int[] array = new int[3];
            array[1] = ((Integer)this.symbolTable.get(unit.getName())).intValue();
            if (unit.isContextDependent())
            {
                LeftRightContext leftRightContext = (LeftRightContext)unit.getContext();
                Unit             unit2            = leftRightContext.getLeftContext()[0];
                Unit             unit3            = leftRightContext.getRightContext()[0];
                array[0] = ((Integer)this.symbolTable.get(unit2.getName())).intValue();
                array[2] = ((Integer)this.symbolTable.get(unit3.getName())).intValue();
            }
            else
            {
                array[0] = ((Integer)this.symbolTable.get("SIL")).intValue();
                array[2] = ((Integer)this.symbolTable.get("SIL")).intValue();
            }
            int[] array2 = new int[]
            {
                this.eventMap.map(0, array),
                this.eventMap.map(1, array),
                this.eventMap.map(2, array)
            };
            SenoneSequence senoneSequence = new SenoneSequence(new Senone[]
            {
                (Senone)this.senonePool.get(array2[0]),
                (Senone)this.senonePool.get(array2[1]),
                (Senone)this.senonePool.get(array2[2])
            });

            float[][] transitionMatrix = this.transitionModel.getTransitionMatrix(array[1], array2);
            SenoneHMM senoneHMM        = new SenoneHMM(unit, senoneSequence, transitionMatrix, position);

            this.put(senoneHMM);
            return(senoneHMM);
        }
        private SenoneHMM getHMMInSilenceContext(Unit unit, HMMPosition position)
        {
            SenoneHMM  senoneHMM  = null;
            HMMManager hmmmanager = this.loader.getHMMManager();
            Context    context    = unit.getContext();

            if (context is LeftRightContext)
            {
                LeftRightContext leftRightContext = (LeftRightContext)context;
                Unit[]           leftContext      = leftRightContext.getLeftContext();
                Unit[]           rightContext     = leftRightContext.getRightContext();
                Unit[]           array;
                if (this.hasNonSilenceFiller(leftContext))
                {
                    array = this.replaceNonSilenceFillerWithSilence(leftContext);
                }
                else
                {
                    array = leftContext;
                }
                Unit[] array2;
                if (this.hasNonSilenceFiller(rightContext))
                {
                    array2 = this.replaceNonSilenceFillerWithSilence(rightContext);
                }
                else
                {
                    array2 = rightContext;
                }
                if (array != leftContext || array2 != rightContext)
                {
                    LeftRightContext context2 = LeftRightContext.get(array, array2);
                    Unit             unit2    = this.unitManager.getUnit(unit.getName(), unit.isFiller(), context2);
                    senoneHMM = (SenoneHMM)hmmmanager.get(position, unit2);
                    if (senoneHMM == null)
                    {
                        senoneHMM = this.getHMMAtAnyPosition(unit2);
                    }
                }
            }
            return(senoneHMM);
        }
        private bool isComposite(Unit unit)
        {
            if (unit.isFiller())
            {
                return(false);
            }
            Context context = unit.getContext();

            if (context is LeftRightContext)
            {
                LeftRightContext leftRightContext = (LeftRightContext)context;
                if (leftRightContext.getRightContext() == null)
                {
                    return(true);
                }
                if (leftRightContext.getLeftContext() == null)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #9
0
        /**
         * /// Loads the sphinx3 density file, a set of density arrays are created and
         * /// placed in the given pool.
         * ///
         * /// @param useCDUnits
         * ///            if true, loads also the context dependent units
         * /// @param inputStream
         * ///            the open input stream to use
         * /// @param path
         * ///            the path to a density file
         * /// @throws FileNotFoundException
         * ///             if a file cannot be found
         * /// @throws IOException
         * ///             if an error occurs while loading the data
         */
        protected void LoadHMMPool(Boolean useCDUnits, Stream inputStream,
                                   string path)
        {
            var est = new ExtendedStreamTokenizer(inputStream,
                                                  '#', false);

            this.LogInfo("Loading HMM file from: " + path);

            est.ExpectString(ModelVersion);

            var numBase = est.GetInt("numBase");

            est.ExpectString("n_base");

            var numTri = est.GetInt("numTri");

            est.ExpectString("n_tri");

            var numStateMap = est.GetInt("numStateMap");

            est.ExpectString("n_state_map");

            var numTiedState = est.GetInt("numTiedState");

            est.ExpectString("n_tied_state");

            var numContextIndependentTiedState = est
                                                 .GetInt("numContextIndependentTiedState");

            est.ExpectString("n_tied_ci_state");

            var numTiedTransitionMatrices = est.GetInt("numTiedTransitionMatrices");

            est.ExpectString("n_tied_tmat");

            var numStatePerHMM = numStateMap / (numTri + numBase);

            Debug.Assert(numTiedState == MixtureWeightsPool.StatesNum);
            Debug.Assert(numTiedTransitionMatrices == MatrixPool.Size);

            // Load the base phones
            for (var i = 0; i < numBase; i++)
            {
                var name      = est.GetString();
                var left      = est.GetString();
                var right     = est.GetString();
                var position  = est.GetString();
                var attribute = est.GetString();
                var tmat      = est.GetInt("tmat");

                var stid = new int[numStatePerHMM - 1];

                for (var j = 0; j < numStatePerHMM - 1; j++)
                {
                    stid[j] = est.GetInt("j");
                    Debug.Assert(stid[j] >= 0 && stid[j] < numContextIndependentTiedState);
                }
                est.ExpectString("N");

                Debug.Assert(left.Equals("-"));
                Debug.Assert(right.Equals("-"));
                Debug.Assert(position.Equals("-"));
                Debug.Assert(tmat < numTiedTransitionMatrices);

                var unit = _unitManager.GetUnit(name, attribute.Equals(Filler));
                ContextIndependentUnits.Put(unit.Name, unit);


                //this.LogInfo("Loaded " + unit.ToString());

                // The first filler
                if (unit.IsFiller && unit.Name.Equals(SilenceCiphone))
                {
                    unit = UnitManager.Silence;
                }

                var transitionMatrix = MatrixPool.Get(tmat);
                var ss = GetSenoneSequence(stid);

                IHMM hmm = new SenoneHMM(unit, ss, transitionMatrix, GetHMMPosition(position));
                HmmManager.Put(hmm);
            }

            if (HmmManager.Get(HMMPosition.Undefined, UnitManager.Silence) == null)
            {
                throw new IOException("Could not find SIL unit in acoustic model");
            }

            // Load the context dependent phones. If the useCDUnits
            // property is false, the CD phones will not be created, but
            // the values still need to be read in from the file.

            var  lastUnitName = "";
            Unit lastUnit     = null;

            int[]          lastStid           = null;
            SenoneSequence lastSenoneSequence = null;

            for (var i = 0; i < numTri; i++)
            {
                var name      = est.GetString();
                var left      = est.GetString();
                var right     = est.GetString();
                var position  = est.GetString();
                var attribute = est.GetString();
                var tmat      = est.GetInt("tmat");

                var stid = new int[numStatePerHMM - 1];

                for (var j = 0; j < numStatePerHMM - 1; j++)
                {
                    stid[j] = est.GetInt("j");
                    Debug.Assert(stid[j] >= numContextIndependentTiedState &&
                                 stid[j] < numTiedState);
                }
                est.ExpectString("N");

                Debug.Assert(!left.Equals("-"));
                Debug.Assert(!right.Equals("-"));
                Debug.Assert(!position.Equals("-"));
                Debug.Assert(attribute.Equals("n/a"));
                Debug.Assert(tmat < numTiedTransitionMatrices);

                if (useCDUnits)
                {
                    Unit unit;
                    var  unitName = (name + ' ' + left + ' ' + right);

                    if (unitName.Equals(lastUnitName))
                    {
                        unit = lastUnit;
                    }
                    else
                    {
                        var leftContext = new Unit[1];
                        leftContext[0] = ContextIndependentUnits.Get(left);

                        var rightContext = new Unit[1];
                        rightContext[0] = ContextIndependentUnits.Get(right);

                        Context context = LeftRightContext.Get(leftContext,
                                                               rightContext);
                        unit = _unitManager.GetUnit(name, false, context);
                    }
                    lastUnitName = unitName;
                    lastUnit     = unit;


                    //this.LogInfo("Loaded " + unit.ToString());


                    var transitionMatrix = MatrixPool.Get(tmat);

                    var ss = lastSenoneSequence;
                    if (ss == null || !SameSenoneSequence(stid, lastStid))
                    {
                        ss = GetSenoneSequence(stid);
                    }
                    lastSenoneSequence = ss;
                    lastStid           = stid;

                    IHMM hmm = new SenoneHMM(unit, ss, transitionMatrix, GetHMMPosition(position));
                    HmmManager.Put(hmm);
                }
            }

            est.Close();
        }
예제 #10
0
 /// <summary>
 /// Returns a string representation of this object
 /// </summary>
 /// <returns>string representation</returns>
 public override string ToString()
 {
     return(LeftRightContext.GetContextName(Units));
 }
예제 #11
0
 public override string toString()
 {
     return(LeftRightContext.getContextName(this.context));
 }
예제 #12
0
        protected internal virtual void loadHMMPool(bool useCDUnits, InputStream inputStream)
        {
            ExtendedStreamTokenizer extendedStreamTokenizer = new ExtendedStreamTokenizer(inputStream, 35, false);

            this.logger.fine(new StringBuilder().append("Loading HMM file from: ").append(this.location).toString());
            extendedStreamTokenizer.expectString("0.3");
            int @int = extendedStreamTokenizer.getInt("numBase");

            extendedStreamTokenizer.expectString("n_base");
            int int2 = extendedStreamTokenizer.getInt("numTri");

            extendedStreamTokenizer.expectString("n_tri");
            int int3 = extendedStreamTokenizer.getInt("numStateMap");

            extendedStreamTokenizer.expectString("n_state_map");
            int int4 = extendedStreamTokenizer.getInt("numTiedState");

            extendedStreamTokenizer.expectString("n_tied_state");
            int int5 = extendedStreamTokenizer.getInt("numContextIndependentTiedState");

            extendedStreamTokenizer.expectString("n_tied_ci_state");
            int int6 = extendedStreamTokenizer.getInt("numTiedTransitionMatrices");

            extendedStreamTokenizer.expectString("n_tied_tmat");
            int num  = int3;
            int num2 = int2 + @int;
            int num3 = (num2 != -1) ? (num / num2) : (-num);

            if (!Sphinx3Loader.assertionsDisabled && int4 != this.mixtureWeights.getStatesNum())
            {
                throw new AssertionError();
            }
            if (!Sphinx3Loader.assertionsDisabled && int6 != this.transitionsPool.size())
            {
                throw new AssertionError();
            }
            for (int i = 0; i < @int; i++)
            {
                string @string = extendedStreamTokenizer.getString();
                string string2 = extendedStreamTokenizer.getString();
                string string3 = extendedStreamTokenizer.getString();
                string string4 = extendedStreamTokenizer.getString();
                string string5 = extendedStreamTokenizer.getString();
                int    int7    = extendedStreamTokenizer.getInt("tmat");
                int[]  array   = new int[num3 - 1];
                for (int j = 0; j < num3 - 1; j++)
                {
                    array[j] = extendedStreamTokenizer.getInt("j");
                    if (!Sphinx3Loader.assertionsDisabled && (array[j] < 0 || array[j] >= int5))
                    {
                        throw new AssertionError();
                    }
                }
                extendedStreamTokenizer.expectString("N");
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string2, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string3, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string4, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && int7 >= int6)
                {
                    throw new AssertionError();
                }
                Unit unit = this.unitManager.getUnit(@string, String.instancehelper_equals(string5, "filler"));
                this.contextIndependentUnits.put(unit.getName(), unit);
                if (this.logger.isLoggable(Level.FINE))
                {
                    this.logger.fine(new StringBuilder().append("Loaded ").append(unit).toString());
                }
                if (unit.isFiller() && String.instancehelper_equals(unit.getName(), "SIL"))
                {
                    unit = UnitManager.__SILENCE;
                }
                float[][]      transitionMatrix = (float[][])this.transitionsPool.get(int7);
                SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup(string4));
                this.hmmManager.put(hmm);
            }
            if (this.hmmManager.get(HMMPosition.__UNDEFINED, UnitManager.__SILENCE) == null)
            {
                string text = "Could not find SIL unit in acoustic model";

                throw new IOException(text);
            }
            string text2 = "";
            Unit   unit2 = null;

            int[]          ssid            = null;
            SenoneSequence senoneSequence2 = null;

            for (int k = 0; k < int2; k++)
            {
                string string5 = extendedStreamTokenizer.getString();
                string string6 = extendedStreamTokenizer.getString();
                string string7 = extendedStreamTokenizer.getString();
                string string8 = extendedStreamTokenizer.getString();
                string string9 = extendedStreamTokenizer.getString();
                int    int8    = extendedStreamTokenizer.getInt("tmat");
                int[]  array2  = new int[num3 - 1];
                for (int l = 0; l < num3 - 1; l++)
                {
                    array2[l] = extendedStreamTokenizer.getInt("j");
                    if (!Sphinx3Loader.assertionsDisabled && (array2[l] < int5 || array2[l] >= int4))
                    {
                        throw new AssertionError();
                    }
                }
                extendedStreamTokenizer.expectString("N");
                if (!Sphinx3Loader.assertionsDisabled && String.instancehelper_equals(string6, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && String.instancehelper_equals(string7, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && String.instancehelper_equals(string8, "-"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && !String.instancehelper_equals(string9, "n/a"))
                {
                    throw new AssertionError();
                }
                if (!Sphinx3Loader.assertionsDisabled && int8 >= int6)
                {
                    throw new AssertionError();
                }
                if (useCDUnits)
                {
                    string text3 = new StringBuilder().append(string5).append(' ').append(string6).append(' ').append(string7).toString();
                    Unit   unit3;
                    if (String.instancehelper_equals(text3, text2))
                    {
                        unit3 = unit2;
                    }
                    else
                    {
                        LeftRightContext context = LeftRightContext.get(new Unit[]
                        {
                            (Unit)this.contextIndependentUnits.get(string6)
                        }, new Unit[]
                        {
                            (Unit)this.contextIndependentUnits.get(string7)
                        });
                        unit3 = this.unitManager.getUnit(string5, false, context);
                    }
                    text2 = text3;
                    unit2 = unit3;
                    if (this.logger.isLoggable(Level.FINE))
                    {
                        this.logger.fine(new StringBuilder().append("Loaded ").append(unit3).toString());
                    }
                    float[][]      transitionMatrix2 = (float[][])this.transitionsPool.get(int8);
                    SenoneSequence senoneSequence3   = senoneSequence2;
                    if (senoneSequence3 == null || !this.sameSenoneSequence(array2, ssid))
                    {
                        senoneSequence3 = this.getSenoneSequence(array2);
                    }
                    senoneSequence2 = senoneSequence3;
                    ssid            = array2;
                    SenoneHMM hmm2 = new SenoneHMM(unit3, senoneSequence3, transitionMatrix2, HMMPosition.lookup(string8));
                    this.hmmManager.put(hmm2);
                }
            }
            extendedStreamTokenizer.close();
        }
예제 #13
0
        protected internal virtual void loadHMMPool(bool useCDUnits, HTKLoader.HTKStruct htkModels, string path)
        {
            if (!this.tie1ph)
            {
                Iterator iterator = htkModels.hmmsHTK.get1phIt();
                while (iterator.hasNext())
                {
                    SingleHMM singleHMM = (SingleHMM)iterator.next();
                    if (singleHMM == null)
                    {
                        break;
                    }
                    string baseName = singleHMM.getName();
                    string text;
                    if (String.instancehelper_equals(baseName, "sil") || String.instancehelper_equals(baseName, "sp") || String.instancehelper_equals(baseName, "bb") || String.instancehelper_equals(baseName, "xx") || String.instancehelper_equals(baseName, "hh"))
                    {
                        text = "filler";
                    }
                    else
                    {
                        text = "nofiller";
                    }
                    int   trIdx   = singleHMM.trIdx;
                    int   nstates = singleHMM.getNstates();
                    int[] array   = new int[singleHMM.getNbEmittingStates()];
                    int   num     = 0;
                    for (int i = 0; i < nstates; i++)
                    {
                        if (singleHMM.isEmitting(i))
                        {
                            HTK.HMMState state = singleHMM.getState(i);
                            array[num] = htkModels.hmmsHTK.getStateIdx(state);
                            num++;
                        }
                    }
                    Unit unit = this.unitManager.getUnit(baseName, String.instancehelper_equals(text, "filler"));
                    this.contextIndependentUnits.put(unit.getName(), unit);
                    if (this.logger.isLoggable(Level.FINE))
                    {
                        this.logger.fine(new StringBuilder().append("Loaded ").append(unit).toString());
                    }
                    if (unit.isFiller() && String.instancehelper_equals(unit.getName(), "SIL"))
                    {
                        unit = UnitManager.__SILENCE;
                    }
                    float[][]      transitionMatrix = (float[][])this.matrixPool.get(trIdx);
                    SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                    SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup("-"));
                    this.hmmManager.put(hmm);
                }
            }
            else
            {
                for (int j = 0; j < htkModels.hmmsHTK.getNhmms(); j++)
                {
                    SingleHMM singleHMM = htkModels.hmmsHTK.getHMM(j);
                    if (singleHMM == null)
                    {
                        break;
                    }
                    string baseName = singleHMM.getBaseName();
                    if (!this.contextIndependentUnits.containsKey(baseName))
                    {
                        string text;
                        if (String.instancehelper_equals(baseName, "SIL") || String.instancehelper_equals(baseName, "SP") || String.instancehelper_equals(baseName, "BB") || String.instancehelper_equals(baseName, "XX") || String.instancehelper_equals(baseName, "HH"))
                        {
                            text = "filler";
                        }
                        else
                        {
                            text = "nofiller";
                        }
                        int   trIdx   = singleHMM.trIdx;
                        int   nstates = singleHMM.getNstates();
                        int[] array   = new int[singleHMM.getNbEmittingStates()];
                        int   num     = 0;
                        for (int i = 0; i < nstates; i++)
                        {
                            if (singleHMM.isEmitting(i))
                            {
                                HTK.HMMState state = singleHMM.getState(i);
                                array[num] = htkModels.hmmsHTK.getStateIdx(state);
                                num++;
                            }
                        }
                        Unit unit = this.unitManager.getUnit(baseName, String.instancehelper_equals(text, "filler"));
                        this.contextIndependentUnits.put(unit.getName(), unit);
                        if (this.logger.isLoggable(Level.FINE))
                        {
                            this.logger.fine(new StringBuilder().append("Loaded ").append(unit).toString());
                        }
                        if (unit.isFiller() && String.instancehelper_equals(unit.getName(), "SIL"))
                        {
                            unit = UnitManager.__SILENCE;
                        }
                        float[][]      transitionMatrix = (float[][])this.matrixPool.get(trIdx);
                        SenoneSequence senoneSequence   = this.getSenoneSequence(array);
                        SenoneHMM      hmm = new SenoneHMM(unit, senoneSequence, transitionMatrix, HMMPosition.lookup("-"));
                        this.hmmManager.put(hmm);
                    }
                }
            }
            string text2 = "";
            Unit   unit2 = null;

            int[]          ssid            = null;
            SenoneSequence senoneSequence2 = null;
            ArrayList      arrayList       = new ArrayList();
            Iterator       iterator2       = htkModels.hmmsHTK.get3phIt();

            while (iterator2.hasNext())
            {
                SingleHMM singleHMM2 = (SingleHMM)iterator2.next();
                if (singleHMM2 == null)
                {
                    break;
                }
                string baseName2 = singleHMM2.getBaseName();
                string text3     = singleHMM2.getLeft();
                string text4     = singleHMM2.getRight();
                if (String.instancehelper_equals(text3, "-"))
                {
                    text3 = "SIL";
                }
                if (String.instancehelper_equals(text4, "-"))
                {
                    text4 = "SIL";
                }
                string text5 = new StringBuilder().append(text3).append(' ').append(baseName2).append(' ').append(text4).toString();
                if (!arrayList.contains(text5))
                {
                    arrayList.add(text5);
                    text5 = "i";
                    int   trIdx2  = singleHMM2.trIdx;
                    int   nstates = singleHMM2.getNstates();
                    int[] array2  = new int[singleHMM2.getNbEmittingStates()];
                    int   num2    = 0;
                    for (int k = 0; k < nstates; k++)
                    {
                        if (singleHMM2.isEmitting(k))
                        {
                            HTK.HMMState state2 = singleHMM2.getState(k);
                            array2[num2] = htkModels.hmmsHTK.getStateIdx(state2);
                            num2++;
                        }
                    }
                    if (useCDUnits)
                    {
                        string text6 = new StringBuilder().append(baseName2).append(' ').append(text3).append(' ').append(text4).toString();
                        Unit   unit3;
                        if (String.instancehelper_equals(text6, text2))
                        {
                            unit3 = unit2;
                        }
                        else
                        {
                            LeftRightContext context = LeftRightContext.get(new Unit[]
                            {
                                (Unit)this.contextIndependentUnits.get(text3)
                            }, new Unit[]
                            {
                                (Unit)this.contextIndependentUnits.get(text4)
                            });
                            unit3 = this.unitManager.getUnit(baseName2, false, context);
                        }
                        text2 = text6;
                        unit2 = unit3;
                        if (this.logger.isLoggable(Level.FINE))
                        {
                            this.logger.fine(new StringBuilder().append("Loaded ").append(unit3).toString());
                        }
                        float[][]      transitionMatrix2 = (float[][])this.matrixPool.get(trIdx2);
                        SenoneSequence senoneSequence3   = senoneSequence2;
                        if (senoneSequence3 == null || !this.sameSenoneSequence(array2, ssid))
                        {
                            senoneSequence3 = this.getSenoneSequence(array2);
                        }
                        senoneSequence2 = senoneSequence3;
                        ssid            = array2;
                        SenoneHMM hmm2 = new SenoneHMM(unit3, senoneSequence3, transitionMatrix2, HMMPosition.lookup(text5));
                        this.hmmManager.put(hmm2);
                    }
                }
            }
        }
예제 #14
0
        private void saveHMMPool(bool flag, OutputStream outputStream, string text)
        {
            this.logger.info("Saving HMM file to: ");
            this.logger.info(text);
            if (outputStream == null)
            {
                string text2 = new StringBuilder().append("Error trying to write file ").append(this.location).append(text).toString();

                throw new IOException(text2);
            }
            PrintWriter printWriter = new PrintWriter(outputStream, true);
            int         num         = 0;
            int         num2        = 0;
            int         num3        = 0;
            int         num4        = 0;
            Iterator    iterator    = this.hmmManager.iterator();

            while (iterator.hasNext())
            {
                HMM hmm = (HMM)iterator.next();
                num4 += hmm.getOrder() + 1;
                if (((SenoneHMM)hmm).isContextDependent())
                {
                    num2++;
                }
                else
                {
                    num++;
                    num3 += hmm.getOrder();
                }
            }
            printWriter.println("0.3");
            printWriter.println(new StringBuilder().append(num).append(" n_base").toString());
            printWriter.println(new StringBuilder().append(num2).append(" n_tri").toString());
            printWriter.println(new StringBuilder().append(num4).append(" n_state_map").toString());
            int statesNum = this.mixtureWeights.getStatesNum();

            printWriter.println(new StringBuilder().append(statesNum).append(" n_tied_state").toString());
            printWriter.println(new StringBuilder().append(num3).append(" n_tied_ci_state").toString());
            int num5 = num;

            if (!Sphinx3Saver.assertionsDisabled && num5 != this.matrixPool.size())
            {
                throw new AssertionError();
            }
            printWriter.println(new StringBuilder().append(num5).append(" n_tied_tmat").toString());
            printWriter.println("#");
            printWriter.println("# Columns definitions");
            printWriter.println("#base lft  rt p attrib tmat      ... state id's ...");
            Iterator iterator2 = this.hmmManager.iterator();

            while (iterator2.hasNext())
            {
                HMM       hmm2      = (HMM)iterator2.next();
                SenoneHMM senoneHMM = (SenoneHMM)hmm2;
                if (!senoneHMM.isContextDependent())
                {
                    Unit   unit = senoneHMM.getUnit();
                    string name = unit.getName();
                    printWriter.print(new StringBuilder().append(name).append('\t').toString());
                    string text3 = "-";
                    printWriter.print(new StringBuilder().append(text3).append("   ").toString());
                    string text4 = "-";
                    printWriter.print(new StringBuilder().append(text4).append(' ').toString());
                    string text5 = senoneHMM.getPosition().toString();
                    printWriter.print(new StringBuilder().append(text5).append('\t').toString());
                    string text6 = (!unit.isFiller()) ? "n/a" : "filler";
                    printWriter.print(new StringBuilder().append(text6).append('\t').toString());
                    int num6 = this.matrixPool.indexOf(senoneHMM.getTransitionMatrix());
                    if (!Sphinx3Saver.assertionsDisabled && num6 >= num5)
                    {
                        throw new AssertionError();
                    }
                    printWriter.print(new StringBuilder().append(num6).append("\t").toString());
                    SenoneSequence senoneSequence = senoneHMM.getSenoneSequence();
                    Senone[]       senones        = senoneSequence.getSenones();
                    Senone[]       array          = senones;
                    int            num7           = array.Length;
                    for (int i = 0; i < num7; i++)
                    {
                        Senone @object = array[i];
                        int    num8    = this.senonePool.indexOf(@object);
                        if (!Sphinx3Saver.assertionsDisabled && (num8 < 0 || num8 >= num3))
                        {
                            throw new AssertionError();
                        }
                        printWriter.print(new StringBuilder().append(num8).append("\t").toString());
                    }
                    printWriter.println("N");
                    if (this.logger.isLoggable(Level.FINE))
                    {
                        this.logger.fine(new StringBuilder().append("Saved ").append(unit).toString());
                    }
                }
            }
            iterator2 = this.hmmManager.iterator();
            while (iterator2.hasNext())
            {
                HMM       hmm2      = (HMM)iterator2.next();
                SenoneHMM senoneHMM = (SenoneHMM)hmm2;
                if (senoneHMM.isContextDependent())
                {
                    Unit             unit             = senoneHMM.getUnit();
                    LeftRightContext leftRightContext = (LeftRightContext)unit.getContext();
                    Unit[]           leftContext      = leftRightContext.getLeftContext();
                    Unit[]           rightContext     = leftRightContext.getRightContext();
                    if (!Sphinx3Saver.assertionsDisabled && (leftContext.Length != 1 || rightContext.Length != 1))
                    {
                        throw new AssertionError();
                    }
                    string text5 = unit.getName();
                    printWriter.print(new StringBuilder().append(text5).append('\t').toString());
                    string text6 = leftContext[0].getName();
                    printWriter.print(new StringBuilder().append(text6).append("   ").toString());
                    string name2 = rightContext[0].getName();
                    printWriter.print(new StringBuilder().append(name2).append(' ').toString());
                    string text7 = senoneHMM.getPosition().toString();
                    printWriter.print(new StringBuilder().append(text7).append('\t').toString());
                    string text8 = (!unit.isFiller()) ? "n/a" : "filler";
                    if (!Sphinx3Saver.assertionsDisabled && !String.instancehelper_equals(text8, "n/a"))
                    {
                        throw new AssertionError();
                    }
                    printWriter.print(new StringBuilder().append(text8).append('\t').toString());
                    int num9 = this.matrixPool.indexOf(senoneHMM.getTransitionMatrix());
                    if (!Sphinx3Saver.assertionsDisabled && num9 >= num5)
                    {
                        throw new AssertionError();
                    }
                    printWriter.print(new StringBuilder().append(num9).append("\t").toString());
                    SenoneSequence senoneSequence2 = senoneHMM.getSenoneSequence();
                    Senone[]       senones2        = senoneSequence2.getSenones();
                    Senone[]       array2          = senones2;
                    int            num8            = array2.Length;
                    for (int j = 0; j < num8; j++)
                    {
                        Senone object2 = array2[j];
                        int    num10   = this.senonePool.indexOf(object2);
                        if (!Sphinx3Saver.assertionsDisabled && (num10 < 0 || num10 >= statesNum))
                        {
                            throw new AssertionError();
                        }
                        printWriter.print(new StringBuilder().append(num10).append("\t").toString());
                    }
                    printWriter.println("N");
                    if (this.logger.isLoggable(Level.FINE))
                    {
                        this.logger.fine(new StringBuilder().append("Saved ").append(unit).toString());
                    }
                }
            }
            outputStream.close();
        }