Exemple #1
0
            /**
             * /// Attaches the given unit to the given tail, expanding the unit if necessary. If an identical unit is already
             * /// attached, then this path is folded into the existing path.
             *
             * /// @param parent       the parent state
             * /// @param tail         the place to attach the unit to
             * /// @param units        the set of units
             * /// @param which        the index into the set of units
             * /// @param leftContext  the left context for the unit
             * /// @param rightContext the right context for the unit
             * /// @return the tail of the added unit (or null if the path was folded onto an already expanded path.
             */
            private SentenceHMMState AttachUnit(PronunciationState parent,
                                                SentenceHMMState tail, Unit[] units, int which,
                                                UnitContext leftContext, UnitContext rightContext)
            {
                Unit[]           lc = GetLC(leftContext, units, which);
                Unit[]           rc = GetRC(units, which, rightContext);
                UnitContext      actualRightContext = UnitContext.Get(rc);
                LeftRightContext context            = LeftRightContext.Get(lc, rc);
                Unit             cdUnit             = _parent.UnitManager.GetUnit(units[which].Name, units[which].IsFiller, context);
                UnitState        unitState          = new ExtendedUnitState(parent, which, cdUnit);
                float            logInsertionProbability;

                if (unitState.Unit.IsSilence)
                {
                    logInsertionProbability = _parent.LogSilenceInsertionProbability;
                }
                else if (unitState.Unit.IsFiller)
                {
                    logInsertionProbability = _parent._logFillerInsertionProbability;
                }
                else if (unitState.GetWhich() == 0)
                {
                    logInsertionProbability = _parent._logWordInsertionProbability;
                }
                else
                {
                    logInsertionProbability = _parent._logUnitInsertionProbability;
                }
                // check to see if this state already exists, if so
                // branch to it and we are done, otherwise, branch to
                // the new state and expand it.
                SentenceHMMState existingState = GetExistingState(unitState);

                if (existingState != null)
                {
                    AttachState(tail, existingState, LogOne, logInsertionProbability);
                    // T(" Folding " + existingState);
                    return(null);
                }
                else
                {
                    AttachState(tail, unitState, LogOne, logInsertionProbability);
                    AddStateToCache(unitState);
                    // T(" Attaching " + unitState);
                    tail = ExpandUnit(unitState);
                    // if we are attaching the last state of a word, then
                    // we add it to the exitPoints table. the exit points
                    // table is indexed by a ContextPair, consisting of
                    // the exiting left context and the right context.
                    if (unitState.IsLast())
                    {
                        UnitContext nextLeftContext = GenerateNextLeftContext(leftContext, units[which]);
                        ContextPair cp = ContextPair.Get(nextLeftContext, actualRightContext);
                        // T(" Adding to exitPoints " + cp);
                        AddExitPoint(cp, tail);
                    }
                    return(tail);
                }
            }
Exemple #2
0
            /**
             * /// Retrieves the starting UnitContext for the given pronunciation
             *
             * /// @param pronunciation the pronunciation
             * /// @return a UnitContext representing the starting context of the pronunciation
             */
            private UnitContext GetStartingContext(Pronunciation pronunciation)
            {
                int maxSize = GetRightContextSize();

                Unit[] units   = pronunciation.Units;
                Unit[] context = units.Length > maxSize?Arrays.copyOf(units, maxSize) : units;

                return(UnitContext.Get(context));
            }
Exemple #3
0
            /// <summary>
            /// Generates the next left context based upon a previous context and a unit
            /// </summary>
            /// <param name="prevLeftContext">the previous left context</param>
            /// <param name="unit">the current unit</param>
            /// <returns></returns>
            UnitContext GenerateNextLeftContext(UnitContext prevLeftContext, Unit unit)
            {
                Unit[] prevUnits = prevLeftContext.Units;
                int    actSize   = Math.Min(prevUnits.Length, GetLeftContextSize());

                if (actSize == 0)
                {
                    return(UnitContext.Empty);
                }
                Unit[] leftUnits = Arrays.copyOfRange(prevUnits, 1, actSize + 1);
                leftUnits[actSize - 1] = unit;
                return(UnitContext.Get(leftUnits));
            }
Exemple #4
0
            /// <summary>
            /// Retrieves the set of trailing contexts for this node. the trailing contexts are the set of Unit[] with a size
            /// equal to the maximum left context size that align with the end of the node
            /// </summary>
            /// <returns></returns>
            List <UnitContext> GetEndingContexts()
            {
                List <UnitContext> endingContexts = new List <UnitContext>();

                if (!_node.IsEmpty)
                {
                    int             maxSize = GetLeftContextSize();
                    Word            word    = _node.GetWord();
                    Pronunciation[] prons   = word.GetPronunciations(null);
                    foreach (Pronunciation pron in prons)
                    {
                        Unit[] units   = pron.Units;
                        int    size    = units.Length;
                        Unit[] context = size > maxSize?Arrays.copyOfRange(units, size - maxSize, size) : units;

                        endingContexts.Add(UnitContext.Get(context));
                    }
                }
                return(endingContexts);
            }