Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb6a7c82 authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android (Google) Code Review
Browse files

Merge "Migrate used functions in UnigramDicitonary"

parents 2a529b85 6c4ad527
Loading
Loading
Loading
Loading
+33 −26
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
#include <stdint.h>

#include "defines.h"
#include "obsolete/unigram_dictionary.h"
#include "suggest/core/dictionary/bigram_dictionary.h"
#include "suggest/core/dictionary/binary_format.h"
#include "suggest/core/session/dic_traverse_session.h"
@@ -35,16 +34,15 @@ namespace latinime {

Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust)
        : mBinaryDicitonaryInfo(static_cast<const uint8_t *>(dict), dictSize),
          mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
          mUnigramDictionary(new UnigramDictionary(&mBinaryDicitonaryInfo,
                  BinaryFormat::getFlags(mBinaryDicitonaryInfo.getDictBuf(), dictSize))),
          mDictSize(dictSize),
          mDictFlags(BinaryFormat::getFlags(mBinaryDicitonaryInfo.getDictBuf(), dictSize)),
          mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
          mBigramDictionary(new BigramDictionary(&mBinaryDicitonaryInfo)),
          mGestureSuggest(new Suggest(GestureSuggestPolicyFactory::getGestureSuggestPolicy())),
          mTypingSuggest(new Suggest(TypingSuggestPolicyFactory::getTypingSuggestPolicy())) {
}

Dictionary::~Dictionary() {
    delete mUnigramDictionary;
    delete mBigramDictionary;
    delete mGestureSuggest;
    delete mTypingSuggest;
@@ -67,7 +65,6 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
        }
        return result;
    } else {
        if (USE_SUGGEST_INTERFACE_FOR_TYPING) {
        DicTraverseSession::initSessionInstance(
                traverseSession, this, prevWordCodePoints, prevWordLength, suggestOptions);
        result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
@@ -77,16 +74,6 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, DicTraverseSession
            DUMP_RESULT(outWords, frequencies);
        }
        return result;
        } else {
            std::map<int, int> bigramMap;
            uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE];
            mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints,
                    prevWordLength, &bigramMap, bigramFilter);
            result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
                    inputCodePoints, inputSize, &bigramMap, bigramFilter,
                    suggestOptions->useFullEditDistance(), outWords, frequencies, outputTypes);
            return result;
        }
    }
}

@@ -98,7 +85,27 @@ int Dictionary::getBigrams(const int *word, int length, int *inputCodePoints, in
}

int Dictionary::getProbability(const int *word, int length) const {
    return mUnigramDictionary->getProbability(word, length);
    const uint8_t *const root = mBinaryDicitonaryInfo.getDictRoot();
    int pos = BinaryFormat::getTerminalPosition(root, word, length,
            false /* forceLowerCaseSearch */);
    if (NOT_VALID_WORD == pos) {
        return NOT_A_PROBABILITY;
    }
    const uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(root, &pos);
    if (flags & (BinaryFormat::FLAG_IS_BLACKLISTED | BinaryFormat::FLAG_IS_NOT_A_WORD)) {
        // If this is not a word, or if it's a blacklisted entry, it should behave as
        // having no probability outside of the suggestion process (where it should be used
        // for shortcuts).
        return NOT_A_PROBABILITY;
    }
    const bool hasMultipleChars = (0 != (BinaryFormat::FLAG_HAS_MULTIPLE_CHARS & flags));
    if (hasMultipleChars) {
        pos = BinaryFormat::skipOtherCharacters(root, pos);
    } else {
        BinaryFormat::getCodePointAndForwardPointer(root, &pos);
    }
    const int unigramProbability = BinaryFormat::readProbabilityWithoutMovingPointer(root, pos);
    return unigramProbability;
}

bool Dictionary::isValidBigram(const int *word1, int length1, const int *word2, int length2) const {
@@ -106,7 +113,7 @@ bool Dictionary::isValidBigram(const int *word1, int length1, const int *word2,
}

int Dictionary::getDictFlags() const {
    return mUnigramDictionary->getDictFlags();
    return mDictFlags;
}

} // namespace latinime
+1 −2
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ class DicTraverseSession;
class ProximityInfo;
class SuggestInterface;
class SuggestOptions;
class UnigramDictionary;

class Dictionary {
 public:
@@ -82,10 +81,10 @@ class Dictionary {
    // Used only for the mmap version of dictionary loading, but we use these as dummy variables
    // also for the malloc version.
    const int mDictSize;
    const int mDictFlags;
    const int mMmapFd;
    const int mDictBufAdjust;

    const UnigramDictionary *mUnigramDictionary;
    const BigramDictionary *mBigramDictionary;
    SuggestInterface *mGestureSuggest;
    SuggestInterface *mTypingSuggest;