예제 #1
0
 private float getAvailableProb(WordSequence wordSequence, NgramTrieModel.TrieRange trieRange, float num)
 {
     if (!trieRange.isSearchable())
     {
         return(num);
     }
     for (int i = wordSequence.size() - 2; i >= 0; i--)
     {
         int num2 = wordSequence.size() - 2 - i;
         if (num2 + 1 == this.maxDepth)
         {
             break;
         }
         int   wordId = ((Integer)this.unigramIDMap.get(wordSequence.getWord(i))).intValue();
         float num3   = this.trie.readNgramProb(wordId, num2, trieRange, this.quant);
         if (!trieRange.getFound())
         {
             break;
         }
         num = num3;
         this.curDepth++;
         if (!trieRange.isSearchable())
         {
             break;
         }
     }
     return(num);
 }
예제 #2
0
        private float getAvailableBackoff(WordSequence wordSequence)
        {
            float num  = 0f;
            int   num2 = wordSequence.size();
            int   num3 = ((Integer)this.unigramIDMap.get(wordSequence.getWord(num2 - 2))).intValue();

            NgramTrieModel.TrieRange trieRange = new NgramTrieModel.TrieRange(this.unigrams[num3].next, this.unigrams[num3 + 1].next);
            if (this.curDepth == 1)
            {
                num += this.unigrams[num3].backoff;
            }
            int i    = num2 - 3;
            int num4 = 0;

            while (i >= 0)
            {
                int   wordId = ((Integer)this.unigramIDMap.get(wordSequence.getWord(i))).intValue();
                float num5   = this.trie.readNgramBackoff(wordId, num4, trieRange, this.quant);
                if (!trieRange.getFound())
                {
                    break;
                }
                num += num5;
                if (!trieRange.isSearchable())
                {
                    break;
                }
                i--;
                num4++;
            }
            return(num);
        }
예제 #3
0
            internal void readNextRange(int num, NgramTrieModel.TrieRange trieRange)
            {
                int num2 = num * this.totalBits;

                num2           += this.wordBits;
                num2           += this.getQuantBits();
                trieRange.begin = NgramTrie.access_100(this.this_0).readInt(this.memPtr, num2, this.nextMask);
                num2           += this.totalBits;
                trieRange.end   = NgramTrie.access_100(this.this_0).readInt(this.memPtr, num2, this.nextMask);
            }
예제 #4
0
        public virtual float readNgramProb(int wordId, int orderMinusTwo, NgramTrieModel.TrieRange range, NgramTrieQuant quant)
        {
            NgramTrie.NgramSet ngram = this.getNgram(orderMinusTwo);
            int num;

            if ((num = this.findNgram(ngram, wordId, range)) < 0)
            {
                return(0f);
            }
            return(quant.readProb(this.bitArr, ngram.memPtr, ngram.getNgramWeightsOffset(num), orderMinusTwo));
        }
예제 #5
0
        private int findNgram(NgramTrie.NgramSet ngramSet, int num, NgramTrieModel.TrieRange trieRange)
        {
            trieRange.begin--;
            int num2;

            if ((num2 = this.uniformFind(ngramSet, trieRange, num)) < 0)
            {
                trieRange.setFound(false);
                return(-1);
            }
            if (ngramSet is NgramTrie.MiddleNgramSet)
            {
                ((NgramTrie.MiddleNgramSet)ngramSet).readNextRange(num2, trieRange);
            }
            return(num2);
        }
예제 #6
0
        private float getProbabilityRaw(WordSequence wordSequence)
        {
            int num  = wordSequence.size();
            int num2 = ((Integer)this.unigramIDMap.get(wordSequence.getWord(num - 1))).intValue();

            NgramTrieModel.TrieRange trieRange = new NgramTrieModel.TrieRange(this.unigrams[num2].next, this.unigrams[num2 + 1].next);
            float num3 = this.unigrams[num2].prob;

            this.curDepth = 1;
            if (num == 1)
            {
                return(num3);
            }
            num3 = this.getAvailableProb(wordSequence, trieRange, num3);
            if (this.curDepth < num)
            {
                num3 += this.getAvailableBackoff(wordSequence);
            }
            return(num3);
        }
예제 #7
0
 private int uniformFind(NgramTrie.NgramSet ngramSet, NgramTrieModel.TrieRange trieRange, int num)
 {
     NgramTrieModel.TrieRange trieRange2 = new NgramTrieModel.TrieRange(0, ngramSet.maxVocab);
     while (trieRange.getWidth() > 1)
     {
         int num2 = trieRange.begin + 1 + this.calculatePivot(num - trieRange2.begin, trieRange2.getWidth(), trieRange.getWidth() - 1);
         int num3 = ngramSet.readNgramWord(num2);
         if (num3 < num)
         {
             trieRange.begin  = num2;
             trieRange2.begin = num3;
         }
         else
         {
             if (num3 <= num)
             {
                 return(num2);
             }
             trieRange.end  = num2;
             trieRange2.end = num3;
         }
     }
     return(-1);
 }