am e531c224: Move a flag about switching dynamic update to java.

* commit 'e531c2241eb8d5a1462c43ce0deffaf6c769cc23':
  Move a flag about switching dynamic update to java.
main
Keisuke Kuroyanagi 2013-09-10 02:56:59 -07:00 committed by Android Git Automerger
commit a01e18d581
4 changed files with 35 additions and 33 deletions

View File

@ -49,6 +49,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/** Whether to print debug output to log */
private static boolean DEBUG = false;
// TODO: Remove and enable dynamic update in native code.
/** Whether to call binary dictionary dynamically updating methods. */
private static boolean ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE = false;
/**
* The maximum length of a word in this dictionary.
*/
@ -72,6 +76,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/
private BinaryDictionary mBinaryDictionary;
// TODO: Remove and handle dictionaries in native code.
/** The in-memory dictionary used to generate the binary dictionary. */
protected AbstractDictionaryWriter mDictionaryWriter;
@ -225,6 +230,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// TODO: Use a queue to reflect what needs to be reflected.
if (mLocalDictionaryController.writeLock().tryLock()) {
try {
if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
mBinaryDictionary.addUnigramWord(word, frequency);
}
// TODO: Remove.
mDictionaryWriter.addUnigramWord(word, shortcutTarget, frequency, isNotAWord);
} finally {
mLocalDictionaryController.writeLock().unlock();
@ -245,6 +254,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// TODO: Use a queue to reflect what needs to be reflected.
if (mLocalDictionaryController.writeLock().tryLock()) {
try {
if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
mBinaryDictionary.addBigramWords(word0, word1, frequency);
}
// TODO: Remove.
mDictionaryWriter.addBigramWords(word0, word1, frequency, isValid,
0 /* lastTouchedTime */);
} finally {
@ -265,6 +278,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// TODO: Use a queue to reflect what needs to be reflected.
if (mLocalDictionaryController.writeLock().tryLock()) {
try {
if (ENABLE_BINARY_DICTIONARY_DYNAMIC_UPDATE) {
mBinaryDictionary.removeBigramWords(word0, word1);
}
// TODO: Remove.
mDictionaryWriter.removeBigramWords(word0, word1);
} finally {
mLocalDictionaryController.writeLock().unlock();

View File

@ -204,6 +204,7 @@ static void latinime_BinaryDictionary_addUnigramWord(JNIEnv *env, jclass clazz,
}
jsize wordLength = env->GetArrayLength(word);
int codePoints[wordLength];
env->GetIntArrayRegion(word, 0, wordLength, codePoints);
dictionary->addUnigramWord(codePoints, wordLength, probability);
}
@ -215,8 +216,10 @@ static void latinime_BinaryDictionary_addBigramWords(JNIEnv *env, jclass clazz,
}
jsize word0Length = env->GetArrayLength(word0);
int word0CodePoints[word0Length];
env->GetIntArrayRegion(word0, 0, word0Length, word0CodePoints);
jsize word1Length = env->GetArrayLength(word1);
int word1CodePoints[word1Length];
env->GetIntArrayRegion(word1, 0, word1Length, word1CodePoints);
dictionary->addBigramWords(word0CodePoints, word0Length, word1CodePoints,
word1Length, probability);
}
@ -229,8 +232,10 @@ static void latinime_BinaryDictionary_removeBigramWords(JNIEnv *env, jclass claz
}
jsize word0Length = env->GetArrayLength(word0);
int word0CodePoints[word0Length];
env->GetIntArrayRegion(word0, 0, word0Length, word0CodePoints);
jsize word1Length = env->GetArrayLength(word1);
int word1CodePoints[word1Length];
env->GetIntArrayRegion(word1, 0, word1Length, word1CodePoints);
dictionary->removeBigramWords(word0CodePoints, word0Length, word1CodePoints,
word1Length);
}

View File

@ -26,9 +26,6 @@
namespace latinime {
// TODO: Enable dynamic update and remove this flag.
const bool DynamicPatriciaTrieWritingHelper::ENABLE_DYNAMIC_UPDATE = false;
bool DynamicPatriciaTrieWritingHelper::addUnigramWord(
DynamicPatriciaTrieReadingHelper *const readingHelper,
const int *const wordCodePoints, const int codePointCount, const int probability) {
@ -49,33 +46,21 @@ bool DynamicPatriciaTrieWritingHelper::addUnigramWord(
const int nextIndex = matchedCodePointCount + j;
if (nextIndex >= codePointCount || !readingHelper->isMatchedCodePoint(j,
wordCodePoints[matchedCodePointCount + j])) {
if (ENABLE_DYNAMIC_UPDATE) {
return reallocatePtNodeAndAddNewPtNodes(nodeReader,
readingHelper->getMergedNodeCodePoints(), j, probability,
wordCodePoints + matchedCodePointCount,
codePointCount - matchedCodePointCount);
} else {
return false;
}
}
}
// All characters are matched.
if (codePointCount == readingHelper->getTotalCodePointCount()) {
if (ENABLE_DYNAMIC_UPDATE) {
return setPtNodeProbability(nodeReader, probability,
readingHelper->getMergedNodeCodePoints());
} else {
return false;
}
}
if (!nodeReader->hasChildren()) {
if (ENABLE_DYNAMIC_UPDATE) {
return createChildrenPtNodeArrayAndAChildPtNode(nodeReader, probability,
wordCodePoints + readingHelper->getTotalCodePointCount(),
codePointCount - readingHelper->getTotalCodePointCount());
} else {
return false;
}
}
// Advance to the children nodes.
parentPos = nodeReader->getNodePos();
@ -86,14 +71,10 @@ bool DynamicPatriciaTrieWritingHelper::addUnigramWord(
return false;
}
int pos = readingHelper->getPosOfLastForwardLinkField();
if (ENABLE_DYNAMIC_UPDATE) {
return createAndInsertNodeIntoPtNodeArray(parentPos,
wordCodePoints + readingHelper->getPrevTotalCodePointCount(),
codePointCount - readingHelper->getPrevTotalCodePointCount(),
probability, &pos);
} else {
return false;
}
}
bool DynamicPatriciaTrieWritingHelper::addBigramWords(const int word0Pos, const int word1Pos,

View File

@ -49,7 +49,6 @@ class DynamicPatriciaTrieWritingHelper {
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(DynamicPatriciaTrieWritingHelper);
static const bool ENABLE_DYNAMIC_UPDATE;
BufferWithExtendableBuffer *const mBuffer;
DynamicBigramListPolicy *const mBigramPolicy;
DynamicShortcutListPolicy *const mShortcutPolicy;