Use getProbabilityOfWordInContext for prediction.
Bug: 14425059 Change-Id: I9d5c905a0adda3503c593bfbf0bb9af8d1686f5d
This commit is contained in:
parent
395fe8e98d
commit
11a48f92a5
2 changed files with 12 additions and 8 deletions
|
@ -61,10 +61,11 @@ void Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
|
|||
}
|
||||
|
||||
Dictionary::NgramListenerForPrediction::NgramListenerForPrediction(
|
||||
const PrevWordsInfo *const prevWordsInfo, SuggestionResults *const suggestionResults,
|
||||
const PrevWordsInfo *const prevWordsInfo, const WordIdArrayView prevWordIds,
|
||||
SuggestionResults *const suggestionResults,
|
||||
const DictionaryStructureWithBufferPolicy *const dictStructurePolicy)
|
||||
: mPrevWordsInfo(prevWordsInfo), mSuggestionResults(suggestionResults),
|
||||
mDictStructurePolicy(dictStructurePolicy) {}
|
||||
: mPrevWordsInfo(prevWordsInfo), mPrevWordIds(prevWordIds),
|
||||
mSuggestionResults(suggestionResults), mDictStructurePolicy(dictStructurePolicy) {}
|
||||
|
||||
void Dictionary::NgramListenerForPrediction::onVisitEntry(const int ngramProbability,
|
||||
const int targetWordId) {
|
||||
|
@ -83,19 +84,20 @@ void Dictionary::NgramListenerForPrediction::onVisitEntry(const int ngramProbabi
|
|||
if (codePointCount <= 0) {
|
||||
return;
|
||||
}
|
||||
const int probability = mDictStructurePolicy->getProbability(
|
||||
unigramProbability, ngramProbability);
|
||||
const int probability = mDictStructurePolicy->getProbabilityOfWordInContext(mPrevWordIds.data(),
|
||||
targetWordId, nullptr /* multiBigramMap */);
|
||||
mSuggestionResults->addPrediction(targetWordCodePoints, codePointCount, probability);
|
||||
}
|
||||
|
||||
void Dictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo,
|
||||
SuggestionResults *const outSuggestionResults) const {
|
||||
TimeKeeper::setCurrentTime();
|
||||
NgramListenerForPrediction listener(prevWordsInfo, outSuggestionResults,
|
||||
mDictionaryStructureWithBufferPolicy.get());
|
||||
int prevWordIds[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
|
||||
prevWordsInfo->getPrevWordIds(mDictionaryStructureWithBufferPolicy.get(), prevWordIds,
|
||||
true /* tryLowerCaseSearch */);
|
||||
NgramListenerForPrediction listener(prevWordsInfo,
|
||||
WordIdArrayView::fromFixedSizeArray(prevWordIds), outSuggestionResults,
|
||||
mDictionaryStructureWithBufferPolicy.get());
|
||||
mDictionaryStructureWithBufferPolicy->iterateNgramEntries(prevWordIds, &listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "suggest/core/policy/dictionary_header_structure_policy.h"
|
||||
#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
|
||||
#include "suggest/core/suggest_interface.h"
|
||||
#include "utils/int_array_view.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
|
@ -118,7 +119,7 @@ class Dictionary {
|
|||
class NgramListenerForPrediction : public NgramListener {
|
||||
public:
|
||||
NgramListenerForPrediction(const PrevWordsInfo *const prevWordsInfo,
|
||||
SuggestionResults *const suggestionResults,
|
||||
const WordIdArrayView prevWordIds, SuggestionResults *const suggestionResults,
|
||||
const DictionaryStructureWithBufferPolicy *const dictStructurePolicy);
|
||||
virtual void onVisitEntry(const int ngramProbability, const int targetWordId);
|
||||
|
||||
|
@ -126,6 +127,7 @@ class Dictionary {
|
|||
DISALLOW_IMPLICIT_CONSTRUCTORS(NgramListenerForPrediction);
|
||||
|
||||
const PrevWordsInfo *const mPrevWordsInfo;
|
||||
const WordIdArrayView mPrevWordIds;
|
||||
SuggestionResults *const mSuggestionResults;
|
||||
const DictionaryStructureWithBufferPolicy *const mDictStructurePolicy;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue