/**
  * Counts all the tokens in the active list (and displays them). This is an
  * expensive operation.
  */
 protected void showTokenCount()
 {
     if (logger.IsInfoEnabled)
     {
         HashSet <Token> tokenSet = new HashSet <Token>();
         var             tokens   = JavaToCs.GetTokenCollection(activeList);
         foreach (Token token in tokens)
         {
             var tok = token;
             while (tok != null)
             {
                 tokenSet.Add(tok);
                 tok = tok.getPredecessor();
             }
         }
         logger.Info("Token Lattice size: " + tokenSet.Count);
         tokenSet = new HashSet <Token>();
         foreach (Token token in resultList)
         {
             var tok = token;
             while (tok != null)
             {
                 tokenSet.Add(tok);
                 tok = tok.getPredecessor();
             }
         }
         logger.Info("Result Lattice size: " + tokenSet.Count);
     }
 }
        /**
         * Because the growBranches() is called although no data is left after the
         * last speech frame, the ordering of the active-list might depend on the
         * transition probabilities and (penalty-scores) only. Therefore we need to
         * undo the last grow-step up to final states or the last emitting state in
         * order to fix the list.
         *
         * @return newly created list
         */
        protected ActiveList undoLastGrowStep()
        {
            ActiveList fixedList = activeList.newInstance();

            var tokens = JavaToCs.GetTokenCollection(activeList);

            foreach (Token token in tokens)
            {
                Token curToken = token.getPredecessor();

                // remove the final states that are not the real final ones because
                // they're just hide prior final tokens:
                while (curToken.getPredecessor() != null &&
                       ((curToken.isFinal() &&
                         curToken.getPredecessor() != null && !curToken
                         .getPredecessor().isFinal()) ||
                        (curToken.isEmitting() && curToken.getData() == null) // the
                                                                              // so
                                                                              // long
                                                                              // not
                                                                              // scored
                                                                              // tokens
                        || (!curToken.isFinal() && !curToken.isEmitting())))
                {
                    curToken = curToken.getPredecessor();
                }

                fixedList.add(curToken);
            }

            return(fixedList);
        }
        /**
         * Goes through the active list of tokens and expands each token, finding
         * the set of successor tokens until all the successor tokens are emitting
         * tokens.
         */
        protected void growBranches()
        {
            int mapSize = activeList.size() * 10;

            if (mapSize == 0)
            {
                mapSize = 1;
            }
            growTimer.start();
            bestTokenMap = new Dictionary <SearchState, Token>(mapSize);
            ActiveList oldActiveList = activeList;

            resultList    = new List <Token>();
            activeList    = activeListFactory.newInstance();
            threshold     = oldActiveList.getBeamThreshold();
            wordThreshold = oldActiveList.getBestScore() + logRelativeWordBeamWidth;

            var tokens = JavaToCs.GetTokenCollection(oldActiveList);

            foreach (Token token in tokens)
            {
                collectSuccessorTokens(token);
            }
            growTimer.stop();
            if (logger.IsInfoEnabled)
            {
                int hmms = activeList.size();
                totalHmms += hmms;
                logger.Info("Frame: " + currentFrameNumber + " Hmms: " + hmms
                            + "  total " + totalHmms);
            }
        }
        //@Override
        public override void newProperties(PropertySheet ps)
        {
            base.newProperties(ps);

            //logger = ps.getLogger();
            name = ps.getInstanceName();

            logMath = (LogMath)ps.getComponent(PROP_LOG_MATH);

            linguist          = (edu.cmu.sphinx.linguist.Linguist)ps.getComponent(PROP_LINGUIST);
            pruner            = (Pruner)ps.getComponent(PROP_PRUNER);
            scorer            = (AcousticScorer)ps.getComponent(PROP_SCORER);
            activeListFactory = (ActiveListFactory)ps
                                .getComponent(PROP_ACTIVE_LIST_FACTORY);
            showTokenCountP = JavaToCs.ConvertBool(ps.getBoolean(PROP_SHOW_TOKEN_COUNT));

            double relativeWordBeamWidth = ps.getDouble(PROP_RELATIVE_WORD_BEAM_WIDTH);

            growSkipInterval         = ps.getInt(PROP_GROW_SKIP_INTERVAL);
            wantEntryPruning         = JavaToCs.ConvertBool(ps.getBoolean(PROP_WANT_ENTRY_PRUNING));
            logRelativeWordBeamWidth = logMath.linearToLog(relativeWordBeamWidth);

            this.keepAllTokens = true;
        }