Пример #1
0
        /**
         * /// Keeps track of and reports all of the active word histories for the given active list
         *
         * /// @param activeList the active list to track
         */
        private void monitorWords(ActiveList activeList)
        {
            //        WordTracker tracker1 = new WordTracker(currentFrameNumber);
            //
            //        for (Token t : activeList) {
            //            tracker1.add(t);
            //        }
            //        tracker1.dump();
            //
            //        TokenTracker tracker2 = new TokenTracker();
            //
            //        for (Token t : activeList) {
            //            tracker2.add(t);
            //        }
            //        tracker2.dumpSummary();
            //        tracker2.dumpDetails();
            //
            //        TokenTypeTracker tracker3 = new TokenTypeTracker();
            //
            //        for (Token t : activeList) {
            //            tracker3.add(t);
            //        }
            //        tracker3.dump();

            //        StateHistoryTracker tracker4 = new StateHistoryTracker(currentFrameNumber);

            //        for (Token t : activeList) {
            //            tracker4.add(t);
            //        }
            //        tracker4.dump();
        }
Пример #2
0
        /** Gets the initial grammar node from the linguist and creates a GrammarNodeToken */
        protected void localStart()
        {
            ISearchGraph searchGraph = linguist.getSearchGraph();

            currentFrameNumber    = 0;
            curTokensScored.value = 0;
            numStateOrder         = searchGraph.getNumStateOrder();
            activeListManager.setNumStateOrder(numStateOrder);
            if (buildWordLattice)
            {
                loserManager = new AlternateHypothesisManager(maxLatticeEdges);
            }

            ISearchState state = searchGraph.getInitialState();

            activeList = activeListManager.getEmittingList();
            activeList.add(new Token(state, currentFrameNumber));

            clearCollectors();

            growBranches();
            growNonEmittingBranches();
            // tokenTracker.setEnabled(false);
            // tokenTracker.startUtterance();
        }
Пример #3
0
        /**
         * /// 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 <ISearchState, Token>(mapSize);
            ActiveList oldActiveList = activeList;

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

            foreach (Token token in oldActiveList.getTokens())
            {
                collectSuccessorTokens(token);
            }
            growTimer.stop();

            #if Debug
            int hmms = activeList.size();
            totalHmms += hmms;
            Trace.WriteLine("Frame: " + currentFrameNumber + " Hmms: "
                            + hmms + "  total " + totalHmms);
                #endif
        }
Пример #4
0
        /**
         * /// Performs the recognition for the given number of frames.
         *
         * /// @param nFrames the number of frames to recognize
         * /// @return the current result or null if there is no Result (due to the lack of frames to recognize)
         */
        override public Result recognize(int nFrames)
        {
            bool   done   = false;
            Result result = null;

            streamEnd = false;

            for (int i = 0; i < nFrames && !done; i++)
            {
                done = recognize();
            }

            // generate a new temporary result if the current token is based on a final search state
            // remark: the first check for not null is necessary in cases that the search space does not contain scoreable tokens.
            if (activeList.getBestToken() != null)
            {
                // to make the current result as correct as possible we undo the last search graph expansion here
                ActiveList fixedList = undoLastGrowStep();

                // Now create the result using the fixed active-list.
                if (!streamEnd)
                {
                    result = new Results.Result(fixedList, resultList, currentFrameNumber, done);
                }
            }

            if (_showTokenCount)
            {
                showTokenCount();
            }

            return(result);
        }
Пример #5
0
        /** Removes unpromising branches from the active list */
        protected void pruneBranches()
        {
            int startSize = activeList.size();

            pruneTimer.start();
            activeList        = pruner.prune(activeList);
            beamPruned.value += startSize - activeList.size();
            pruneTimer.stop();
        }
Пример #6
0
        /**
         * /// Keeps track of and reports statistics about the number of active states
         *
         * /// @param activeList the active list of states
         */
        private void monitorStates(ActiveList activeList)
        {
            tokenSum += activeList.size();
            tokenCount++;

            if ((tokenCount % 1000) == 0)
            {
                Trace.WriteLine("Average Tokens/State: " + (tokenSum / tokenCount));
            }
        }
Пример #7
0
        /**
         * /// Adds the given token to the list
         *
         * /// @param token the token to add
         */
        override public void add(Token token)
        {
            ActiveList activeList = findListFor(token);

            if (activeList == null)
            {
                throw new Exception("Cannot find ActiveList for "
                                    + token.getSearchState().GetType().Name);
            }
            activeList.add(token);
        }
Пример #8
0
        /// <summary>
        /// Gets the initial grammar node from the linguist and creates a GrammarNodeToken.
        /// </summary>
        protected void localStart()
        {
            currentFrameNumber    = 0;
            curTokensScored.value = 0;
            ActiveList   newActiveList = activeListFactory.newInstance();
            ISearchState state         = linguist.getSearchGraph().getInitialState();

            newActiveList.add(new Token(state, currentFrameNumber));
            activeList = newActiveList;

            growBranches();
        }
Пример #9
0
 /** Grow the non-emitting branches, until the tokens reach an emitting state. */
 private void growNonEmittingBranches()
 {
     for (IEnumerator <ActiveList> i = activeListManager.getNonEmittingListIterator(); i.MoveNext();)
     {
         activeList = i.Current;
         if (activeList != null)
         {
             // TO DO: look for new implementation
             //i.Current.Remove()
             pruneBranches();
             growBranches();
         }
     }
 }
Пример #10
0
        private Boolean recognize()
        {
            activeList = activeListManager.getEmittingList();
            Boolean more = scoreTokens();

            if (more)
            {
                pruneBranches();
                currentFrameNumber++;
                if (growSkipInterval == 0 || (currentFrameNumber % growSkipInterval) != 0)
                {
                    clearCollectors();
                    growEmittingBranches();
                    growNonEmittingBranches();
                }
            }
            return(!more);
        }
Пример #11
0
 /**
  * /// Sets the ActiveList.
  *
  * /// @param activeList the new ActiveList
  */
 public void setActiveList(ActiveList activeList)
 {
     this.activeList = activeList;
 }
Пример #12
0
 /** Removes unpromising branches from the active list */
 protected void pruneBranches()
 {
     pruneTimer.start();
     activeList = pruner.prune(activeList);
     pruneTimer.stop();
 }
Пример #13
0
 /**
  * /// Dumps out debugging info for the given active list
  *
  * /// @param al the active list to dump
  */
 private void dumpList(ActiveList al)
 {
     Trace.WriteLine("Size: " + al.size() + " Best token: " + al.getBestToken());
 }
Пример #14
0
        /**
         * /// Clears emitting list in manager
         */
        override public void clearEmittingList()
        {
            ActiveList list = currentActiveLists[currentActiveLists.Length - 1];

            currentActiveLists[currentActiveLists.Length - 1] = list.newInstance();
        }
Пример #15
0
        /**
         * /// Replaces an old token with a new token
         *
         * /// @param oldToken the token to replace (or null in which case, replace works like add).
         * /// @param newToken the new token to be placed in the list.
         */
        //override public void replace(Token oldToken, Token newToken)
        //{
        //    ActiveList activeList = findListFor(oldToken);
        //    Trace.Assert(activeList != null);
        //    activeList.replace(oldToken, newToken);
        //}


        /**
         * /// Returns the emitting ActiveList from the manager
         *
         * /// @return the emitting ActiveList
         */
        override public ActiveList getEmittingList()
        {
            ActiveList list = currentActiveLists[currentActiveLists.Length - 1];

            return(list);
        }