/// <summary>
 ///  Puts the probability into the map.
 /// </summary>
 /// <param name="wordSequence">The tag for the prob.</param>
 /// <param name="logProb">The probability in log math base.</param>
 /// <param name="logBackoff">The backoff probability in log math base.</param>
 private void Put(WordSequence wordSequence, float logProb, float logBackoff)
 {
     // System.out.println("Putting " + wordSequence + " p " + logProb
     // + " b " + logBackoff);
     Java.Put(_map, wordSequence, new Probability(logProb, logBackoff));
     Java.Add(_tokens, wordSequence);
 }
        /**
         * Returns the NGrams of the given word sequence
         *
         * @param wordSequence the word sequence from which to get the buffer
         * @return the NGramBuffer of the word sequence
         */
        private NGramBuffer GetNGramBuffer(WordSequence wordSequence)
        {
            NGramBuffer nGramBuffer = null;
            var         order       = wordSequence.Size;

            if (order > 1)
            {
                nGramBuffer = _loadedNGramBuffers[order - 1].Get(wordSequence); // better
            }
            // when
            // using
            // containsKey

            if (nGramBuffer == null)
            {
                nGramBuffer = LoadNGramBuffer(wordSequence);

                if (nGramBuffer != null)
                {
                    Java.Put(_loadedNGramBuffers[order - 1], wordSequence, nGramBuffer); // optimizable
                }
                // by
                // adding
                // an
                // 'empty'
                // nGramBuffer
            }

            return(nGramBuffer);
        }
Exemple #3
0
 /**
  * /// Create the entry point table give the set of all possible entry point units
  *
  * /// @param entryPointCollection the set of possible entry points
  */
 public EntryPointTable(IEnumerable <Unit> entryPointCollection, HMMTree parent)
 {
     _entryPoints = new Dictionary <Unit, EntryPoint>();
     foreach (var unit in entryPointCollection)
     {
         Java.Put(_entryPoints, unit, new EntryPoint(unit, parent));
     }
 }
Exemple #4
0
        /// <summary>
        /// Add a word hypothesis to this confusion set.
        /// </summary>
        /// <param name="word">The hypothesis to add.</param>
        public void AddWordHypothesis(WordResult word)
        {
            var wordSet = GetWordSet(word.GetConfidence());

            if (wordSet == null)
            {
                wordSet = new HashSet <WordResult>();
                Java.Put(this, word.GetConfidence(), wordSet);
            }
            wordSet.Add(word);
        }
        /// <summary>
        ///Purge all but max number of alternate preceding token hypotheses.
        /// </summary>
        public void Purge()
        {
            int max = _maxEdges - 1;

            foreach (var entry in _viterbiLoserMap.ToList())
            {
                List <Token> list = entry.Value;
                list.Sort(new ScoreableComparator());
                List <Token> newList = list.GetRange(0, list.Count > max ? max : list.Count);
                Java.Put(_viterbiLoserMap, entry.Key, newList);
            }
        }
Exemple #6
0
        /// <summary>
        /// A version of createEntryPointMap that compresses common hmms across all entry points.
        /// </summary>
        public void CreateEntryPointMap()
        {
            Dictionary <IHMM, Node>    map           = new Dictionary <IHMM, Node>();
            Dictionary <IHMM, HMMNode> singleUnitMap = new Dictionary <IHMM, HMMNode>();

            foreach (Unit lc in _parent.ExitPoints)
            {
                Node epNode = new Node(LogMath.LogZero);
                foreach (Unit rc in GetEntryPointRC())
                {
                    IHMM hmm = _parent.HMMPool.GetHMM(BaseUnit, lc, rc, HMMPosition.Begin);
                    if (hmm == null)
                    {
                        continue;
                    }
                    Node addedNode = null;
                    if (map.ContainsKey(hmm))
                    {
                        addedNode = map[hmm];
                    }
                    if (addedNode == null)
                    {
                        addedNode = epNode.AddSuccessor(hmm, Probability);
                        map.Add(hmm, addedNode);
                    }
                    else
                    {
                        epNode.PutSuccessor(hmm, addedNode);
                    }

                    nodeCount++;
                    ConnectEntryPointNode(addedNode, rc);
                }
                ConnectSingleUnitWords(lc, epNode, singleUnitMap);
                Java.Put(UnitToEntryPointMap, lc, epNode);
            }
        }
Exemple #7
0
        /// <summary>
        /// Returns the next Data object, which is usually a window of the input Data, with the windowing function applied to
        /// it.
        /// </summary>
        /// <returns>the next available Data object, returns null if no Data object is available</returns>
        public override IData GetData()
        {
            if (_outputQueue.Count == 0)
            {
                var input = Predecessor.GetData();

                if (input != null)
                {
                    if (input is DoubleData)
                    {
                        var data = (DoubleData)input;
                        // System.err.print("to windower: ");
                        // System.err.println(Arrays.toString(data.getValues()));
                        if (_currentFirstSampleNumber == -1)
                        {
                            _currentFirstSampleNumber = data.FirstSampleNumber;
                        }

                        // should not be necessary if all DataProcessor would forward Signals. Unfortunately this
                        // is currently not the case.
                        CreateWindow(data.SampleRate);

                        // process the Data, and output the windows
                        Process(data);
                    }
                    else
                    {
                        if (input is DataStartSignal)
                        {
                            var startSignal = (DataStartSignal)input;

                            CreateWindow(startSignal.SampleRate);

                            // attach the frame-length and the shift-length to the start-signal to allow
                            // detection of incorrect frontend settings
                            var props = startSignal.GetProps();
                            Java.Put(props, WindowShiftSamples, _windowShift);
                            Java.Put(props, WindowSizeSamples, _cosineWindow.Length);

                            // reset the current first sample number
                            _currentFirstSampleNumber = -1;
                        }
                        else if (input is SpeechStartSignal)
                        {
                            // reset the current first sample number
                            _currentFirstSampleNumber = -1;
                        }
                        else if (input is DataEndSignal || input is SpeechEndSignal)
                        {
                            // end of utterance handling
                            ProcessUtteranceEnd();
                        }

                        _outputQueue.Add(input);
                    }
                }
            }

            if (_outputQueue.Count != 0)
            {
                var output = _outputQueue[0];
                _outputQueue.RemoveAt(0);
                if (output is DoubleData)
                {
                    Debug.Assert(((DoubleData)output).Values.Length == _cosineWindow.Length);
                }
                return(output);
            }
            return(null);
        }
 public static void TagAsVadStream(DataStartSignal dsSignal)
 {
     Java.Put(dsSignal.GetProps(), SpeechTaggedFeatureStream, true);
     //dsSignal.getProps().Add(, true);
 }
 /** Add a new RuleGrammar comment. */
 public void AddRuleDocComment(String rname, String comment)
 {
     Java.Put(_ruleDocComments, rname, comment);
 }
 /** Add a new import comment. */
 public void AddImportDocComment(JSGFRuleName imp, String comment)
 {
     Java.Put(_importDocComments, imp.ToString(), comment);
 }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HMMPool"/> class.
        /// </summary>
        /// <param name="model">The model to use for the pool</param>
        /// <param name="unitManager">The unit manager.</param>
        /// <exception cref="System.Exception">
        /// LexTreeLinguist: Unsupported left context size
        /// or
        /// LexTreeLinguist: Unsupported right context size
        /// </exception>
        public HMMPool(AcousticModel model, UnitManager unitManager)
        {
            var maxCiUnits = 0;

            this.Model        = model;
            this._unitManager = unitManager;
            TimerPool.GetTimer(this, "Build HMM Pool").Start();

            if (model.GetLeftContextSize() != 1)
            {
                throw new Exception("LexTreeLinguist: Unsupported left context size");
            }

            if (model.GetRightContextSize() != 1)
            {
                throw new Exception("LexTreeLinguist: Unsupported right context size");
            }

            // count CI units:
            var i = model.GetContextIndependentUnitIterator();

            while (i.MoveNext())
            {
                var unit = i.Current;
                //this.LogInfo("CI unit " + unit);
                if (unit.BaseID > maxCiUnits)
                {
                    maxCiUnits = unit.BaseID;
                }
            }

            NumCiUnits = maxCiUnits + 1;

            _unitTable = new Unit[NumCiUnits * NumCiUnits * NumCiUnits];
            var iHMM = model.GetHMMIterator();

            while (iHMM.MoveNext())
            {
                var hmm  = iHMM.Current;
                var unit = hmm.Unit;
                var id   = GetId(unit);
                _unitTable[id] = unit;

                //this.LogInfo("Unit " + unit + " id " + id);
            }

            // build up the hmm table to allow quick access to the hmms
            _hmmTable = new Dictionary <HMMPosition, IHMM[]>();
            foreach (HMMPosition position in Enum.GetValues(typeof(HMMPosition)))
            {
                var hmms = new IHMM[_unitTable.Length];
                Java.Put(_hmmTable, position, hmms);
                //hmmTable.Put(position, hmms);
                for (var j = 1; j < _unitTable.Length; j++)
                {
                    var unit = _unitTable[j];
                    if (unit == null)
                    {
                        unit = SynthesizeUnit(j);
                    }
                    if (unit != null)
                    {
                        hmms[j] = model.LookupNearestHMM(unit, position, false);
                        Debug.Assert(hmms[j] != null);
                    }
                }
            }
            TimerPool.GetTimer(this, "Build HMM Pool").Stop();
        }