am 6ec3f63d: Merge "Make dictionary structure policy have updating methods."

* commit '6ec3f63d59524ed422d8a584d6d5148b0107e582':
  Make dictionary structure policy have updating methods.
main
Keisuke Kuroyanagi 2013-08-14 20:19:29 -07:00 committed by Android Git Automerger
commit d920c917de
8 changed files with 64 additions and 8 deletions

View File

@ -53,6 +53,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jclass clazz, jstring s
jlong dictOffset, jlong dictSize, jboolean isUpdatable) { jlong dictOffset, jlong dictSize, jboolean isUpdatable) {
PROF_OPEN; PROF_OPEN;
PROF_START(66); PROF_START(66);
// TODO: Move dictionary buffer handling to policyimpl.
const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir); const jsize sourceDirUtf8Length = env->GetStringUTFLength(sourceDir);
if (sourceDirUtf8Length <= 0) { if (sourceDirUtf8Length <= 0) {
AKLOGE("DICT: Can't get sourceDir string"); AKLOGE("DICT: Can't get sourceDir string");

View File

@ -49,8 +49,7 @@ class BinaryDictionaryInfo {
} }
AK_FORCE_INLINE bool isDynamicallyUpdatable() const { AK_FORCE_INLINE bool isDynamicallyUpdatable() const {
// TODO: Support dynamic dictionary formats. const bool isUpdatableDictionaryFormat = mDictionaryHeader.supportsDynamicUpdate();
const bool isUpdatableDictionaryFormat = false;
return mIsUpdatable && isUpdatableDictionaryFormat; return mIsUpdatable && isUpdatableDictionaryFormat;
} }

View File

@ -107,7 +107,7 @@ void Dictionary::addUnigramWord(const int *const word, const int length, const i
AKLOGI("Warning: Dictionary::addUnigramWord() is called for non-updatable dictionary."); AKLOGI("Warning: Dictionary::addUnigramWord() is called for non-updatable dictionary.");
return; return;
} }
// TODO: Support dynamic update mDictionaryStructureWithBufferPolicy->addUnigramWord(word, length, probability);
} }
void Dictionary::addBigramWords(const int *const word0, const int length0, const int *const word1, void Dictionary::addBigramWords(const int *const word0, const int length0, const int *const word1,
@ -117,7 +117,8 @@ void Dictionary::addBigramWords(const int *const word0, const int length0, const
AKLOGI("Warning: Dictionary::addBigramWords() is called for non-updatable dictionary."); AKLOGI("Warning: Dictionary::addBigramWords() is called for non-updatable dictionary.");
return; return;
} }
// TODO: Support dynamic update mDictionaryStructureWithBufferPolicy->addBigramWords(word0, length0, word1, length1,
probability);
} }
void Dictionary::removeBigramWords(const int *const word0, const int length0, void Dictionary::removeBigramWords(const int *const word0, const int length0,
@ -127,7 +128,7 @@ void Dictionary::removeBigramWords(const int *const word0, const int length0,
AKLOGI("Warning: Dictionary::removeBigramWords() is called for non-updatable dictionary."); AKLOGI("Warning: Dictionary::removeBigramWords() is called for non-updatable dictionary.");
return; return;
} }
// TODO: Support dynamic update mDictionaryStructureWithBufferPolicy->removeBigramWords(word0, length0, word1, length1);
} }
void Dictionary::logDictionaryInfo(JNIEnv *const env) const { void Dictionary::logDictionaryInfo(JNIEnv *const env) const {

View File

@ -94,9 +94,9 @@ class Dictionary {
const BinaryDictionaryInfo mBinaryDictionaryInfo; const BinaryDictionaryInfo mBinaryDictionaryInfo;
DictionaryStructureWithBufferPolicy *const mDictionaryStructureWithBufferPolicy; DictionaryStructureWithBufferPolicy *const mDictionaryStructureWithBufferPolicy;
const BigramDictionary *mBigramDictionary; const BigramDictionary *const mBigramDictionary;
SuggestInterface *mGestureSuggest; const SuggestInterface *const mGestureSuggest;
SuggestInterface *mTypingSuggest; const SuggestInterface *const mTypingSuggest;
void logDictionaryInfo(JNIEnv *const env) const; void logDictionaryInfo(JNIEnv *const env) const;
}; };

View File

@ -59,6 +59,18 @@ class DictionaryStructureWithBufferPolicy {
virtual const DictionaryShortcutsStructurePolicy *getShortcutsStructurePolicy() const = 0; virtual const DictionaryShortcutsStructurePolicy *getShortcutsStructurePolicy() const = 0;
// Returns whether the update was success or not.
virtual bool addUnigramWord(const int *const word, const int length,
const int probability) = 0;
// Returns whether the update was success or not.
virtual bool addBigramWords(const int *const word0, const int length0, const int *const word1,
const int length1, const int probability) = 0;
// Returns whether the update was success or not.
virtual bool removeBigramWords(const int *const word0, const int length0,
const int *const word1, const int length1) = 0;
protected: protected:
DictionaryStructureWithBufferPolicy() {} DictionaryStructureWithBufferPolicy() {}

View File

@ -231,4 +231,22 @@ int DynamicPatriciaTriePolicy::getBigramsPositionOfNode(const int nodePos) const
return nodeReader.getBigramsPos(); return nodeReader.getBigramsPos();
} }
bool DynamicPatriciaTriePolicy::addUnigramWord(const int *const word, const int length,
const int probability) {
// TODO: Implement.
return false;
}
bool DynamicPatriciaTriePolicy::addBigramWords(const int *const word0, const int length0,
const int *const word1, const int length1, const int probability) {
// TODO: Implement.
return false;
}
bool DynamicPatriciaTriePolicy::removeBigramWords(const int *const word0, const int length0,
const int *const word1, const int length1) {
// TODO: Implement.
return false;
}
} // namespace latinime } // namespace latinime

View File

@ -70,6 +70,14 @@ class DynamicPatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
return &mShortcutListPolicy; return &mShortcutListPolicy;
} }
bool addUnigramWord(const int *const word, const int length, const int probability);
bool addBigramWords(const int *const word0, const int length0, const int *const word1,
const int length1, const int probability);
bool removeBigramWords(const int *const word0, const int length0, const int *const word1,
const int length1);
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicPatriciaTriePolicy); DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicPatriciaTriePolicy);
static const int MAX_CHILD_COUNT_TO_AVOID_INFINITE_LOOP; static const int MAX_CHILD_COUNT_TO_AVOID_INFINITE_LOOP;

View File

@ -70,6 +70,23 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
return &mShortcutListPolicy; return &mShortcutListPolicy;
} }
bool addUnigramWord(const int *const word, const int length, const int probability) {
// This dictionary format is not updatable.
return false;
}
bool addBigramWords(const int *const word0, const int length0, const int *const word1,
const int length1, const int probability) {
// This dictionary format is not updatable.
return false;
}
bool removeBigramWords(const int *const word0, const int length0, const int *const word1,
const int length1) {
// This dictionary format is not updatable.
return false;
}
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(PatriciaTriePolicy); DISALLOW_IMPLICIT_CONSTRUCTORS(PatriciaTriePolicy);