diff options
author | 2013-09-05 12:28:38 +0900 | |
---|---|---|
committer | 2013-09-05 12:28:38 +0900 | |
commit | 5901b5e1bda3b1cee4ecfbfda414468a7bfd0e52 (patch) | |
tree | 4968a52f0a8329b1d46ddd4281baf528ff1cdcd2 /native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp | |
parent | 91486bdb3d1cefc50d0ec8870ec476e60d1f3a7d (diff) | |
download | latinime-5901b5e1bda3b1cee4ecfbfda414468a7bfd0e52.tar.gz latinime-5901b5e1bda3b1cee4ecfbfda414468a7bfd0e52.tar.xz latinime-5901b5e1bda3b1cee4ecfbfda414468a7bfd0e52.zip |
Check usesForgettingCurve in HeaderPolicy.
Bug: 6669677
Change-Id: I47ebfc50f477b2a6514fba6fad421dd90f29ecb1
Diffstat (limited to 'native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp')
-rw-r--r-- | native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp index 439c3de1d..196da5c97 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.cpp @@ -21,6 +21,8 @@ namespace latinime { 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::MULTIPLE_WORD_COST_MULTIPLIER_SCALE = 100.0f; @@ -49,24 +51,47 @@ void HeaderPolicy::readHeaderValueOrQuestionMark(const char *const key, int *out } float HeaderPolicy::readMultipleWordCostMultiplier() const { - std::vector<int> multipleWordsDemotionRateKeyVector; - insertCharactersIntoVector(MULTIPLE_WORDS_DEMOTION_RATE_KEY, - &multipleWordsDemotionRateKeyVector); - HeaderReadingUtils::AttributeMap::const_iterator it = - mAttributeMap.find(multipleWordsDemotionRateKeyVector); - if (it == mAttributeMap.end()) { - // The key was not found. + int attributeValue = 0; + if (getAttributeValueAsInt(MULTIPLE_WORDS_DEMOTION_RATE_KEY, &attributeValue)) { + if (attributeValue <= 0) { + return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); + } + return MULTIPLE_WORD_COST_MULTIPLIER_SCALE / static_cast<float>(attributeValue); + } else { return DEFAULT_MULTIPLE_WORD_COST_MULTIPLIER; } - const int headerValue = parseIntAttributeValue(&(it->second)); - if (headerValue == S_INT_MIN) { - // Invalid value - 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; } - if (headerValue <= 0) { - return static_cast<float>(MAX_VALUE_FOR_WEIGHTING); +} + +// 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()) { + // The key was not found. + return false; } - return MULTIPLE_WORD_COST_MULTIPLIER_SCALE / static_cast<float>(headerValue); + *outValue = parseIntAttributeValue(&(it->second)); + return true; } /* static */ HeaderReadingUtils::AttributeMap HeaderPolicy::createAttributeMapAndReadAllAttributes( |