示例#1
0
        public virtual NGramProbability findNGram(int num)
        {
            int num2 = 0;
            int num3 = this.getNumberNGrams() - 1;
            NGramProbability result = null;

            while (num3 - num2 > 0)
            {
                int num4   = (num2 + num3) / 2;
                int wordID = this.getWordID(num4);
                if (wordID < num)
                {
                    num2 = num4 + 1;
                }
                else
                {
                    if (wordID <= num)
                    {
                        result = this.getNGramProbability(num4);
                        break;
                    }
                    num3 = num4;
                }
            }
            return(result);
        }
示例#2
0
        private float getBigramProb(int num, int num2)
        {
            NGramBuffer      bigramBuffer     = this.getBigramBuffer(num);
            NGramProbability ngramProbability = bigramBuffer.findNGram(num2);

            return(this.ngramProbTable[1][ngramProbability.getProbabilityID()]);
        }
示例#3
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())));
        }
示例#4
0
        private NGramProbability findNGram(WordSequence wordSequence)
        {
            int num = wordSequence.size();
            NGramProbability result      = null;
            WordSequence     oldest      = wordSequence.getOldest();
            NGramBuffer      ngramBuffer = (NGramBuffer)this.loadedNGramBuffers[num - 1].get(oldest);

            if (ngramBuffer == null)
            {
                ngramBuffer = this.getNGramBuffer(oldest);
                if (ngramBuffer != null)
                {
                    this.loadedNGramBuffers[num - 1].put(oldest, ngramBuffer);
                }
            }
            if (ngramBuffer != null)
            {
                int wordID = this.getWordID(wordSequence.getWord(num - 1));
                result = ngramBuffer.findNGram(wordID);
            }
            return(result);
        }
示例#5
0
        private void buildSmearInfo()
        {
            double num  = (double)0f;
            double num2 = (double)0f;

            this.bigramSmearMap = new HashMap();
            double[] array  = new double[this.unigrams.Length];
            double[] array2 = new double[this.unigrams.Length];
            double[] array3 = new double[this.unigrams.Length];
            this.unigramSmearTerm = new float[this.unigrams.Length];
            UnigramProbability[] array4 = this.unigrams;
            int num3 = array4.Length;

            for (int i = 0; i < num3; i++)
            {
                UnigramProbability unigramProbability = array4[i];
                float  logProbability = unigramProbability.getLogProbability();
                double num4           = this.logMath.logToLinear(logProbability);
                num  += num4 * (double)logProbability;
                num2 += num4 * (double)logProbability * (double)logProbability;
            }
            [email protected](new StringBuilder().append("R0 S0 ").append(num2).append(' ').append(num).toString());
            for (int j = 0; j < this.loadedBigramBuffers.Length; j++)
            {
                NGramBuffer bigramBuffer = this.getBigramBuffer(j);
                if (bigramBuffer == null)
                {
                    this.unigramSmearTerm[j] = 0f;
                }
                else
                {
                    array[j]  = (double)0f;
                    array2[j] = (double)0f;
                    array3[j] = (double)0f;
                    float    logBackoff = this.unigrams[j].getLogBackoff();
                    double   num5       = this.logMath.logToLinear(logBackoff);
                    int      num11;
                    double[] array6;
                    for (int k = 0; k < bigramBuffer.getNumberNGrams(); k++)
                    {
                        int wordID = bigramBuffer.getWordID(k);
                        NGramProbability ngramProbability = bigramBuffer.getNGramProbability(k);
                        float            logProbability2  = this.unigrams[wordID].getLogProbability();
                        float            num6             = this.ngramProbTable[1][ngramProbability.getProbabilityID()];
                        double           num7             = this.logMath.logToLinear(logProbability2);
                        double           num8             = this.logMath.logToLinear(num6);
                        double           num9             = num5 * num7;
                        double           num10            = (double)this.logMath.linearToLog(num9);
                        double[]         array5           = array;
                        num11          = j;
                        array6         = array5;
                        array6[num11] += (num8 * (double)num6 - num9 * num10) * (double)logProbability2;
                        double[] array7 = array2;
                        num11          = j;
                        array6         = array7;
                        array6[num11] += (num8 - num9) * (double)logProbability2;
                    }
                    double[] array8 = array;
                    num11          = j;
                    array6         = array8;
                    array6[num11] += num5 * ((double)logBackoff * num + num2);
                    array3[j]      = array2[j] + num5 * num;
                    double[] array9 = array2;
                    num11                    = j;
                    array6                   = array9;
                    array6[num11]           += num5 * num2;
                    this.unigramSmearTerm[j] = (float)(array[j] / array2[j]);
                }
            }
            for (int j = 0; j < this.loadedBigramBuffers.Length; j++)
            {
                [email protected](new StringBuilder().append("Processed ").append(j).append(" of ").append(this.loadedBigramBuffers.Length).toString());
                NGramBuffer bigramBuffer = this.getBigramBuffer(j);
                if (bigramBuffer != null)
                {
                    for (int i = 0; i < bigramBuffer.getNumberNGrams(); i++)
                    {
                        NGramProbability ngramProbability2 = bigramBuffer.getNGramProbability(i);
                        float            num12             = this.ngramBackoffTable[2][ngramProbability2.getBackoffID()];
                        double           num13             = this.logMath.logToLinear(num12);
                        int         wordID2     = bigramBuffer.getWordID(i);
                        NGramBuffer ngramBuffer = this.loadTrigramBuffer(j, wordID2);
                        float       num14;
                        if (ngramBuffer == null)
                        {
                            num14 = this.unigramSmearTerm[wordID2];
                        }
                        else
                        {
                            double num7 = (double)0f;
                            double num8 = (double)0f;
                            for (int l = 0; l < ngramBuffer.getNumberNGrams(); l++)
                            {
                                int    wordID3         = ngramBuffer.getWordID(l);
                                float  num15           = this.ngramProbTable[2][ngramBuffer.getProbabilityID(l)];
                                double num16           = this.logMath.logToLinear(num15);
                                float  bigramProb      = this.getBigramProb(wordID2, wordID3);
                                double num17           = this.logMath.logToLinear(bigramProb);
                                float  logProbability3 = this.unigrams[wordID3].getLogProbability();
                                double num18           = num13 * num17;
                                double num19           = (double)this.logMath.linearToLog(num18);
                                num7 += (num16 * (double)num15 - num18 * num19) * (double)logProbability3;
                                num8 += (num16 - num18) * (double)logProbability3 * (double)logProbability3;
                            }
                            num7 += num13 * ((double)num12 * array3[wordID2] - array[wordID2]);
                            num8 += num13 * array2[wordID2];
                            num14 = (float)(num7 / num8);
                            this.smearTermCount++;
                        }
                        this.putSmearTerm(j, wordID2, num14);
                    }
                }
            }
            [email protected](new StringBuilder().append("Smear count is ").append(this.smearTermCount).toString());
        }
示例#6
0
 private int getFirstNGramEntry(NGramProbability ngramProbability, int num, int num2)
 {
     return(this.ngramSegmentTable[num2 - 1][num + ngramProbability.getWhichFollower() >> this.loader.getLogNGramSegmentSize()] + ngramProbability.getFirstNPlus1GramEntry());
 }