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

View File

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

View File

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

View File

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