Пример #1
0
 /**
  * /// Constructs a LexTreeUnitState
  *
  * /// @param wordSequence the history of words
  */
 public LexTreeUnitState(HMMNode hmmNode, WordSequence wordSequence,
                         float smearTerm, float smearProb, float languageProbability,
                         float insertionProbability, Node parentNode, LexTreeLinguist parent)
     : base(hmmNode, wordSequence, smearTerm, smearProb, parent)
 {
     _logInsertionProbability = insertionProbability;
     _logLanguageProbability  = languageProbability;
     _parentNode = parentNode;
     _parent     = parent;
 }
Пример #2
0
 /**
  * /// Constructs a LexTreeWordState
  *
  * /// @param wordNode       the word node
  * /// @param wordSequence   the sequence of words triphone context
  * /// @param languageProbability the probability of this word
  */
 public LexTreeWordState(WordNode wordNode, HMMNode lastNode,
                         WordSequence wordSequence, float smearTerm, float smearProb,
                         float languageProbability, LexTreeLinguist _parent)
     : base(wordNode, wordSequence, smearTerm, smearProb, _parent)
 {
     // Trace.WriteLine(string.Format("LexTreeWordState Created with values wordNode: {0}, lastNode: {1}, wordSequence: {2}, smearTerm: {3}, smearProb: {4}, languageProbability: {5}",
     // wordNode, lastNode, wordSequence, smearTerm, smearProb, languageProbability));
     this._lastNode          = lastNode;
     _logLanguageProbability = languageProbability;
     //if (wordNode.ToString().Contains("NSN"))
     //{
     //    this.LogInfo("FOUND NOISE!");
     //}
 }
Пример #3
0
        /// <summary>
        /// Connects the single unit words associated with this entry point.   The singleUnitWords list contains all
        /// single unit pronunciations that have as their sole unit, the unit associated with this entry point. Entry
        /// points for these words are added to the epNode for all possible left (exit) and right (entry) contexts.
        /// </summary>
        /// <param name="lc">the left context</param>
        /// <param name="epNode">the entry point node</param>
        /// <param name="map"></param>
        private void ConnectSingleUnitWords(Unit lc, Node epNode, Dictionary <IHMM, HMMNode> map)
        {
            if (!_singleUnitWords.IsEmpty())
            {
                foreach (Unit rc in _parent.EntryPoints)
                {
                    IHMM hmm = _parent.HMMPool.GetHMM(BaseUnit, lc, rc, HMMPosition.Single);
                    if (hmm == null)
                    {
                        continue;
                    }
                    HMMNode tailNode = null;
                    if (hmm != null && map.ContainsKey(hmm))
                    {
                        tailNode = map[hmm];
                    }

                    if (tailNode == null)
                    {
                        tailNode = (HMMNode)epNode.AddSuccessor(hmm, Probability);
                        map.Add(hmm, tailNode);
                    }
                    else
                    {
                        epNode.PutSuccessor(hmm, tailNode);
                    }
                    WordNode wordNode;
                    tailNode.AddRC(rc);
                    nodeCount++;

                    foreach (Pronunciation p in _singleUnitWords)
                    {
                        if (p.Word == _parent.Dictionary.GetSentenceStartWord())
                        {
                            _parent.InitialNode = new InitialWordNode(p, tailNode);
                        }
                        else
                        {
                            float prob = _parent.GetWordUnigramProbability(p.Word);
                            wordNode = tailNode.AddSuccessor(p, prob, _parent.WordNodeMap);
                            if (p.Word == _parent.Dictionary.GetSentenceEndWord())
                            {
                                _parent.sentenceEndWordNode = wordNode;
                            }
                        }
                        nodeCount++;
                    }
                }
            }
        }
Пример #4
0
        /**
         * /// Creates a word search state for the given word node
         *
         * /// @param wordNode the wordNode
         *
         *
         * /// @return the search state for the wordNode
         */
        protected ISearchStateArc CreateWordStateArc(WordNode wordNode,
                                                     HMMNode lastUnit, LexTreeState previous)
        {
            //TODO: UNCOMMENT DURING RELEASE
            //this.LogInfo("CWSA " + wordNode + " fup " /*+ fixupProb*/);
            float languageProbability = Parent.LogOne;
            Word  nextWord            = wordNode.GetWord();
            float smearTerm           = previous.SmearTerm;

            if (nextWord.IsFiller && !Equals(nextWord, Parent.SentenceEndWord))
            {
                return(new LexTreeWordState(wordNode, lastUnit,
                                            _wordSequence,
                                            smearTerm, Parent.LogOne, languageProbability, Parent));
            }

            WordSequence nextWordSequence = _wordSequence.AddWord(nextWord, Parent.MaxDepth);
            float        probability      = Parent.LanguageModel.GetProbability(nextWordSequence) * Parent.LanguageWeight;

            smearTerm = Parent.GetSmearTermFromLanguageModel(nextWordSequence);

            //this.LogInfo("LP " + nextWordSequence + " " /*+ logProbability*/);
            //    subtract off the previously applied smear probability
            languageProbability = probability - previous.SmearProb;

            //Boolean collapse = (probability.depth < parent.maxDepth - 1) || !parent.fullWordHistories;

            if (Equals(nextWord, Parent.SentenceEndWord))
            {
                return(new LexTreeEndWordState(wordNode, lastUnit,
                                               nextWordSequence.Trim(Parent.MaxDepth - 1),
                                               smearTerm, Parent.LogOne, languageProbability, Parent));
            }

            return(new LexTreeWordState(wordNode, lastUnit,
                                        nextWordSequence.Trim(Parent.MaxDepth - 1),
                                        smearTerm, Parent.LogOne, languageProbability, Parent));
        }
Пример #5
0
        /**
         * /// Creates a unit search state for the given unit node
         *
         * /// @param hmmNode the unit node
         *
         * /// @return the search state
         */
        public ISearchStateArc CreateUnitStateArc(HMMNode hmmNode, LexTreeState previous)
        {
            ISearchStateArc arc;

            float insertionProbability = Parent.CalculateInsertionProbability(hmmNode);
            float smearProbability     = Parent.GetUnigramSmear(hmmNode) + previous.SmearTerm;
            float languageProbability  = smearProbability - previous.SmearProb;

            //if we want a unit state create it, otherwise
            //get the first hmm state of the unit

            if (Parent.GenerateUnitStates)
            {
                arc = new LexTreeUnitState(hmmNode, WordHistory, previous.SmearTerm, smearProbability, languageProbability,
                                           insertionProbability, Parent);
            }
            else
            {
                IHMM hmm = hmmNode.HMM;
                arc = new LexTreeHmmState(hmmNode, WordHistory, previous.SmearTerm, smearProbability, hmm.GetInitialState(),
                                          languageProbability, insertionProbability, null, Parent);
            }
            return(arc);
        }
Пример #6
0
        /// <summary>
        /// Adds a child node holding an hmm to the successor.  If a node similar to the child has already been added, we use
        /// the previously added node, otherwise we add this. Also, we record the base unit of the child in the set of right
        /// context
        /// </summary>
        /// <param name="hmm">the hmm to add</param>
        /// <param name="probability"></param>
        /// <returns>the node that holds the hmm (new or old)</returns>
        public Node AddSuccessor(IHMM hmm, float probability)
        {
            if (hmm == null)
            {
                return(null);
            }
            Node child         = null;
            Node matchingChild = GetSuccessor(hmm);

            if (matchingChild == null)
            {
                child = new HMMNode(hmm, probability);
                PutSuccessor(hmm, child);
            }
            else
            {
                if (matchingChild.UnigramProbability < probability)
                {
                    matchingChild.UnigramProbability = probability;
                }
                child = matchingChild;
            }
            return(child);
        }
Пример #7
0
 /// <summary>
 /// Creates an InitialWordNode
 /// </summary>
 /// <param name="pronunciation">the pronunciation</param>
 /// <param name="parent">the parent node</param>
 public InitialWordNode(Pronunciation pronunciation, HMMNode parent)
     : base(pronunciation, LogMath.LogOne)
 {
     _parent = parent;
 }