am b0df28f4: Merge "[HD02] Make the date header attribute mandatory."

* commit 'b0df28f4cc225c5e41ce4e51ec23f1bac5f6f4fe':
  [HD02] Make the date header attribute mandatory.
main
Jean Chalard 2014-01-30 20:43:29 -08:00 committed by Android Git Automerger
commit 2fe4cdf4eb
5 changed files with 34 additions and 38 deletions

View File

@ -46,7 +46,7 @@ public final class UserHistoryDictIOUtils {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE"; private static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE";
private static final String USES_FORGETTING_CURVE_VALUE = "1"; private static final String USES_FORGETTING_CURVE_VALUE = "1";
private static final String LAST_UPDATED_TIME_KEY = "date"; private static final String DATE_KEY = "date";
public interface OnAddWordListener { public interface OnAddWordListener {
/** /**
@ -76,7 +76,7 @@ public final class UserHistoryDictIOUtils {
final FormatOptions formatOptions, final HashMap<String, String> options) { final FormatOptions formatOptions, final HashMap<String, String> options) {
final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams, options); final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams, options);
fusionDict.addOptionAttribute(USES_FORGETTING_CURVE_KEY, USES_FORGETTING_CURVE_VALUE); fusionDict.addOptionAttribute(USES_FORGETTING_CURVE_KEY, USES_FORGETTING_CURVE_VALUE);
fusionDict.addOptionAttribute(LAST_UPDATED_TIME_KEY, fusionDict.addOptionAttribute(DATE_KEY,
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
try { try {
dictEncoder.writeDictionary(fusionDict, formatOptions); dictEncoder.writeDictionary(fusionDict, formatOptions);

View File

@ -24,7 +24,7 @@ const char *const HeaderPolicy::REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY =
"REQUIRES_GERMAN_UMLAUT_PROCESSING"; "REQUIRES_GERMAN_UMLAUT_PROCESSING";
// TODO: Change attribute string to "IS_DECAYING_DICT". // TODO: Change attribute string to "IS_DECAYING_DICT".
const char *const HeaderPolicy::IS_DECAYING_DICT_KEY = "USES_FORGETTING_CURVE"; const char *const HeaderPolicy::IS_DECAYING_DICT_KEY = "USES_FORGETTING_CURVE";
const char *const HeaderPolicy::LAST_UPDATED_TIME_KEY = "date"; const char *const HeaderPolicy::DATE_KEY = "date";
const char *const HeaderPolicy::LAST_DECAYED_TIME_KEY = "LAST_DECAYED_TIME"; const char *const HeaderPolicy::LAST_DECAYED_TIME_KEY = "LAST_DECAYED_TIME";
const char *const HeaderPolicy::UNIGRAM_COUNT_KEY = "UNIGRAM_COUNT"; const char *const HeaderPolicy::UNIGRAM_COUNT_KEY = "UNIGRAM_COUNT";
const char *const HeaderPolicy::BIGRAM_COUNT_KEY = "BIGRAM_COUNT"; const char *const HeaderPolicy::BIGRAM_COUNT_KEY = "BIGRAM_COUNT";
@ -73,13 +73,13 @@ bool HeaderPolicy::readRequiresGermanUmlautProcessing() const {
REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY, false); REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY, false);
} }
bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTime, bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastDecayedTime,
const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, const int unigramCount, const int bigramCount,
const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const { const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const {
int writingPos = 0; int writingPos = 0;
HeaderReadWriteUtils::AttributeMap attributeMapToWrite(mAttributeMap); HeaderReadWriteUtils::AttributeMap attributeMapToWrite(mAttributeMap);
fillInHeader(updatesLastDecayedTime, updatesLastDecayedTime, fillInHeader(updatesLastDecayedTime, unigramCount, bigramCount,
unigramCount, bigramCount, extendedRegionSize, &attributeMapToWrite); extendedRegionSize, &attributeMapToWrite);
if (!HeaderReadWriteUtils::writeDictionaryVersion(outBuffer, mDictFormatVersion, if (!HeaderReadWriteUtils::writeDictionaryVersion(outBuffer, mDictFormatVersion,
&writingPos)) { &writingPos)) {
return false; return false;
@ -106,18 +106,16 @@ bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTim
return true; return true;
} }
void HeaderPolicy::fillInHeader(const bool updatesLastUpdatedTime, void HeaderPolicy::fillInHeader(const bool updatesLastDecayedTime, const int unigramCount,
const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, const int bigramCount, const int extendedRegionSize,
const int extendedRegionSize, HeaderReadWriteUtils::AttributeMap *outAttributeMap) const { HeaderReadWriteUtils::AttributeMap *outAttributeMap) const {
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, UNIGRAM_COUNT_KEY, unigramCount); HeaderReadWriteUtils::setIntAttribute(outAttributeMap, UNIGRAM_COUNT_KEY, unigramCount);
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, BIGRAM_COUNT_KEY, bigramCount); HeaderReadWriteUtils::setIntAttribute(outAttributeMap, BIGRAM_COUNT_KEY, bigramCount);
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, EXTENDED_REGION_SIZE_KEY, HeaderReadWriteUtils::setIntAttribute(outAttributeMap, EXTENDED_REGION_SIZE_KEY,
extendedRegionSize); extendedRegionSize);
if (updatesLastUpdatedTime) { // Set the current time as the generation time.
// Set current time as the last updated time. HeaderReadWriteUtils::setIntAttribute(outAttributeMap, DATE_KEY,
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime());
TimeKeeper::peekCurrentTime());
}
if (updatesLastDecayedTime) { if (updatesLastDecayedTime) {
// Set current time as the last updated time. // Set current time as the last updated time.
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_DECAYED_TIME_KEY, HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_DECAYED_TIME_KEY,

View File

@ -39,8 +39,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()), mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()),
mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap, mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap,
IS_DECAYING_DICT_KEY, false /* defaultValue */)), IS_DECAYING_DICT_KEY, false /* defaultValue */)),
mLastUpdatedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, mDate(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
LAST_DECAYED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), LAST_DECAYED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
mUnigramCount(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, mUnigramCount(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
@ -62,10 +62,10 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()), mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()),
mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap, mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap,
IS_DECAYING_DICT_KEY, false /* defaultValue */)), IS_DECAYING_DICT_KEY, false /* defaultValue */)),
mLastUpdatedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, mDate(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap, mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)), DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
mUnigramCount(0), mBigramCount(0), mExtendedRegionSize(0), mUnigramCount(0), mBigramCount(0), mExtendedRegionSize(0),
mHasHistoricalInfoOfWords(HeaderReadWriteUtils::readBoolAttributeValue( mHasHistoricalInfoOfWords(HeaderReadWriteUtils::readBoolAttributeValue(
&mAttributeMap, HAS_HISTORICAL_INFO_KEY, false /* defaultValue */)) {} &mAttributeMap, HAS_HISTORICAL_INFO_KEY, false /* defaultValue */)) {}
@ -75,7 +75,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
: mDictFormatVersion(FormatUtils::UNKNOWN_VERSION), mDictionaryFlags(0), mSize(0), : mDictFormatVersion(FormatUtils::UNKNOWN_VERSION), mDictionaryFlags(0), mSize(0),
mAttributeMap(), mMultiWordCostMultiplier(0.0f), mAttributeMap(), mMultiWordCostMultiplier(0.0f),
mRequiresGermanUmlautProcessing(false), mIsDecayingDict(false), mRequiresGermanUmlautProcessing(false), mIsDecayingDict(false),
mLastUpdatedTime(0), mLastDecayedTime(0), mUnigramCount(0), mBigramCount(0), mDate(0), mLastDecayedTime(0), mUnigramCount(0), mBigramCount(0),
mExtendedRegionSize(0), mHasHistoricalInfoOfWords(false) {} mExtendedRegionSize(0), mHasHistoricalInfoOfWords(false) {}
~HeaderPolicy() {} ~HeaderPolicy() {}
@ -122,8 +122,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
return mRequiresGermanUmlautProcessing; return mRequiresGermanUmlautProcessing;
} }
AK_FORCE_INLINE int getLastUpdatedTime() const { AK_FORCE_INLINE int getDate() const {
return mLastUpdatedTime; return mDate;
} }
AK_FORCE_INLINE int getLastDecayedTime() const { AK_FORCE_INLINE int getLastDecayedTime() const {
@ -149,11 +149,11 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
void readHeaderValueOrQuestionMark(const char *const key, void readHeaderValueOrQuestionMark(const char *const key,
int *outValue, int outValueSize) const; int *outValue, int outValueSize) const;
bool fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTime, bool fillInAndWriteHeaderToBuffer(const bool updatesLastDecayedTime,
const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount, const int unigramCount, const int bigramCount,
const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const; const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const;
void fillInHeader(const bool updatesLastUpdatedTime, const bool updatesLastDecayedTime, void fillInHeader(const bool updatesLastDecayedTime,
const int unigramCount, const int bigramCount, const int extendedRegionSize, const int unigramCount, const int bigramCount, const int extendedRegionSize,
HeaderReadWriteUtils::AttributeMap *outAttributeMap) const; HeaderReadWriteUtils::AttributeMap *outAttributeMap) const;
@ -163,7 +163,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
static const char *const MULTIPLE_WORDS_DEMOTION_RATE_KEY; static const char *const MULTIPLE_WORDS_DEMOTION_RATE_KEY;
static const char *const REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY; static const char *const REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY;
static const char *const IS_DECAYING_DICT_KEY; static const char *const IS_DECAYING_DICT_KEY;
static const char *const LAST_UPDATED_TIME_KEY; static const char *const DATE_KEY;
static const char *const LAST_DECAYED_TIME_KEY; static const char *const LAST_DECAYED_TIME_KEY;
static const char *const UNIGRAM_COUNT_KEY; static const char *const UNIGRAM_COUNT_KEY;
static const char *const BIGRAM_COUNT_KEY; static const char *const BIGRAM_COUNT_KEY;
@ -179,7 +179,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
const float mMultiWordCostMultiplier; const float mMultiWordCostMultiplier;
const bool mRequiresGermanUmlautProcessing; const bool mRequiresGermanUmlautProcessing;
const bool mIsDecayingDict; const bool mIsDecayingDict;
const int mLastUpdatedTime; const int mDate;
const int mLastDecayedTime; const int mLastDecayedTime;
const int mUnigramCount; const int mUnigramCount;
const int mBigramCount; const int mBigramCount;

View File

@ -39,12 +39,11 @@ void Ver4PatriciaTrieWritingHelper::writeToDictFile(const char *const dictDirPat
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE); BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
const int extendedRegionSize = headerPolicy->getExtendedRegionSize() const int extendedRegionSize = headerPolicy->getExtendedRegionSize()
+ mBuffers->getTrieBuffer()->getUsedAdditionalBufferSize(); + mBuffers->getTrieBuffer()->getUsedAdditionalBufferSize();
if (!headerPolicy->fillInAndWriteHeaderToBuffer(false /* updatesLastUpdatedTime */, if (!headerPolicy->fillInAndWriteHeaderToBuffer(false /* updatesLastDecayedTime */,
false /* updatesLastDecayedTime */, unigramCount, bigramCount, extendedRegionSize, unigramCount, bigramCount, extendedRegionSize, &headerBuffer)) {
&headerBuffer)) { AKLOGE("Cannot write header structure to buffer. "
AKLOGE("Cannot write header structure to buffer. updatesLastUpdatedTime: %d, "
"updatesLastDecayedTime: %d, unigramCount: %d, bigramCount: %d, " "updatesLastDecayedTime: %d, unigramCount: %d, bigramCount: %d, "
"extendedRegionSize: %d", false, false, unigramCount, bigramCount, "extendedRegionSize: %d", false, unigramCount, bigramCount,
extendedRegionSize); extendedRegionSize);
return; return;
} }
@ -63,9 +62,8 @@ void Ver4PatriciaTrieWritingHelper::writeToDictFileWithGC(const int rootPtNodeAr
} }
BufferWithExtendableBuffer headerBuffer( BufferWithExtendableBuffer headerBuffer(
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE); BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
if (!headerPolicy->fillInAndWriteHeaderToBuffer(true /* updatesLastUpdatedTime */, if (!headerPolicy->fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */,
true /* updatesLastDecayedTime */, unigramCount, bigramCount, unigramCount, bigramCount, 0 /* extendedRegionSize */, &headerBuffer)) {
0 /* extendedRegionSize */, &headerBuffer)) {
return; return;
} }
dictBuffers.get()->flushHeaderAndDictBuffers(dictDirPath, &headerBuffer); dictBuffers.get()->flushHeaderAndDictBuffers(dictDirPath, &headerBuffer);

View File

@ -48,8 +48,8 @@ const char *const DictFileWritingUtils::TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE =
HeaderPolicy headerPolicy(FormatUtils::VERSION_4, attributeMap); HeaderPolicy headerPolicy(FormatUtils::VERSION_4, attributeMap);
Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers = Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers =
Ver4DictBuffers::createVer4DictBuffers(&headerPolicy); Ver4DictBuffers::createVer4DictBuffers(&headerPolicy);
headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastUpdatedTime */, headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */,
true /* updatesLastDecayedTime */, 0 /* unigramCount */, 0 /* bigramCount */, 0 /* unigramCount */, 0 /* bigramCount */,
0 /* extendedRegionSize */, dictBuffers.get()->getWritableHeaderBuffer()); 0 /* extendedRegionSize */, dictBuffers.get()->getWritableHeaderBuffer());
if (!DynamicPtWritingUtils::writeEmptyDictionary( if (!DynamicPtWritingUtils::writeEmptyDictionary(
dictBuffers.get()->getWritableTrieBuffer(), 0 /* rootPos */)) { dictBuffers.get()->getWritableTrieBuffer(), 0 /* rootPos */)) {