am 6cc1cb63: Merge "Use getProbabilityOfWordInContext for prediction."
* commit '6cc1cb63720ff0f15272057a80c3126567884371': Use getProbabilityOfWordInContext for prediction.main
commit
0c202793dc
|
@ -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 New Issue