Example #1
0
 private Set getStartingContexts()
 {
     if (this.startingContexts == null)
     {
         this.startingContexts = new HashSet();
         if (this.node.isEmpty())
         {
             GrammarArc[] successors = this.getSuccessors();
             GrammarArc[] array      = successors;
             int          num        = array.Length;
             for (int i = 0; i < num; i++)
             {
                 GrammarArc          grammarArc = array[i];
                 FlatLinguist.GState gstate     = this.this_0.getGState(grammarArc.getGrammarNode());
                 this.startingContexts.addAll(gstate.getStartingContexts());
             }
         }
         else
         {
             Word            word           = this.node.getWord();
             Pronunciation[] pronunciations = word.getPronunciations();
             Pronunciation[] array2         = pronunciations;
             int             i = array2.Length;
             for (int j = 0; j < i; j++)
             {
                 Pronunciation pronunciation   = array2[j];
                 UnitContext   startingContext = this.getStartingContext(pronunciation);
                 this.startingContexts.add(startingContext);
             }
         }
     }
     return(this.startingContexts);
 }
Example #2
0
        public override bool equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is UnitContext))
            {
                return(false);
            }
            UnitContext unitContext = (UnitContext)obj;

            if (this.context.Length != unitContext.context.Length)
            {
                return(false);
            }
            for (int i = 0; i < this.context.Length; i++)
            {
                if (this.context[i] != unitContext.context[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Example #3
0
        internal static UnitContext get(Unit[] array)
        {
            UnitContext unitContext  = new UnitContext(array);
            UnitContext unitContext2 = (UnitContext)UnitContext.unitContextCache.cache(unitContext);

            return((unitContext2 != null) ? unitContext2 : unitContext);
        }
        internal static ContextPair get(UnitContext unitContext, UnitContext unitContext2)
        {
            ContextPair contextPair  = new ContextPair(unitContext, unitContext2);
            ContextPair contextPair2 = (ContextPair)ContextPair.contextPairCache.cache(contextPair);

            return((contextPair2 != null) ? contextPair2 : contextPair);
        }
Example #5
0
            private bool needsEmptyVersion(ContextPair contextPair)
            {
                UnitContext leftContext = contextPair.getLeftContext();

                Unit[] units = leftContext.getUnits();
                return(units.Length > 0 && this.getRightContextSize(units[0]) < this.getRightContextSize());
            }
Example #6
0
            private UnitContext getStartingContext(Pronunciation pronunciation)
            {
                int rightContextSize = this.getRightContextSize();

                Unit[] units = pronunciation.getUnits();
                Unit[] array = (units.Length <= rightContextSize) ? units : ((Unit[])Arrays.copyOf(units, rightContextSize));
                return(UnitContext.get(array));
            }
Example #7
0
            private void expandWord(UnitContext unitContext)
            {
                Word word = this.node.getWord();

                FlatLinguist.access_100(this.this_0, new StringBuilder().append("  Expanding word ").append(word).append(" for lc ").append(unitContext).toString());
                Pronunciation[] pronunciations = word.getPronunciations();
                for (int i = 0; i < pronunciations.Length; i++)
                {
                    this.expandPronunciation(unitContext, pronunciations[i], i);
                }
            }
Example #8
0
            internal virtual UnitContext generateNextLeftContext(UnitContext unitContext, Unit unit)
            {
                Unit[] units = unitContext.getUnits();
                int    num   = Math.min(units.Length, this.getLeftContextSize());

                if (num == 0)
                {
                    return(UnitContext.EMPTY);
                }
                Unit[] array = (Unit[])Arrays.copyOfRange(units, 1, num + 1);
                array[num - 1] = unit;
                return(UnitContext.get(array));
            }
Example #9
0
            public virtual void expand()
            {
                Iterator iterator = this.leftContexts.iterator();

                while (iterator.hasNext())
                {
                    UnitContext unitContext = (UnitContext)iterator.next();
                    Iterator    iterator2   = this.getStartingContexts().iterator();
                    while (iterator2.hasNext())
                    {
                        UnitContext unitContext2 = (UnitContext)iterator2.next();
                        ContextPair contextPair  = ContextPair.get(unitContext, unitContext2);
                        this.entryPoints.put(contextPair, new ArrayList());
                    }
                }
                if (this.node.isFinalNode())
                {
                    GrammarState grammarState = new GrammarState(this.node);
                    Iterator     iterator3    = this.entryPoints.values().iterator();
                    while (iterator3.hasNext())
                    {
                        List list = (List)iterator3.next();
                        list.add(grammarState);
                    }
                }
                else if (!this.node.isEmpty())
                {
                    iterator = this.leftContexts.iterator();
                    while (iterator.hasNext())
                    {
                        UnitContext unitContext = (UnitContext)iterator.next();
                        this.expandWord(unitContext);
                    }
                }
                else
                {
                    iterator = this.entryPoints.entrySet().iterator();
                    while (iterator.hasNext())
                    {
                        Map.Entry   entry        = (Map.Entry)iterator.next();
                        ContextPair contextPair2 = (ContextPair)entry.getKey();
                        List        list2        = (List)entry.getValue();
                        BranchState branchState  = new BranchState(contextPair2.getLeftContext().toString(), contextPair2.getRightContext().toString(), this.node.getID());
                        list2.add(branchState);
                        this.addExitPoint(contextPair2, branchState);
                    }
                }
                this.addEmptyEntryPoints();
            }
Example #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++;
                    }
                }
            }
Example #11
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);
            }
Example #12
0
            internal virtual Collection getEndingContexts()
            {
                ArrayList arrayList = new ArrayList();

                if (!this.node.isEmpty())
                {
                    int             leftContextSize = this.getLeftContextSize();
                    Word            word            = this.node.getWord();
                    Pronunciation[] pronunciations  = word.getPronunciations();
                    Pronunciation[] array           = pronunciations;
                    int             num             = array.Length;
                    for (int i = 0; i < num; i++)
                    {
                        Pronunciation pronunciation = array[i];
                        Unit[]        units         = pronunciation.getUnits();
                        int           num2          = units.Length;
                        Unit[]        array2        = (num2 <= leftContextSize) ? units : ((Unit[])Arrays.copyOfRange(units, num2 - leftContextSize, num2));
                        arrayList.add(UnitContext.get(array2));
                    }
                }
                return(arrayList);
            }
Example #13
0
            private Unit[] getRC(Unit[] array, int num, UnitContext unitContext)
            {
                Unit[] units = unitContext.getUnits();
                int    num2  = num + 1;
                int    num3  = array.Length - num2 + units.Length;
                int    num4  = Math.min(num3, this.getRightContextSize(array[num]));

                Unit[] array2 = new Unit[num4];
                for (int i = 0; i < array2.Length; i++)
                {
                    int num5 = num2 + i;
                    if (num5 < array.Length)
                    {
                        array2[i] = array[num5];
                    }
                    else
                    {
                        array2[i] = units[num5 - array.Length];
                    }
                }
                return(array2);
            }
Example #14
0
            private Unit[] getLC(UnitContext unitContext, Unit[] array, int num)
            {
                Unit[] units = unitContext.getUnits();
                int    num2  = units.Length + num;
                int    num3  = Math.min(num2, this.getLeftContextSize(array[num]));
                int    num4  = num - num3;

                Unit[] array2 = new Unit[num3];
                for (int i = 0; i < array2.Length; i++)
                {
                    int num5 = num4 + i;
                    if (num5 < 0)
                    {
                        array2[i] = units[units.Length + num5];
                    }
                    else
                    {
                        array2[i] = array[num5];
                    }
                }
                return(array2);
            }
Example #15
0
 private ContextPair(UnitContext unitContext, UnitContext unitContext2)
 {
     this.left      = unitContext;
     this.right     = unitContext2;
     this._hashCode = 99 + unitContext.hashCode() * 113 + unitContext2.hashCode();
 }
Example #16
0
 internal static void access_000(FlatLinguist.GState gstate, UnitContext unitContext)
 {
     gstate.addLeftContext(unitContext);
 }
Example #17
0
 private void addLeftContext(UnitContext unitContext)
 {
     this.leftContexts.add(unitContext);
 }