/** * Finds the NGram probabilities for the given nth word in a NGram. * * @param nthWordID the ID of the nth word * @return the NGramProbability of the given nth word */ @Override public NGramProbability findNGram(int nthWordID) { int mid, start = 0, end = getNumberNGrams(); NGramProbability ngram = null; while ((end - start) > 0) { mid = (start + end) / 2; int midWordID = getWordID(mid); if (midWordID < nthWordID) { start = mid + 1; } else if (midWordID > nthWordID) { end = mid; } else { ngram = getNGramProbability(mid); break; } } return ngram; }
/** * Finds the NGram probabilities for the given nth word in a NGram. * * @param nthWordID the ID of the nth word * @return the NGramProbability of the given nth word */ @Override public NGramProbability findNGram(int nthWordID) { int mid, start = 0, end = getNumberNGrams(); NGramProbability ngram = null; while ((end - start) > 0) { mid = (start + end) / 2; int midWordID = getWordID(mid); if (midWordID < nthWordID) { start = mid + 1; } else if (midWordID > nthWordID) { end = mid; } else { ngram = getNGramProbability(mid); break; } } return ngram; }