Esempio n. 1
0
        private Float getNGramProbability(WordSequence wordSequence)
        {
            int  num  = wordSequence.size();
            Word word = wordSequence.getWord(0);

            if (this.loader.getNumberNGrams(num) == 0 || !this.hasUnigram(word))
            {
                return(this.getNGramProbability(wordSequence.getNewest()));
            }
            if (num < 2)
            {
                return(Float.valueOf(this.getUnigramProbability(wordSequence)));
            }
            NGramProbability ngramProbability = this.findNGram(wordSequence);

            if (ngramProbability != null)
            {
                return(Float.valueOf(this.ngramProbTable[num - 1][ngramProbability.getProbabilityID()]));
            }
            if (num == 2)
            {
                UnigramProbability unigram  = this.getUnigram(word);
                UnigramProbability unigram2 = this.getUnigram(wordSequence.getWord(1));
                return(Float.valueOf(unigram.getLogBackoff() + unigram2.getLogProbability()));
            }
            NGramProbability ngramProbability2 = this.findNGram(wordSequence.getOldest());

            if (ngramProbability2 != null)
            {
                return(Float.valueOf(this.ngramBackoffTable[num - 1][ngramProbability2.getBackoffID()] + this.getProbability(wordSequence.getNewest())));
            }
            return(Float.valueOf(this.getProbability(wordSequence.getNewest())));
        }
Esempio n. 2
0
        private void applyUnigramWeight()
        {
            float num    = this.logMath.linearToLog((double)this.unigramWeight);
            float num2   = this.logMath.linearToLog((double)(1f - this.unigramWeight));
            float num3   = this.logMath.linearToLog((double)(1f / (float)this.numberNGrams[0]));
            float num4   = this.logMath.linearToLog(this.wip);
            float logVal = num3 + num2;

            for (int i = 0; i < this.numberNGrams[0]; i++)
            {
                UnigramProbability unigramProbability = this.unigrams[i];
                float num5 = unigramProbability.getLogProbability();
                if (i != this.startWordID)
                {
                    num5 += num;
                    num5  = this.logMath.addAsLinear(num5, logVal);
                }
                if (this.applyLanguageWeightAndWip)
                {
                    num5 = num5 * this.languageWeight + num4;
                    unigramProbability.setLogBackoff(unigramProbability.getLogBackoff() * this.languageWeight);
                }
                unigramProbability.setLogProbability(num5);
            }
        }