Merge "Get bigram probability using language model dict content."
commit
e38f79182d
|
@ -127,22 +127,29 @@ int Ver4PatriciaTriePolicy::getProbabilityOfPtNode(const int *const prevWordsPtN
|
||||||
if (ptNodePos == NOT_A_DICT_POS) {
|
if (ptNodePos == NOT_A_DICT_POS) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
const PtNodeParams ptNodeParams(mNodeReader.fetchPtNodeParamsInBufferFromPtNodePos(ptNodePos));
|
const PtNodeParams ptNodeParams = mNodeReader.fetchPtNodeParamsInBufferFromPtNodePos(ptNodePos);
|
||||||
if (ptNodeParams.isDeleted() || ptNodeParams.isBlacklisted() || ptNodeParams.isNotAWord()) {
|
if (ptNodeParams.isDeleted() || ptNodeParams.isBlacklisted() || ptNodeParams.isNotAWord()) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
if (prevWordsPtNodePos) {
|
if (prevWordsPtNodePos) {
|
||||||
const int bigramsPosition = getBigramsPositionOfPtNode(prevWordsPtNodePos[0]);
|
// TODO: Support n-gram.
|
||||||
BinaryDictionaryBigramsIterator bigramsIt(&mBigramPolicy, bigramsPosition);
|
const PtNodeParams prevWordPtNodeParams =
|
||||||
while (bigramsIt.hasNext()) {
|
mNodeReader.fetchPtNodeParamsInBufferFromPtNodePos(prevWordsPtNodePos[0]);
|
||||||
bigramsIt.next();
|
const int prevWordTerminalId = prevWordPtNodeParams.getTerminalId();
|
||||||
if (bigramsIt.getBigramPos() == ptNodePos
|
const ProbabilityEntry probabilityEntry =
|
||||||
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
mBuffers->getLanguageModelDictContent()->getNgramProbabilityEntry(
|
||||||
return getProbability(ptNodeParams.getProbability(), bigramsIt.getProbability());
|
IntArrayView::fromObject(&prevWordTerminalId),
|
||||||
}
|
ptNodeParams.getTerminalId());
|
||||||
}
|
if (!probabilityEntry.isValid()) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
if (mHeaderPolicy->hasHistoricalInfoOfWords()) {
|
||||||
|
return ForgettingCurveUtils::decodeProbability(probabilityEntry.getHistoricalInfo(),
|
||||||
|
mHeaderPolicy);
|
||||||
|
} else {
|
||||||
|
return probabilityEntry.getProbability();
|
||||||
|
}
|
||||||
|
}
|
||||||
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue