Exemple #1
0
            protected internal virtual HMMStateState expandHMMTree(UnitState parent, HMMStateState tree)
            {
                HMMStateState result = tree;

                HMMStateArc[] successors = tree.getHMMState().getSuccessors();
                int           num        = successors.Length;

                for (int i = 0; i < num; i++)
                {
                    HMMStateArc   hmmstateArc = successors[i];
                    HMMStateState hmmstateState;
                    if (hmmstateArc.getHMMState().isEmitting())
                    {
                        hmmstateState = new HMMStateState(parent, hmmstateArc.getHMMState());
                    }
                    else
                    {
                        hmmstateState = new NonEmittingHMMState(parent, hmmstateArc.getHMMState());
                    }
                    SentenceHMMState existingState  = this.getExistingState(hmmstateState);
                    float            logProbability = hmmstateArc.getLogProbability();
                    if (existingState != null)
                    {
                        this.attachState(tree, existingState, 0f, logProbability);
                    }
                    else
                    {
                        this.attachState(tree, hmmstateState, 0f, logProbability);
                        this.addStateToCache(hmmstateState);
                        result = this.expandHMMTree(parent, hmmstateState);
                    }
                }
                return(result);
            }
Exemple #2
0
 public GrammarPoint(SentenceHMMState state)
 {
     while (state != null)
     {
         if (state is UnitState)
         {
             this.unitIndex = state.getWhich();
         }
         else if (state is PronunciationState)
         {
             this.pronunciationIndex = state.getWhich();
         }
         else if (state is WordState)
         {
             this.wordIndex = state.getWhich();
         }
         else if (state is AlternativeState)
         {
             this.alternativeIndex = state.getWhich();
         }
         else if (state is GrammarState)
         {
             this.node = ((GrammarState)state).getGrammarNode();
         }
         state = state.getParent();
     }
     if (!GrammarPoint.assertionsDisabled && this.node == null)
     {
         throw new AssertionError();
     }
 }
        public static Set collectStates(SentenceHMMState start)
        {
            HashSet    hashSet    = new HashSet();
            LinkedList linkedList = new LinkedList();

            linkedList.add(start);
            while (!linkedList.isEmpty())
            {
                SentenceHMMState sentenceHMMState = (SentenceHMMState)linkedList.remove(0);
                hashSet.add(sentenceHMMState);
                SearchStateArc[] successors = sentenceHMMState.getSuccessors();
                SearchStateArc[] array      = successors;
                int num = array.Length;
                for (int i = 0; i < num; i++)
                {
                    SearchStateArc   searchStateArc    = array[i];
                    SentenceHMMState sentenceHMMState2 = (SentenceHMMState)searchStateArc.getState();
                    if (!hashSet.contains(sentenceHMMState2) && !linkedList.contains(sentenceHMMState2))
                    {
                        linkedList.add(sentenceHMMState2);
                    }
                }
            }
            return(hashSet);
        }
Exemple #4
0
            private void addExitPoint(ContextPair contextPair, SentenceHMMState sentenceHMMState)
            {
                object obj = (List)this.exitPoints.get(contextPair);

                if ((List)obj == null)
                {
                    obj = new ArrayList();
                    this.exitPoints.put(contextPair, (ArrayList)obj);
                }
                object obj2 = obj;
                List   list;

                if (obj2 != null)
                {
                    if ((list = (obj2 as List)) == null)
                    {
                        throw new IncompatibleClassChangeError();
                    }
                }
                else
                {
                    list = null;
                }
                list.add(sentenceHMMState);
            }
 public SentenceHMMStateArc(SentenceHMMState nextState, float logLanguageProbability, float logInsertionProbability)
 {
     this.nextState = nextState;
     this.logLanguageProbability  = logLanguageProbability;
     this.logInsertionProbability = logInsertionProbability;
     this._hashCode = 111 + Object.instancehelper_hashCode(nextState) + 17 * Float.floatToIntBits(logLanguageProbability) + 23 * Float.floatToIntBits(logInsertionProbability);
 }
 protected internal SentenceHMMState(string name, SentenceHMMState parent, int which) : this()
 {
     this.name   = new StringBuilder().append(name).append(which).toString();
     this.parent = parent;
     this.setWhich(which);
     this.setProcessed(false);
     this.setColor(SentenceHMMState.Color.__RED);
 }
Exemple #7
0
        protected internal virtual SentenceHMMStateArc getArc(SentenceHMMState nextState, float logLanguageProbability, float logInsertionProbability)
        {
            SentenceHMMStateArc sentenceHMMStateArc  = new SentenceHMMStateArc(nextState, logLanguageProbability * this.languageWeight, logInsertionProbability);
            SentenceHMMStateArc sentenceHMMStateArc2 = (SentenceHMMStateArc)this.arcPool.cache(sentenceHMMStateArc);

            this.actualArcs.value = (double)this.arcPool.getMisses();
            this.totalArcs.value  = (double)(this.arcPool.getHits() + this.arcPool.getMisses());
            return((sentenceHMMStateArc2 != null) ? sentenceHMMStateArc2 : sentenceHMMStateArc);
        }
Exemple #8
0
 protected internal virtual void attachState(SentenceHMMState prevState, SentenceHMMState nextState, float logLanguageProbablity, float logInsertionProbablity)
 {
     prevState.connect(this.this_0.getArc(nextState, logLanguageProbablity, logInsertionProbablity));
     if (FlatLinguist.access_900(this.this_0))
     {
         bool flag = FlatLinguist.access_1008(this.this_0) != 0;
         int  num  = 1000;
         if (num == -1 || (flag ? 1 : 0) % num == 0)
         {
             [email protected](".");
         }
     }
 }
        public virtual Word getAssociatedWord()
        {
            Word             result           = null;
            SentenceHMMState sentenceHMMState = this;

            while (sentenceHMMState != null && !(sentenceHMMState is WordState))
            {
                sentenceHMMState = sentenceHMMState.getParent();
            }
            if (sentenceHMMState != null)
            {
                WordState wordState = (WordState)sentenceHMMState;
                result = wordState.getWord();
            }
            return(result);
        }
Exemple #10
0
            private void expandPronunciation(UnitContext unitContext, Pronunciation pronunciation, int which)
            {
                UnitContext        startingContext    = this.getStartingContext(pronunciation);
                string             name               = new StringBuilder().append("P(").append(pronunciation.getWord()).append('[').append(unitContext).append(',').append(startingContext).append("])-G").append(this.getNode().getID()).toString();
                PronunciationState pronunciationState = new PronunciationState(name, pronunciation, which);

                FlatLinguist.access_100(this.this_0, new StringBuilder().append("     Expanding ").append(pronunciationState.getPronunciation()).append(" for lc ").append(unitContext).toString());
                ContextPair contextPair = ContextPair.get(unitContext, startingContext);
                List        list        = (List)this.entryPoints.get(contextPair);

                if (list == null)
                {
                    string text = new StringBuilder().append("No EP list for context pair ").append(contextPair).toString();

                    throw new Error(text);
                }
                list.add(pronunciationState);
                Unit[] units = pronunciation.getUnits();
                int    num   = units.Length - this.getRightContextSize();

                if (num < 0)
                {
                    num = 0;
                }
                SentenceHMMState sentenceHMMState = pronunciationState;
                int num2 = 0;

                while (sentenceHMMState != null && num2 < num)
                {
                    sentenceHMMState = this.attachUnit(pronunciationState, sentenceHMMState, units, num2, unitContext, UnitContext.EMPTY);
                    num2++;
                }
                SentenceHMMState sentenceHMMState2 = sentenceHMMState;
                Iterator         iterator          = this.rightContexts.iterator();

                while (iterator.hasNext())
                {
                    UnitContext unitContext2 = (UnitContext)iterator.next();
                    sentenceHMMState = sentenceHMMState2;
                    int num3 = num;
                    while (sentenceHMMState != null && num3 < units.Length)
                    {
                        sentenceHMMState = this.attachUnit(pronunciationState, sentenceHMMState, units, num3, unitContext, unitContext2);
                        num3++;
                    }
                }
            }
Exemple #11
0
            private void connect(List list, List list2, float num)
            {
                Iterator iterator = list.iterator();

                while (iterator.hasNext())
                {
                    SearchState      searchState      = (SearchState)iterator.next();
                    SentenceHMMState sentenceHMMState = (SentenceHMMState)searchState;
                    Iterator         iterator2        = list2.iterator();
                    while (iterator2.hasNext())
                    {
                        SearchState      searchState2 = (SearchState)iterator2.next();
                        SentenceHMMState nextState    = (SentenceHMMState)searchState2;
                        sentenceHMMState.connect(this.this_0.getArc(nextState, num, 0f));
                        this.exitConnections++;
                    }
                }
            }
Exemple #12
0
            private SentenceHMMState attachUnit(PronunciationState parent, SentenceHMMState sentenceHMMState, Unit[] array, int num, UnitContext unitContext, UnitContext unitContext2)
            {
                Unit[]            lc                = this.getLC(unitContext, array, num);
                Unit[]            rc                = this.getRC(array, num, unitContext2);
                UnitContext       unitContext3      = UnitContext.get(rc);
                LeftRightContext  context           = LeftRightContext.get(lc, rc);
                Unit              unit              = FlatLinguist.access_200(this.this_0).getUnit(array[num].getName(), array[num].isFiller(), context);
                ExtendedUnitState extendedUnitState = new ExtendedUnitState(parent, num, unit);
                float             logInsertionProbablity;

                if (extendedUnitState.getUnit().isSilence())
                {
                    logInsertionProbablity = FlatLinguist.access_300(this.this_0);
                }
                else if (extendedUnitState.getUnit().isFiller())
                {
                    logInsertionProbablity = FlatLinguist.access_400(this.this_0);
                }
                else if (extendedUnitState.getWhich() == 0)
                {
                    logInsertionProbablity = FlatLinguist.access_500(this.this_0);
                }
                else
                {
                    logInsertionProbablity = FlatLinguist.access_600(this.this_0);
                }
                SentenceHMMState existingState = this.getExistingState(extendedUnitState);

                if (existingState != null)
                {
                    this.attachState(sentenceHMMState, existingState, 0f, logInsertionProbablity);
                    return(null);
                }
                this.attachState(sentenceHMMState, extendedUnitState, 0f, logInsertionProbablity);
                this.addStateToCache(extendedUnitState);
                sentenceHMMState = this.expandUnit(extendedUnitState);
                if (extendedUnitState.isLast())
                {
                    UnitContext unitContext4 = this.generateNextLeftContext(unitContext, array[num]);
                    ContextPair contextPair  = ContextPair.get(unitContext4, unitContext3);
                    this.addExitPoint(contextPair, sentenceHMMState);
                }
                return(sentenceHMMState);
            }
        internal static bool visitStates(SentenceHMMStateVisitor visitor, SentenceHMMState start, bool sorted)
        {
            object obj = SentenceHMMState.collectStates(start);

            if (sorted)
            {
                TreeSet treeSet = new TreeSet(new SentenceHMMState_3());
                treeSet.addAll((Set)obj);
                obj = treeSet;
            }
            object obj2 = obj;
            Set    set;

            if (obj2 != null)
            {
                if ((set = (obj2 as Set)) == null)
                {
                    throw new IncompatibleClassChangeError();
                }
            }
            else
            {
                set = null;
            }
            Iterator iterator = set.iterator();

            while (iterator.hasNext())
            {
                SentenceHMMState sentenceHMMState = (SentenceHMMState)iterator.next();
                if (visitor.visit(sentenceHMMState))
                {
                    return(true);
                }
            }
            return(false);
        }
 public static bool visitStates(object obj, SentenceHMMState start, bool sorted)
 {
     return(SentenceHMMState.visitStates((SentenceHMMStateVisitor)obj, start, sorted));
 }
Exemple #15
0
 private void addStateToCache(SentenceHMMState sentenceHMMState)
 {
     this.existingStates.put(sentenceHMMState.getSignature(), sentenceHMMState);
 }
 internal static void access_000(SentenceHMMState sentenceHMMState)
 {
     sentenceHMMState.dump();
 }
 internal static int access_100(SentenceHMMState sentenceHMMState)
 {
     return(sentenceHMMState.stateNumber);
 }
 public virtual void dumpAll()
 {
     SentenceHMMState.visitStates(new SentenceHMMState_2(this), this, true);
 }
 public virtual SentenceHMMStateArc findArc(SentenceHMMState state)
 {
     return((SentenceHMMStateArc)this.arcs.get(state.getValueSignature()));
 }
Exemple #20
0
        protected internal virtual Collection compileGrammar()
        {
            this.initialGrammarState = this.grammar.getInitialNode();
            this.nodeStateMap        = new HashMap();
            this.arcPool             = new Cache();
            ArrayList arrayList = new ArrayList();

            TimerPool.getTimer(this, "Compile").start();
            TimerPool.getTimer(this, "Create States").start();
            Iterator iterator = this.grammar.getGrammarNodes().iterator();

            while (iterator.hasNext())
            {
                GrammarNode         grammarNode = (GrammarNode)iterator.next();
                FlatLinguist.GState gstate      = this.createGState(grammarNode);
                arrayList.add(gstate);
            }
            TimerPool.getTimer(this, "Create States").stop();
            this.addStartingPath();
            TimerPool.getTimer(this, "Collect Contexts").start();
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                FlatLinguist.GState gstate2 = (FlatLinguist.GState)iterator.next();
                gstate2.collectContexts();
            }
            TimerPool.getTimer(this, "Collect Contexts").stop();
            TimerPool.getTimer(this, "Expand States").start();
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                FlatLinguist.GState gstate2 = (FlatLinguist.GState)iterator.next();
                gstate2.expand();
            }
            TimerPool.getTimer(this, "Expand States").stop();
            TimerPool.getTimer(this, "Connect Nodes").start();
            iterator = arrayList.iterator();
            while (iterator.hasNext())
            {
                FlatLinguist.GState gstate2 = (FlatLinguist.GState)iterator.next();
                gstate2.connect();
            }
            TimerPool.getTimer(this, "Connect Nodes").stop();
            SentenceHMMState sentenceHMMState = this.findStartingState();

            if (this.addOutOfGrammarBranch)
            {
                CIPhoneLoop      ciphoneLoop = new CIPhoneLoop(this.phoneLoopAcousticModel, this.logPhoneInsertionProbability);
                SentenceHMMState nextState   = (SentenceHMMState)ciphoneLoop.getSearchGraph().getInitialState();
                sentenceHMMState.connect(this.getArc(nextState, 0f, this.logOutOfGrammarBranchProbability));
            }
            this.searchGraph = new FlatLinguist.FlatSearchGraph(this, sentenceHMMState);
            TimerPool.getTimer(this, "Compile").stop();
            if (this.dumpGStates)
            {
                Iterator iterator2 = this.grammar.getGrammarNodes().iterator();
                while (iterator2.hasNext())
                {
                    GrammarNode         node    = (GrammarNode)iterator2.next();
                    FlatLinguist.GState gstate3 = this.getGState(node);
                    gstate3.dumpInfo();
                }
            }
            this.nodeStateMap = null;
            this.arcPool      = null;
            return(SentenceHMMState.collectStates(sentenceHMMState));
        }
 public virtual void resetAllProcessed()
 {
     SentenceHMMState.visitStates(new SentenceHMMState_1(this), this, false);
 }
Exemple #22
0
 private SentenceHMMState getExistingState(SentenceHMMState sentenceHMMState)
 {
     return((SentenceHMMState)this.__existingStates.get(sentenceHMMState.getSignature()));
 }
 public NonEmittingHMMState(SentenceHMMState parent, HMMState hmmState) : base(parent, hmmState)
 {
 }
        private void rawConnect(SentenceHMMStateArc sentenceHMMStateArc)
        {
            SentenceHMMState sentenceHMMState = (SentenceHMMState)sentenceHMMStateArc.getState();

            this.arcs.put(new StringBuilder().append(sentenceHMMState.getValueSignature()).append(sentenceHMMState.getStateNumber()).toString(), sentenceHMMStateArc);
        }
Exemple #25
0
 internal SentenceHMMState_2(SentenceHMMState sentenceHMMState)
 {
     this.this_0 = sentenceHMMState;
 }
Exemple #26
0
            protected internal virtual void attachState(SentenceHMMState prevState, SentenceHMMState nextState, float logLanguageProbability, float logInsertionProbability)
            {
                SentenceHMMStateArc arc = new SentenceHMMStateArc(nextState, logLanguageProbability, logInsertionProbability);

                prevState.connect(arc);
            }
 public HMMStateState(SentenceHMMState parent, HMMState hmmState) : base("S", parent, hmmState.getState())
 {
     this.hmmState    = hmmState;
     this._isEmitting = hmmState.isEmitting();
 }
Exemple #28
0
 protected internal virtual void addStateToCache(SentenceHMMState state)
 {
     this.__existingStates.put(state.getSignature(), state);
 }
Exemple #29
0
 public bool visit(SentenceHMMState sentenceHMMState)
 {
     SentenceHMMState.access_000(sentenceHMMState);
     return(false);
 }
Exemple #30
0
 public int compare(SentenceHMMState sentenceHMMState, SentenceHMMState sentenceHMMState2)
 {
     return(SentenceHMMState.access_100(sentenceHMMState) - SentenceHMMState.access_100(sentenceHMMState2));
 }