diff options
author | 2013-06-26 12:51:33 +0900 | |
---|---|---|
committer | 2013-06-26 12:51:33 +0900 | |
commit | 5bf1be71629607e7206e6203489cf742d2f8ed79 (patch) | |
tree | 84ce7e64082e7f44be0a6a1b0606d5cc14a99846 /native/jni/src | |
parent | 4da287d0d153a6994d39be29cef167105978aba1 (diff) | |
download | latinime-5bf1be71629607e7206e6203489cf742d2f8ed79.tar.gz latinime-5bf1be71629607e7206e6203489cf742d2f8ed79.tar.xz latinime-5bf1be71629607e7206e6203489cf742d2f8ed79.zip |
Add jni methods for dynamically handling a dictionary.
Bug: 6669677
Change-Id: I8a26623adbb41a78e3c023c652be635c635e3b47
Diffstat (limited to 'native/jni/src')
3 files changed, 47 insertions, 7 deletions
diff --git a/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp b/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp index 6e02100fc..242a9bdd6 100644 --- a/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/bigram_dictionary.cpp @@ -184,13 +184,13 @@ bool BigramDictionary::checkFirstCharacter(int *word, int *inputCodePoints) cons return false; } -bool BigramDictionary::isValidBigram(const int *word1, int length1, const int *word2, - int length2) const { - int pos = getBigramListPositionForWord(word1, length1, false /* forceLowerCaseSearch */); +bool BigramDictionary::isValidBigram(const int *word0, int length0, const int *word1, + int length1) const { + int pos = getBigramListPositionForWord(word0, length0, false /* forceLowerCaseSearch */); // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams if (0 == pos) return false; int nextWordPos = BinaryFormat::getTerminalPosition(mBinaryDictionaryInfo->getDictRoot(), - word2, length2, false /* forceLowerCaseSearch */); + word1, length1, false /* forceLowerCaseSearch */); if (NOT_VALID_WORD == nextWordPos) return false; for (BinaryDictionaryBigramsIterator bigramsIt(mBinaryDictionaryInfo, pos); diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index 028b61506..51f23dc55 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -106,8 +106,37 @@ int Dictionary::getProbability(const int *word, int length) const { return unigramProbability; } -bool Dictionary::isValidBigram(const int *word1, int length1, const int *word2, int length2) const { - return mBigramDictionary->isValidBigram(word1, length1, word2, length2); +bool Dictionary::isValidBigram(const int *word0, int length0, const int *word1, int length1) const { + return mBigramDictionary->isValidBigram(word0, length0, word1, length1); +} + +void Dictionary::addUnigramWord(const int *const word, const int length, const int probability) { + if (!mBinaryDictionaryInfo.isDynamicallyUpdatable()) { + // This method should not be called for non-updatable dictionary. + AKLOGI("Warning: Dictionary::addUnigramWord() is called for non-updatable dictionary."); + return; + } + // TODO: Support dynamic update +} + +void Dictionary::addBigramWords(const int *const word0, const int length0, const int *const word1, + const int length1, const int probability) { + if (!mBinaryDictionaryInfo.isDynamicallyUpdatable()) { + // This method should not be called for non-updatable dictionary. + AKLOGI("Warning: Dictionary::addBigramWords() is called for non-updatable dictionary."); + return; + } + // TODO: Support dynamic update +} + +void Dictionary::removeBigramWords(const int *const word0, const int length0, + const int *const word1, const int length1) { + if (!mBinaryDictionaryInfo.isDynamicallyUpdatable()) { + // This method should not be called for non-updatable dictionary. + AKLOGI("Warning: Dictionary::removeBigramWords() is called for non-updatable dictionary."); + return; + } + // TODO: Support dynamic update } } // namespace latinime diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h index afd081841..94579c200 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.h +++ b/native/jni/src/suggest/core/dictionary/dictionary.h @@ -64,10 +64,21 @@ class Dictionary { int *frequencies, int *outputTypes) const; int getProbability(const int *word, int length) const; - bool isValidBigram(const int *word1, int length1, const int *word2, int length2) const; + + bool isValidBigram(const int *word0, int length0, const int *word1, int length1) const; + + void addUnigramWord(const int *const word, const int length, const int probability); + + void addBigramWords(const int *const word0, const int length0, const int *const word1, + const int length1, const int probability); + + void removeBigramWords(const int *const word0, const int length0, const int *const word1, + const int length1); + const BinaryDictionaryInfo *getBinaryDictionaryInfo() const { return &mBinaryDictionaryInfo; } + virtual ~Dictionary(); private: |