/** * Retrieves the bigram probability for the two given words * * @param word1 * the first word of the bigram * @param word2 * the second word of the bigram * @return the log probability */ private float getBigramProb(int word1, int word2) { NGramBuffer bigram = getBigramBuffer(word1); NGramProbability bigramProbability = bigram.findNGram(word2); return ngramProbTable[1][bigramProbability.getProbabilityID()]; }
/** * Finds or loads the NGram probability of the given NGram. * * @param wordSequence * the NGram to load * @return a NGramProbability of the given NGram */ private NGramProbability findNGram(WordSequence wordSequence) { int numberWords = wordSequence.size(); NGramProbability nGram = null; WordSequence oldest = wordSequence.getOldest(); NGramBuffer nGramBuffer = loadedNGramBuffers[numberWords - 1] .get(oldest); if (nGramBuffer == null) { nGramBuffer = getNGramBuffer(oldest); if (nGramBuffer != null) loadedNGramBuffers[numberWords - 1].put(oldest, nGramBuffer); } if (nGramBuffer != null) { int nthWordID = getWordID(wordSequence.getWord(numberWords - 1)); nGram = nGramBuffer.findNGram(nthWordID); } return nGram; }
/** * Retrieves the bigram probability for the two given words * * @param word1 * the first word of the bigram * @param word2 * the second word of the bigram * @return the log probability */ private float getBigramProb(int word1, int word2) { NGramBuffer bigram = getBigramBuffer(word1); NGramProbability bigramProbability = bigram.findNGram(word2); return ngramProbTable[1][bigramProbability.getProbabilityID()]; }
/** * Finds or loads the NGram probability of the given NGram. * * @param wordSequence * the NGram to load * @return a NGramProbability of the given NGram */ private NGramProbability findNGram(WordSequence wordSequence) { int numberWords = wordSequence.size(); NGramProbability nGram = null; WordSequence oldest = wordSequence.getOldest(); NGramBuffer nGramBuffer = loadedNGramBuffers[numberWords - 1] .get(oldest); if (nGramBuffer == null) { nGramBuffer = getNGramBuffer(oldest); if (nGramBuffer != null) loadedNGramBuffers[numberWords - 1].put(oldest, nGramBuffer); } if (nGramBuffer != null) { int nthWordID = getWordID(wordSequence.getWord(numberWords - 1)); nGram = nGramBuffer.findNGram(nthWordID); } return nGram; }