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);
        }
Example #2
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);
        }
        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();
        }