am 6cc1cb63: Merge "Use getProbabilityOfWordInContext for prediction."

* commit '6cc1cb63720ff0f15272057a80c3126567884371':
  Use getProbabilityOfWordInContext for prediction.
main
Keisuke Kuroyanagi 2014-09-10 11:46:06 +00:00 committed by Android Git Automerger
commit 0c202793dc
2 changed files with 12 additions and 8 deletions

View File

@ -61,10 +61,11 @@ void Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
} }
Dictionary::NgramListenerForPrediction::NgramListenerForPrediction( Dictionary::NgramListenerForPrediction::NgramListenerForPrediction(
const PrevWordsInfo *const prevWordsInfo, SuggestionResults *const suggestionResults, const PrevWordsInfo *const prevWordsInfo, const WordIdArrayView prevWordIds,
SuggestionResults *const suggestionResults,
const DictionaryStructureWithBufferPolicy *const dictStructurePolicy) const DictionaryStructureWithBufferPolicy *const dictStructurePolicy)
: mPrevWordsInfo(prevWordsInfo), mSuggestionResults(suggestionResults), : mPrevWordsInfo(prevWordsInfo), mPrevWordIds(prevWordIds),
mDictStructurePolicy(dictStructurePolicy) {} mSuggestionResults(suggestionResults), mDictStructurePolicy(dictStructurePolicy) {}
void Dictionary::NgramListenerForPrediction::onVisitEntry(const int ngramProbability, void Dictionary::NgramListenerForPrediction::onVisitEntry(const int ngramProbability,
const int targetWordId) { const int targetWordId) {
@ -83,19 +84,20 @@ void Dictionary::NgramListenerForPrediction::onVisitEntry(const int ngramProbabi
if (codePointCount <= 0) { if (codePointCount <= 0) {
return; return;
} }
const int probability = mDictStructurePolicy->getProbability( const int probability = mDictStructurePolicy->getProbabilityOfWordInContext(mPrevWordIds.data(),
unigramProbability, ngramProbability); targetWordId, nullptr /* multiBigramMap */);
mSuggestionResults->addPrediction(targetWordCodePoints, codePointCount, probability); mSuggestionResults->addPrediction(targetWordCodePoints, codePointCount, probability);
} }
void Dictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo, void Dictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo,
SuggestionResults *const outSuggestionResults) const { SuggestionResults *const outSuggestionResults) const {
TimeKeeper::setCurrentTime(); TimeKeeper::setCurrentTime();
NgramListenerForPrediction listener(prevWordsInfo, outSuggestionResults,
mDictionaryStructureWithBufferPolicy.get());
int prevWordIds[MAX_PREV_WORD_COUNT_FOR_N_GRAM]; int prevWordIds[MAX_PREV_WORD_COUNT_FOR_N_GRAM];
prevWordsInfo->getPrevWordIds(mDictionaryStructureWithBufferPolicy.get(), prevWordIds, prevWordsInfo->getPrevWordIds(mDictionaryStructureWithBufferPolicy.get(), prevWordIds,
true /* tryLowerCaseSearch */); true /* tryLowerCaseSearch */);
NgramListenerForPrediction listener(prevWordsInfo,
WordIdArrayView::fromFixedSizeArray(prevWordIds), outSuggestionResults,
mDictionaryStructureWithBufferPolicy.get());
mDictionaryStructureWithBufferPolicy->iterateNgramEntries(prevWordIds, &listener); mDictionaryStructureWithBufferPolicy->iterateNgramEntries(prevWordIds, &listener);
} }

View File

@ -26,6 +26,7 @@
#include "suggest/core/policy/dictionary_header_structure_policy.h" #include "suggest/core/policy/dictionary_header_structure_policy.h"
#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h" #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
#include "suggest/core/suggest_interface.h" #include "suggest/core/suggest_interface.h"
#include "utils/int_array_view.h"
namespace latinime { namespace latinime {
@ -118,7 +119,7 @@ class Dictionary {
class NgramListenerForPrediction : public NgramListener { class NgramListenerForPrediction : public NgramListener {
public: public:
NgramListenerForPrediction(const PrevWordsInfo *const prevWordsInfo, NgramListenerForPrediction(const PrevWordsInfo *const prevWordsInfo,
SuggestionResults *const suggestionResults, const WordIdArrayView prevWordIds, SuggestionResults *const suggestionResults,
const DictionaryStructureWithBufferPolicy *const dictStructurePolicy); const DictionaryStructureWithBufferPolicy *const dictStructurePolicy);
virtual void onVisitEntry(const int ngramProbability, const int targetWordId); virtual void onVisitEntry(const int ngramProbability, const int targetWordId);
@ -126,6 +127,7 @@ class Dictionary {
DISALLOW_IMPLICIT_CONSTRUCTORS(NgramListenerForPrediction); DISALLOW_IMPLICIT_CONSTRUCTORS(NgramListenerForPrediction);
const PrevWordsInfo *const mPrevWordsInfo; const PrevWordsInfo *const mPrevWordsInfo;
const WordIdArrayView mPrevWordIds;
SuggestionResults *const mSuggestionResults; SuggestionResults *const mSuggestionResults;
const DictionaryStructureWithBufferPolicy *const mDictStructurePolicy; const DictionaryStructureWithBufferPolicy *const mDictStructurePolicy;
}; };