Check usesForgettingCurve in HeaderPolicy.
Bug: 6669677 Change-Id: I47ebfc50f477b2a6514fba6fad421dd90f29ecb1main
parent
91486bdb3d
commit
5901b5e1bd
|
@ -21,6 +21,8 @@
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
|
|
||||||
const char *const HeaderPolicy::MULTIPLE_WORDS_DEMOTION_RATE_KEY = "MULTIPLE_WORDS_DEMOTION_RATE";
|
const char *const HeaderPolicy::MULTIPLE_WORDS_DEMOTION_RATE_KEY = "MULTIPLE_WORDS_DEMOTION_RATE";
|
||||||
|
const char *const HeaderPolicy::USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE";
|
||||||
|
const char *const HeaderPolicy::LAST_UPDATED_TIME_KEY = "date";
|
||||||
const float HeaderPolicy::DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER = 1.0f;
|
const float HeaderPolicy::DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER = 1.0f;
|
||||||
const float HeaderPolicy::MULTIPLE_WORD_COST_MULTIPLIER_SCALE = 100.0f;
|
const float HeaderPolicy::MULTIPLE_WORD_COST_MULTIPLIER_SCALE = 100.0f;
|
||||||
|
|
||||||
|
@ -49,24 +51,47 @@ void HeaderPolicy::readHeaderValueOrQuestionMark(const char *const key, int *out
|
||||||
}
|
}
|
||||||
|
|
||||||
float HeaderPolicy::readMultipleWordCostMultiplier() const {
|
float HeaderPolicy::readMultipleWordCostMultiplier() const {
|
||||||
std::vector<int> multipleWordsDemotionRateKeyVector;
|
int attributeValue = 0;
|
||||||
insertCharactersIntoVector(MULTIPLE_WORDS_DEMOTION_RATE_KEY,
|
if (getAttributeValueAsInt(MULTIPLE_WORDS_DEMOTION_RATE_KEY, &attributeValue)) {
|
||||||
&multipleWordsDemotionRateKeyVector);
|
if (attributeValue <= 0) {
|
||||||
HeaderReadingUtils::AttributeMap::const_iterator it =
|
return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
|
||||||
mAttributeMap.find(multipleWordsDemotionRateKeyVector);
|
}
|
||||||
|
return MULTIPLE_WORD_COST_MULTIPLIER_SCALE / static_cast<float>(attributeValue);
|
||||||
|
} else {
|
||||||
|
return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HeaderPolicy::readUsesForgettingCurveFlag() const {
|
||||||
|
int attributeValue = 0;
|
||||||
|
if (getAttributeValueAsInt(USES_FORGETTING_CURVE_KEY, &attributeValue)) {
|
||||||
|
return attributeValue != 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns S_INT_MIN when the key is not found or the value is invalid.
|
||||||
|
int HeaderPolicy::readLastUpdatedTime() const {
|
||||||
|
int attributeValue = 0;
|
||||||
|
if (getAttributeValueAsInt(LAST_UPDATED_TIME_KEY, &attributeValue)) {
|
||||||
|
return attributeValue;
|
||||||
|
} else {
|
||||||
|
return S_INT_MIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns whether the key is found or not and stores the found value into outValue.
|
||||||
|
bool HeaderPolicy::getAttributeValueAsInt(const char *const key, int *const outValue) const {
|
||||||
|
std::vector<int> keyVector;
|
||||||
|
insertCharactersIntoVector(key, &keyVector);
|
||||||
|
HeaderReadingUtils::AttributeMap::const_iterator it = mAttributeMap.find(keyVector);
|
||||||
if (it == mAttributeMap.end()) {
|
if (it == mAttributeMap.end()) {
|
||||||
// The key was not found.
|
// The key was not found.
|
||||||
return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
|
return false;
|
||||||
}
|
}
|
||||||
const int headerValue = parseIntAttributeValue(&(it->second));
|
*outValue = parseIntAttributeValue(&(it->second));
|
||||||
if (headerValue == S_INT_MIN) {
|
return true;
|
||||||
// Invalid value
|
|
||||||
return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
|
|
||||||
}
|
|
||||||
if (headerValue <= 0) {
|
|
||||||
return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
|
|
||||||
}
|
|
||||||
return MULTIPLE_WORD_COST_MULTIPLIER_SCALE / static_cast<float>(headerValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ HeaderReadingUtils::AttributeMap HeaderPolicy::createAttributeMapAndReadAllAttributes(
|
/* static */ HeaderReadingUtils::AttributeMap HeaderPolicy::createAttributeMapAndReadAllAttributes(
|
||||||
|
|
|
@ -32,7 +32,9 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
||||||
: mDictBuf(dictBuf), mDictionaryFlags(HeaderReadingUtils::getFlags(dictBuf)),
|
: mDictBuf(dictBuf), mDictionaryFlags(HeaderReadingUtils::getFlags(dictBuf)),
|
||||||
mSize(HeaderReadingUtils::getHeaderSize(dictBuf)),
|
mSize(HeaderReadingUtils::getHeaderSize(dictBuf)),
|
||||||
mAttributeMap(createAttributeMapAndReadAllAttributes(mDictBuf)),
|
mAttributeMap(createAttributeMapAndReadAllAttributes(mDictBuf)),
|
||||||
mMultiWordCostMultiplier(readMultipleWordCostMultiplier()) {}
|
mMultiWordCostMultiplier(readMultipleWordCostMultiplier()),
|
||||||
|
mUsesForgettingCurve(readUsesForgettingCurveFlag()),
|
||||||
|
mLastUpdatedTime(readLastUpdatedTime()) {}
|
||||||
|
|
||||||
~HeaderPolicy() {}
|
~HeaderPolicy() {}
|
||||||
|
|
||||||
|
@ -57,6 +59,14 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
||||||
return mMultiWordCostMultiplier;
|
return mMultiWordCostMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AK_FORCE_INLINE bool usesForgettingCurve() const {
|
||||||
|
return mUsesForgettingCurve;
|
||||||
|
}
|
||||||
|
|
||||||
|
AK_FORCE_INLINE int getLastUpdatedTime() const {
|
||||||
|
return mLastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
void readHeaderValueOrQuestionMark(const char *const key,
|
void readHeaderValueOrQuestionMark(const char *const key,
|
||||||
int *outValue, int outValueSize) const;
|
int *outValue, int outValueSize) const;
|
||||||
|
|
||||||
|
@ -64,6 +74,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderPolicy);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderPolicy);
|
||||||
|
|
||||||
static const char *const MULTIPLE_WORDS_DEMOTION_RATE_KEY;
|
static const char *const MULTIPLE_WORDS_DEMOTION_RATE_KEY;
|
||||||
|
static const char *const USES_FORGETTING_CURVE_KEY;
|
||||||
|
static const char *const LAST_UPDATED_TIME_KEY;
|
||||||
static const float DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
|
static const float DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER;
|
||||||
static const float MULTIPLE_WORD_COST_MULTIPLIER_SCALE;
|
static const float MULTIPLE_WORD_COST_MULTIPLIER_SCALE;
|
||||||
|
|
||||||
|
@ -72,9 +84,17 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
||||||
const int mSize;
|
const int mSize;
|
||||||
HeaderReadingUtils::AttributeMap mAttributeMap;
|
HeaderReadingUtils::AttributeMap mAttributeMap;
|
||||||
const float mMultiWordCostMultiplier;
|
const float mMultiWordCostMultiplier;
|
||||||
|
const bool mUsesForgettingCurve;
|
||||||
|
const int mLastUpdatedTime;
|
||||||
|
|
||||||
float readMultipleWordCostMultiplier() const;
|
float readMultipleWordCostMultiplier() const;
|
||||||
|
|
||||||
|
bool readUsesForgettingCurveFlag() const;
|
||||||
|
|
||||||
|
int readLastUpdatedTime() const;
|
||||||
|
|
||||||
|
bool getAttributeValueAsInt(const char *const key, int *const outValue) const;
|
||||||
|
|
||||||
static HeaderReadingUtils::AttributeMap createAttributeMapAndReadAllAttributes(
|
static HeaderReadingUtils::AttributeMap createAttributeMapAndReadAllAttributes(
|
||||||
const uint8_t *const dictBuf);
|
const uint8_t *const dictBuf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue