[HD02] Make the date header attribute mandatory.
Bug: 11281748 Change-Id: I48a6f3d95ca89ced0c51335527201ecabfb7998emain
parent
324adefca3
commit
a137c21c9c
|
@ -46,7 +46,7 @@ public final class UserHistoryDictIOUtils {
|
|||
private static final boolean DEBUG = false;
|
||||
private static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE";
|
||||
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 {
|
||||
/**
|
||||
|
@ -76,7 +76,7 @@ public final class UserHistoryDictIOUtils {
|
|||
final FormatOptions formatOptions, final HashMap<String, String> options) {
|
||||
final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams, options);
|
||||
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())));
|
||||
try {
|
||||
dictEncoder.writeDictionary(fusionDict, formatOptions);
|
||||
|
|
|
@ -24,7 +24,7 @@ const char *const HeaderPolicy::REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY =
|
|||
"REQUIRES_GERMAN_UMLAUT_PROCESSING";
|
||||
// TODO: Change attribute string to "IS_DECAYING_DICT".
|
||||
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::UNIGRAM_COUNT_KEY = "UNIGRAM_COUNT";
|
||||
const char *const HeaderPolicy::BIGRAM_COUNT_KEY = "BIGRAM_COUNT";
|
||||
|
@ -73,13 +73,13 @@ bool HeaderPolicy::readRequiresGermanUmlautProcessing() const {
|
|||
REQUIRES_GERMAN_UMLAUT_PROCESSING_KEY, false);
|
||||
}
|
||||
|
||||
bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTime,
|
||||
const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount,
|
||||
bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastDecayedTime,
|
||||
const int unigramCount, const int bigramCount,
|
||||
const int extendedRegionSize, BufferWithExtendableBuffer *const outBuffer) const {
|
||||
int writingPos = 0;
|
||||
HeaderReadWriteUtils::AttributeMap attributeMapToWrite(mAttributeMap);
|
||||
fillInHeader(updatesLastDecayedTime, updatesLastDecayedTime,
|
||||
unigramCount, bigramCount, extendedRegionSize, &attributeMapToWrite);
|
||||
fillInHeader(updatesLastDecayedTime, unigramCount, bigramCount,
|
||||
extendedRegionSize, &attributeMapToWrite);
|
||||
if (!HeaderReadWriteUtils::writeDictionaryVersion(outBuffer, mDictFormatVersion,
|
||||
&writingPos)) {
|
||||
return false;
|
||||
|
@ -106,18 +106,16 @@ bool HeaderPolicy::fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTim
|
|||
return true;
|
||||
}
|
||||
|
||||
void HeaderPolicy::fillInHeader(const bool updatesLastUpdatedTime,
|
||||
const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount,
|
||||
const int extendedRegionSize, HeaderReadWriteUtils::AttributeMap *outAttributeMap) const {
|
||||
void HeaderPolicy::fillInHeader(const bool updatesLastDecayedTime, const int unigramCount,
|
||||
const int bigramCount, const int extendedRegionSize,
|
||||
HeaderReadWriteUtils::AttributeMap *outAttributeMap) const {
|
||||
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, UNIGRAM_COUNT_KEY, unigramCount);
|
||||
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, BIGRAM_COUNT_KEY, bigramCount);
|
||||
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, EXTENDED_REGION_SIZE_KEY,
|
||||
extendedRegionSize);
|
||||
if (updatesLastUpdatedTime) {
|
||||
// Set current time as the last updated time.
|
||||
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_UPDATED_TIME_KEY,
|
||||
TimeKeeper::peekCurrentTime());
|
||||
}
|
||||
// Set the current time as the generation time.
|
||||
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, DATE_KEY,
|
||||
TimeKeeper::peekCurrentTime());
|
||||
if (updatesLastDecayedTime) {
|
||||
// Set current time as the last updated time.
|
||||
HeaderReadWriteUtils::setIntAttribute(outAttributeMap, LAST_DECAYED_TIME_KEY,
|
||||
|
|
|
@ -39,8 +39,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()),
|
||||
mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap,
|
||||
IS_DECAYING_DICT_KEY, false /* defaultValue */)),
|
||||
mLastUpdatedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
mDate(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
LAST_DECAYED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
mUnigramCount(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
|
@ -62,10 +62,10 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
mRequiresGermanUmlautProcessing(readRequiresGermanUmlautProcessing()),
|
||||
mIsDecayingDict(HeaderReadWriteUtils::readBoolAttributeValue(&mAttributeMap,
|
||||
IS_DECAYING_DICT_KEY, false /* defaultValue */)),
|
||||
mLastUpdatedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
mDate(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
mLastDecayedTime(HeaderReadWriteUtils::readIntAttributeValue(&mAttributeMap,
|
||||
LAST_UPDATED_TIME_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
DATE_KEY, TimeKeeper::peekCurrentTime() /* defaultValue */)),
|
||||
mUnigramCount(0), mBigramCount(0), mExtendedRegionSize(0),
|
||||
mHasHistoricalInfoOfWords(HeaderReadWriteUtils::readBoolAttributeValue(
|
||||
&mAttributeMap, HAS_HISTORICAL_INFO_KEY, false /* defaultValue */)) {}
|
||||
|
@ -75,7 +75,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
: mDictFormatVersion(FormatUtils::UNKNOWN_VERSION), mDictionaryFlags(0), mSize(0),
|
||||
mAttributeMap(), mMultiWordCostMultiplier(0.0f),
|
||||
mRequiresGermanUmlautProcessing(false), mIsDecayingDict(false),
|
||||
mLastUpdatedTime(0), mLastDecayedTime(0), mUnigramCount(0), mBigramCount(0),
|
||||
mDate(0), mLastDecayedTime(0), mUnigramCount(0), mBigramCount(0),
|
||||
mExtendedRegionSize(0), mHasHistoricalInfoOfWords(false) {}
|
||||
|
||||
~HeaderPolicy() {}
|
||||
|
@ -122,8 +122,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
return mRequiresGermanUmlautProcessing;
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE int getLastUpdatedTime() const {
|
||||
return mLastUpdatedTime;
|
||||
AK_FORCE_INLINE int getDate() const {
|
||||
return mDate;
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE int getLastDecayedTime() const {
|
||||
|
@ -149,11 +149,11 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
void readHeaderValueOrQuestionMark(const char *const key,
|
||||
int *outValue, int outValueSize) const;
|
||||
|
||||
bool fillInAndWriteHeaderToBuffer(const bool updatesLastUpdatedTime,
|
||||
const bool updatesLastDecayedTime, const int unigramCount, const int bigramCount,
|
||||
bool fillInAndWriteHeaderToBuffer(const bool updatesLastDecayedTime,
|
||||
const int unigramCount, const int bigramCount,
|
||||
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,
|
||||
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 REQUIRES_GERMAN_UMLAUT_PROCESSING_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 UNIGRAM_COUNT_KEY;
|
||||
static const char *const BIGRAM_COUNT_KEY;
|
||||
|
@ -179,7 +179,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
|||
const float mMultiWordCostMultiplier;
|
||||
const bool mRequiresGermanUmlautProcessing;
|
||||
const bool mIsDecayingDict;
|
||||
const int mLastUpdatedTime;
|
||||
const int mDate;
|
||||
const int mLastDecayedTime;
|
||||
const int mUnigramCount;
|
||||
const int mBigramCount;
|
||||
|
|
|
@ -39,12 +39,11 @@ void Ver4PatriciaTrieWritingHelper::writeToDictFile(const char *const dictDirPat
|
|||
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
|
||||
const int extendedRegionSize = headerPolicy->getExtendedRegionSize()
|
||||
+ mBuffers->getTrieBuffer()->getUsedAdditionalBufferSize();
|
||||
if (!headerPolicy->fillInAndWriteHeaderToBuffer(false /* updatesLastUpdatedTime */,
|
||||
false /* updatesLastDecayedTime */, unigramCount, bigramCount, extendedRegionSize,
|
||||
&headerBuffer)) {
|
||||
AKLOGE("Cannot write header structure to buffer. updatesLastUpdatedTime: %d, "
|
||||
if (!headerPolicy->fillInAndWriteHeaderToBuffer(false /* updatesLastDecayedTime */,
|
||||
unigramCount, bigramCount, extendedRegionSize, &headerBuffer)) {
|
||||
AKLOGE("Cannot write header structure to buffer. "
|
||||
"updatesLastDecayedTime: %d, unigramCount: %d, bigramCount: %d, "
|
||||
"extendedRegionSize: %d", false, false, unigramCount, bigramCount,
|
||||
"extendedRegionSize: %d", false, unigramCount, bigramCount,
|
||||
extendedRegionSize);
|
||||
return;
|
||||
}
|
||||
|
@ -63,9 +62,8 @@ void Ver4PatriciaTrieWritingHelper::writeToDictFileWithGC(const int rootPtNodeAr
|
|||
}
|
||||
BufferWithExtendableBuffer headerBuffer(
|
||||
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
|
||||
if (!headerPolicy->fillInAndWriteHeaderToBuffer(true /* updatesLastUpdatedTime */,
|
||||
true /* updatesLastDecayedTime */, unigramCount, bigramCount,
|
||||
0 /* extendedRegionSize */, &headerBuffer)) {
|
||||
if (!headerPolicy->fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */,
|
||||
unigramCount, bigramCount, 0 /* extendedRegionSize */, &headerBuffer)) {
|
||||
return;
|
||||
}
|
||||
dictBuffers.get()->flushHeaderAndDictBuffers(dictDirPath, &headerBuffer);
|
||||
|
|
|
@ -48,8 +48,8 @@ const char *const DictFileWritingUtils::TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE =
|
|||
HeaderPolicy headerPolicy(FormatUtils::VERSION_4, attributeMap);
|
||||
Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers =
|
||||
Ver4DictBuffers::createVer4DictBuffers(&headerPolicy);
|
||||
headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastUpdatedTime */,
|
||||
true /* updatesLastDecayedTime */, 0 /* unigramCount */, 0 /* bigramCount */,
|
||||
headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */,
|
||||
0 /* unigramCount */, 0 /* bigramCount */,
|
||||
0 /* extendedRegionSize */, dictBuffers.get()->getWritableHeaderBuffer());
|
||||
if (!DynamicPtWritingUtils::writeEmptyDictionary(
|
||||
dictBuffers.get()->getWritableTrieBuffer(), 0 /* rootPos */)) {
|
||||
|
|
Loading…
Reference in New Issue