/** * Gets the ngram probability of the word sequence represented by the word * list * * @param wordSequence - the word sequence * @return the probability of the word sequence. * Probability is in logMath log base */ @Override public float getProbability(WordSequence wordSequence) { int numberWords = wordSequence.size(); if (numberWords > maxDepth) { throw new Error("Unsupported NGram: " + wordSequence.size()); } if (numberWords == maxDepth) { Float probability = ngramProbCache.get(wordSequence); if (probability != null) { ngramHits++; return probability; } ngramMisses++; } float probability = applyWeights(getProbabilityRaw(wordSequence)); if (numberWords == maxDepth) ngramProbCache.put(wordSequence, probability); if (logFile != null) logFile.println(wordSequence.toString().replace("][", " ") + " : " + Float.toString(probability)); return probability; }
/** * Gets the ngram probability of the word sequence represented by the word * list * * @param wordSequence - the word sequence * @return the probability of the word sequence. * Probability is in logMath log base */ @Override public float getProbability(WordSequence wordSequence) { int numberWords = wordSequence.size(); if (numberWords > maxDepth) { throw new Error("Unsupported NGram: " + wordSequence.size()); } if (numberWords == maxDepth) { Float probability = ngramProbCache.get(wordSequence); if (probability != null) { ngramHits++; return probability; } ngramMisses++; } float probability = applyWeights(getProbabilityRaw(wordSequence)); if (numberWords == maxDepth) ngramProbCache.put(wordSequence, probability); if (logFile != null) logFile.println(wordSequence.toString().replace("][", " ") + " : " + Float.toString(probability)); return probability; }