diff options
Diffstat (limited to 'native')
49 files changed, 337 insertions, 225 deletions
diff --git a/native/jni/HostUnitTests.mk b/native/jni/HostUnitTests.mk index 967099a53..572d36564 100644 --- a/native/jni/HostUnitTests.mk +++ b/native/jni/HostUnitTests.mk @@ -29,10 +29,8 @@ LATIN_IME_SRC_DIR := src LOCAL_CFLAGS += -std=c++11 -Wno-unused-parameter -Wno-unused-function LOCAL_CLANG := true LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) -LOCAL_IS_HOST_MODULE := true LOCAL_MODULE := liblatinime_host_static_for_unittests LOCAL_MODULE_TAGS := optional -LOCAL_NDK_STL_VARIANT := c++_static LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES)) include $(BUILD_HOST_STATIC_LIBRARY) @@ -43,10 +41,8 @@ LATIN_IME_TEST_SRC_DIR := tests LOCAL_CFLAGS += -std=c++11 -Wno-unused-parameter -Wno-unused-function LOCAL_CLANG := true LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR) -LOCAL_IS_HOST_MODULE := true LOCAL_MODULE := liblatinime_host_unittests LOCAL_MODULE_TAGS := tests -LOCAL_NDK_STL_VARIANT := c++_static LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES)) LOCAL_STATIC_LIBRARIES += liblatinime_host_static_for_unittests libgtest_host libgtest_main_host include $(BUILD_HOST_NATIVE_TEST) diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk index 3da9d5632..1031903f8 100644 --- a/native/jni/NativeFileList.mk +++ b/native/jni/NativeFileList.mk @@ -32,7 +32,7 @@ LATIN_IME_CORE_SRC_FILES := \ digraph_utils.cpp \ error_type_utils.cpp \ multi_bigram_map.cpp \ - word_property.cpp) \ + property/word_property.cpp) \ $(addprefix suggest/core/layout/, \ additional_proximity_chars.cpp \ proximity_info.cpp \ diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index bf03fdf5c..a10234423 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -24,7 +24,7 @@ #include "jni.h" #include "jni_common.h" #include "suggest/core/dictionary/dictionary.h" -#include "suggest/core/dictionary/word_property.h" +#include "suggest/core/dictionary/property/word_property.h" #include "suggest/core/result/suggestion_results.h" #include "suggest/core/suggest_options.h" #include "suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h" diff --git a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h index 089d4467f..fb76c731f 100644 --- a/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h +++ b/native/jni/src/suggest/core/dicnode/dic_nodes_cache.h @@ -18,7 +18,6 @@ #define LATINIME_DIC_NODES_CACHE_H #include <algorithm> -#include <stdint.h> #include "defines.h" #include "suggest/core/dicnode/dic_node_priority_queue.h" diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_properties.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_properties.h index 6ddb7f1af..11f8c2905 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_properties.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_properties.h @@ -17,7 +17,7 @@ #ifndef LATINIME_DIC_NODE_PROPERTIES_H #define LATINIME_DIC_NODE_PROPERTIES_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h index ea48de1ea..69a886f55 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h @@ -18,8 +18,8 @@ #define LATINIME_DIC_NODE_STATE_OUTPUT_H #include <algorithm> +#include <cstdint> #include <cstring> // for memmove() -#include <stdint.h> #include "defines.h" diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h index f164edbee..c19d48eb9 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_scoring.h @@ -18,7 +18,7 @@ #define LATINIME_DIC_NODE_STATE_SCORING_H #include <algorithm> -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/core/dictionary/digraph_utils.h" diff --git a/native/jni/src/suggest/core/dictionary/bloom_filter.h b/native/jni/src/suggest/core/dictionary/bloom_filter.h index e22c3ae5c..85b8fc397 100644 --- a/native/jni/src/suggest/core/dictionary/bloom_filter.h +++ b/native/jni/src/suggest/core/dictionary/bloom_filter.h @@ -17,8 +17,8 @@ #ifndef LATINIME_BLOOM_FILTER_H #define LATINIME_BLOOM_FILTER_H +#include <cstdint> #include <cstring> -#include <stdint.h> #include "defines.h" diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index ef7a0a8fe..8445da310 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -18,8 +18,6 @@ #include "suggest/core/dictionary/dictionary.h" -#include <stdint.h> - #include "defines.h" #include "suggest/core/policy/dictionary_header_structure_policy.h" #include "suggest/core/result/suggestion_results.h" diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h index cd983b032..6b7756565 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.h +++ b/native/jni/src/suggest/core/dictionary/dictionary.h @@ -17,13 +17,12 @@ #ifndef LATINIME_DICTIONARY_H #define LATINIME_DICTIONARY_H -#include <stdint.h> #include <memory> #include "defines.h" #include "jni.h" #include "suggest/core/dictionary/bigram_dictionary.h" -#include "suggest/core/dictionary/word_property.h" +#include "suggest/core/dictionary/property/word_property.h" #include "suggest/core/policy/dictionary_header_structure_policy.h" #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h" #include "suggest/core/suggest_interface.h" diff --git a/native/jni/src/suggest/core/dictionary/error_type_utils.h b/native/jni/src/suggest/core/dictionary/error_type_utils.h index cc7786765..0e8e5b635 100644 --- a/native/jni/src/suggest/core/dictionary/error_type_utils.h +++ b/native/jni/src/suggest/core/dictionary/error_type_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_ERROR_TYPE_UTILS_H #define LATINIME_ERROR_TYPE_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/core/dictionary/property/bigram_property.h b/native/jni/src/suggest/core/dictionary/property/bigram_property.h new file mode 100644 index 000000000..8d3429b5b --- /dev/null +++ b/native/jni/src/suggest/core/dictionary/property/bigram_property.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_BIGRAM_PROPERTY_H +#define LATINIME_BIGRAM_PROPERTY_H + +#include <vector> + +#include "defines.h" + +namespace latinime { + +class BigramProperty { + public: + BigramProperty(const std::vector<int> *const targetCodePoints, + const int probability, const int timestamp, const int level, const int count) + : mTargetCodePoints(*targetCodePoints), mProbability(probability), + mTimestamp(timestamp), mLevel(level), mCount(count) {} + + const std::vector<int> *getTargetCodePoints() const { + return &mTargetCodePoints; + } + + int getProbability() const { + return mProbability; + } + + int getTimestamp() const { + return mTimestamp; + } + + int getLevel() const { + return mLevel; + } + + int getCount() const { + return mCount; + } + + private: + // Default copy constructor and assign operator are used for using in std::vector. + DISALLOW_DEFAULT_CONSTRUCTOR(BigramProperty); + + // TODO: Make members const. + std::vector<int> mTargetCodePoints; + int mProbability; + int mTimestamp; + int mLevel; + int mCount; +}; +} // namespace latinime +#endif // LATINIME_WORD_PROPERTY_H diff --git a/native/jni/src/suggest/core/dictionary/property/unigram_property.h b/native/jni/src/suggest/core/dictionary/property/unigram_property.h new file mode 100644 index 000000000..d2551057b --- /dev/null +++ b/native/jni/src/suggest/core/dictionary/property/unigram_property.h @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_UNIGRAM_PROPERTY_H +#define LATINIME_UNIGRAM_PROPERTY_H + +#include <vector> + +#include "defines.h" + +namespace latinime { + +class UnigramProperty { + public: + class ShortcutProperty { + public: + ShortcutProperty(const std::vector<int> *const targetCodePoints, const int probability) + : mTargetCodePoints(*targetCodePoints), mProbability(probability) {} + + const std::vector<int> *getTargetCodePoints() const { + return &mTargetCodePoints; + } + + int getProbability() const { + return mProbability; + } + + private: + // Default copy constructor and assign operator are used for using in std::vector. + DISALLOW_DEFAULT_CONSTRUCTOR(ShortcutProperty); + + // TODO: Make members const. + std::vector<int> mTargetCodePoints; + int mProbability; + }; + + UnigramProperty() + : mIsNotAWord(false), mIsBlacklisted(false), mProbability(NOT_A_PROBABILITY), + mTimestamp(NOT_A_TIMESTAMP), mLevel(0), mCount(0), mShortcuts() {} + + UnigramProperty(const bool isNotAWord, const bool isBlacklisted, const int probability, + const int timestamp, const int level, const int count, + const std::vector<ShortcutProperty> *const shortcuts) + : mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), mProbability(probability), + mTimestamp(timestamp), mLevel(level), mCount(count), mShortcuts(*shortcuts) {} + + bool isNotAWord() const { + return mIsNotAWord; + } + + bool isBlacklisted() const { + return mIsBlacklisted; + } + + bool hasShortcuts() const { + return !mShortcuts.empty(); + } + + int getProbability() const { + return mProbability; + } + + int getTimestamp() const { + return mTimestamp; + } + + int getLevel() const { + return mLevel; + } + + int getCount() const { + return mCount; + } + + const std::vector<ShortcutProperty> &getShortcuts() const { + return mShortcuts; + } + + private: + // Default copy constructor is used for using as a return value. + DISALLOW_ASSIGNMENT_OPERATOR(UnigramProperty); + + // TODO: Make members const. + bool mIsNotAWord; + bool mIsBlacklisted; + int mProbability; + // Historical information + int mTimestamp; + int mLevel; + int mCount; + std::vector<ShortcutProperty> mShortcuts; +}; +} // namespace latinime +#endif // LATINIME_UNIGRAM_PROPERTY_H diff --git a/native/jni/src/suggest/core/dictionary/word_property.cpp b/native/jni/src/suggest/core/dictionary/property/word_property.cpp index 473311842..95608dcf8 100644 --- a/native/jni/src/suggest/core/dictionary/word_property.cpp +++ b/native/jni/src/suggest/core/dictionary/property/word_property.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "suggest/core/dictionary/word_property.h" +#include "suggest/core/dictionary/property/word_property.h" namespace latinime { @@ -23,9 +23,12 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, jobject outBigramProbabilities, jobject outShortcutTargets, jobject outShortcutProbabilities) const { env->SetIntArrayRegion(outCodePoints, 0 /* start */, mCodePoints.size(), &mCodePoints[0]); - jboolean flags[] = {mIsNotAWord, mIsBlacklisted, mHasBigrams, mHasShortcuts}; + + jboolean flags[] = {mUnigramProperty.isNotAWord(), mUnigramProperty.isBlacklisted(), + !mBigrams.empty(), mUnigramProperty.hasShortcuts()}; env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags); - int probabilityInfo[] = {mProbability, mTimestamp, mLevel, mCount}; + int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(), + mUnigramProperty.getLevel(), mUnigramProperty.getCount()}; env->SetIntArrayRegion(outProbabilityInfo, 0 /* start */, NELEMS(probabilityInfo), probabilityInfo); @@ -35,19 +38,17 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); // Output bigrams. - const int bigramCount = mBigrams.size(); - for (int i = 0; i < bigramCount; ++i) { - const BigramProperty *const bigramProperty = &mBigrams[i]; - const std::vector<int> *const word1CodePoints = bigramProperty->getTargetCodePoints(); + for (const auto &bigramProperty : mBigrams) { + const std::vector<int> *const word1CodePoints = bigramProperty.getTargetCodePoints(); jintArray bigramWord1CodePointArray = env->NewIntArray(word1CodePoints->size()); env->SetIntArrayRegion(bigramWord1CodePointArray, 0 /* start */, - word1CodePoints->size(), &word1CodePoints->at(0)); + word1CodePoints->size(), word1CodePoints->data()); env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray); env->DeleteLocalRef(bigramWord1CodePointArray); - int bigramProbabilityInfo[] = {bigramProperty->getProbability(), - bigramProperty->getTimestamp(), bigramProperty->getLevel(), - bigramProperty->getCount()}; + int bigramProbabilityInfo[] = {bigramProperty.getProbability(), + bigramProperty.getTimestamp(), bigramProperty.getLevel(), + bigramProperty.getCount()}; jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo)); env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */, NELEMS(bigramProbabilityInfo), bigramProbabilityInfo); @@ -56,16 +57,15 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints, } // Output shortcuts. - const int shortcutTargetCount = mShortcuts.size(); - for (int i = 0; i < shortcutTargetCount; ++i) { - const std::vector<int> *const targetCodePoints = mShortcuts[i].getTargetCodePoints(); + for (const auto &shortcut : mUnigramProperty.getShortcuts()) { + const std::vector<int> *const targetCodePoints = shortcut.getTargetCodePoints(); jintArray shortcutTargetCodePointArray = env->NewIntArray(targetCodePoints->size()); env->SetIntArrayRegion(shortcutTargetCodePointArray, 0 /* start */, - targetCodePoints->size(), &targetCodePoints->at(0)); + targetCodePoints->size(), targetCodePoints->data()); env->CallBooleanMethod(outShortcutTargets, addMethodId, shortcutTargetCodePointArray); env->DeleteLocalRef(shortcutTargetCodePointArray); jobject integerProbability = env->NewObject(integerClass, intToIntegerConstructorId, - mShortcuts[i].getProbability()); + shortcut.getProbability()); env->CallBooleanMethod(outShortcutProbabilities, addMethodId, integerProbability); env->DeleteLocalRef(integerProbability); } diff --git a/native/jni/src/suggest/core/dictionary/property/word_property.h b/native/jni/src/suggest/core/dictionary/property/word_property.h new file mode 100644 index 000000000..5519a917c --- /dev/null +++ b/native/jni/src/suggest/core/dictionary/property/word_property.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_WORD_PROPERTY_H +#define LATINIME_WORD_PROPERTY_H + +#include <vector> + +#include "defines.h" +#include "jni.h" +#include "suggest/core/dictionary/property/bigram_property.h" +#include "suggest/core/dictionary/property/unigram_property.h" + +namespace latinime { + +// This class is used for returning information belonging to a word to java side. +class WordProperty { + public: + // Default constructor is used to create an instance that indicates an invalid word. + WordProperty() + : mCodePoints(), mUnigramProperty(), mBigrams() {} + + WordProperty(const std::vector<int> *const codePoints, + const UnigramProperty *const unigramProperty, + const std::vector<BigramProperty> *const bigrams) + : mCodePoints(*codePoints), mUnigramProperty(*unigramProperty), mBigrams(*bigrams) {} + + void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags, + jintArray outProbabilityInfo, jobject outBigramTargets, jobject outBigramProbabilities, + jobject outShortcutTargets, jobject outShortcutProbabilities) const; + + private: + // Default copy constructor is used for using as a return value. + DISALLOW_ASSIGNMENT_OPERATOR(WordProperty); + + const std::vector<int> mCodePoints; + const UnigramProperty mUnigramProperty; + const std::vector<BigramProperty> mBigrams; +}; +} // namespace latinime +#endif // LATINIME_WORD_PROPERTY_H diff --git a/native/jni/src/suggest/core/dictionary/word_property.h b/native/jni/src/suggest/core/dictionary/word_property.h deleted file mode 100644 index 40b1a91a4..000000000 --- a/native/jni/src/suggest/core/dictionary/word_property.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LATINIME_WORD_PROPERTY_H -#define LATINIME_WORD_PROPERTY_H - -#include <cstring> -#include <vector> - -#include "defines.h" -#include "jni.h" - -namespace latinime { - -// This class is used for returning information belonging to a word to java side. -class WordProperty { - public: - class BigramProperty { - public: - BigramProperty(const std::vector<int> *const targetCodePoints, - const int probability, const int timestamp, const int level, const int count) - : mTargetCodePoints(*targetCodePoints), mProbability(probability), - mTimestamp(timestamp), mLevel(level), mCount(count) {} - - const std::vector<int> *getTargetCodePoints() const { - return &mTargetCodePoints; - } - - int getProbability() const { - return mProbability; - } - - int getTimestamp() const { - return mTimestamp; - } - - int getLevel() const { - return mLevel; - } - - int getCount() const { - return mCount; - } - - private: - std::vector<int> mTargetCodePoints; - int mProbability; - int mTimestamp; - int mLevel; - int mCount; - }; - - class ShortcutProperty { - public: - ShortcutProperty(const std::vector<int> *const targetCodePoints, const int probability) - : mTargetCodePoints(*targetCodePoints), mProbability(probability) {} - - const std::vector<int> *getTargetCodePoints() const { - return &mTargetCodePoints; - } - - int getProbability() const { - return mProbability; - } - - private: - std::vector<int> mTargetCodePoints; - int mProbability; - }; - - // Invalid word. - WordProperty() - : mCodePoints(), mIsNotAWord(false), mIsBlacklisted(false), - mHasBigrams(false), mHasShortcuts(false), mProbability(NOT_A_PROBABILITY), - mTimestamp(0), mLevel(0), mCount(0), mBigrams(), mShortcuts() {} - - WordProperty(const std::vector<int> *const codePoints, - const bool isNotAWord, const bool isBlacklisted, const bool hasBigrams, - const bool hasShortcuts, const int probability, const int timestamp, - const int level, const int count, const std::vector<BigramProperty> *const bigrams, - const std::vector<ShortcutProperty> *const shortcuts) - : mCodePoints(*codePoints), mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), - mHasBigrams(hasBigrams), mHasShortcuts(hasShortcuts), mProbability(probability), - mTimestamp(timestamp), mLevel(level), mCount(count), mBigrams(*bigrams), - mShortcuts(*shortcuts) {} - - void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags, - jintArray outProbabilityInfo, jobject outBigramTargets, jobject outBigramProbabilities, - jobject outShortcutTargets, jobject outShortcutProbabilities) const; - - private: - DISALLOW_ASSIGNMENT_OPERATOR(WordProperty); - - std::vector<int> mCodePoints; - bool mIsNotAWord; - bool mIsBlacklisted; - bool mHasBigrams; - bool mHasShortcuts; - int mProbability; - // Historical information - int mTimestamp; - int mLevel; - int mCount; - std::vector<BigramProperty> mBigrams; - std::vector<ShortcutProperty> mShortcuts; -}; -} // namespace latinime -#endif // LATINIME_WORD_PROPERTY_H diff --git a/native/jni/src/suggest/core/layout/normal_distribution.h b/native/jni/src/suggest/core/layout/normal_distribution.h new file mode 100644 index 000000000..5f21a59c0 --- /dev/null +++ b/native/jni/src/suggest/core/layout/normal_distribution.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LATINIME_NORMAL_DISTRIBUTION_H +#define LATINIME_NORMAL_DISTRIBUTION_H + +#include <cmath> + +#include "defines.h" + +namespace latinime { + +// Normal distribution N(u, sigma^2). +class NormalDistribution { + public: + NormalDistribution(const float u, const float sigma) + : mU(u), + mPreComputedNonExpPart(1.0f / sqrtf(2.0f * M_PI_F + * GeometryUtils::SQUARE_FLOAT(sigma))), + mPreComputedExponentPart(-1.0f / (2.0f * GeometryUtils::SQUARE_FLOAT(sigma))) {} + + float getProbabilityDensity(const float x) const { + const float shiftedX = x - mU; + return mPreComputedNonExpPart + * expf(mPreComputedExponentPart * GeometryUtils::SQUARE_FLOAT(shiftedX)); + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(NormalDistribution); + + const float mU; // mean value + const float mPreComputedNonExpPart; // = 1 / sqrt(2 * PI * sigma^2) + const float mPreComputedExponentPart; // = -1 / (2 * sigma^2) +}; +} // namespace latinime +#endif // LATINIME_NORMAL_DISTRIBUTION_H diff --git a/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp b/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp index 867f59843..5a3ff7384 100644 --- a/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp +++ b/native/jni/src/suggest/core/layout/proximity_info_state_utils.cpp @@ -24,6 +24,7 @@ #include "defines.h" #include "suggest/core/layout/geometry_utils.h" +#include "suggest/core/layout/normal_distribution.h" #include "suggest/core/layout/proximity_info.h" #include "suggest/core/layout/proximity_info_params.h" @@ -717,8 +718,8 @@ namespace latinime { const float sigma = speedxAngleRate + speedxNearestKeyDistanceRate + ProximityInfoParams::MIN_STANDARD_DEVIATION; - ProximityInfoUtils::NormalDistribution - distribution(ProximityInfoParams::CENTER_VALUE_OF_NORMALIZED_DISTRIBUTION, sigma); + NormalDistribution distribution( + ProximityInfoParams::CENTER_VALUE_OF_NORMALIZED_DISTRIBUTION, sigma); // Summing up probability densities of all near keys. float sumOfProbabilityDensities = 0.0f; for (int j = 0; j < keyCount; ++j) { diff --git a/native/jni/src/suggest/core/layout/proximity_info_utils.h b/native/jni/src/suggest/core/layout/proximity_info_utils.h index 310bbdb62..c273ef456 100644 --- a/native/jni/src/suggest/core/layout/proximity_info_utils.h +++ b/native/jni/src/suggest/core/layout/proximity_info_utils.h @@ -125,28 +125,6 @@ class ProximityInfoUtils { return type == MATCH_CHAR || type == PROXIMITY_CHAR || type == ADDITIONAL_PROXIMITY_CHAR; } - // Normal distribution N(u, sigma^2). - struct NormalDistribution { - public: - NormalDistribution(const float u, const float sigma) - : mU(u), - mPreComputedNonExpPart(1.0f / sqrtf(2.0f * M_PI_F - * GeometryUtils::SQUARE_FLOAT(sigma))), - mPreComputedExponentPart(-1.0f / (2.0f * GeometryUtils::SQUARE_FLOAT(sigma))) {} - - float getProbabilityDensity(const float x) const { - const float shiftedX = x - mU; - return mPreComputedNonExpPart - * expf(mPreComputedExponentPart * GeometryUtils::SQUARE_FLOAT(shiftedX)); - } - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(NormalDistribution); - const float mU; // mean value - const float mPreComputedNonExpPart; // = 1 / sqrt(2 * PI * sigma^2) - const float mPreComputedExponentPart; // = -1 / (2 * sigma^2) - }; // struct NormalDistribution - private: DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfoUtils); diff --git a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h index b6dc7d006..ae2e7a8fe 100644 --- a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h +++ b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h @@ -20,7 +20,7 @@ #include <memory> #include "defines.h" -#include "suggest/core/dictionary/word_property.h" +#include "suggest/core/dictionary/property/word_property.h" namespace latinime { diff --git a/native/jni/src/suggest/core/session/dic_traverse_session.h b/native/jni/src/suggest/core/session/dic_traverse_session.h index 9e5d902dd..843ca85a0 100644 --- a/native/jni/src/suggest/core/session/dic_traverse_session.h +++ b/native/jni/src/suggest/core/session/dic_traverse_session.h @@ -17,7 +17,6 @@ #ifndef LATINIME_DIC_TRAVERSE_SESSION_H #define LATINIME_DIC_TRAVERSE_SESSION_H -#include <stdint.h> #include <vector> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_policy.h b/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_policy.h index 6ff95cac4..a898e2afc 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_policy.h @@ -17,7 +17,7 @@ #ifndef LATINIME_BIGRAM_LIST_POLICY_H #define LATINIME_BIGRAM_LIST_POLICY_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/core/policy/dictionary_bigrams_structure_policy.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.h b/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.h index 7e1038300..15f924a6a 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/bigram/bigram_list_read_write_utils.h @@ -17,8 +17,8 @@ #ifndef LATINIME_BIGRAM_LIST_READ_WRITE_UTILS_H #define LATINIME_BIGRAM_LIST_READ_WRITE_UTILS_H +#include <cstdint> #include <cstdlib> -#include <stdint.h> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h index 66824245e..f950cade3 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_policy.h @@ -17,7 +17,7 @@ #ifndef LATINIME_HEADER_POLICY_H #define LATINIME_HEADER_POLICY_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/core/policy/dictionary_header_structure_policy.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h index 4185a2e7c..a6b4c4e14 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_HEADER_READ_WRITE_UTILS_H #define LATINIME_HEADER_READ_WRITE_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/core/policy/dictionary_header_structure_policy.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_policy.h b/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_policy.h index d73f73953..6d2b4778c 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_policy.h @@ -17,7 +17,7 @@ #ifndef LATINIME_SHORTCUT_LIST_POLICY_H #define LATINIME_SHORTCUT_LIST_POLICY_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/core/policy/dictionary_shortcuts_structure_policy.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h b/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h index a83ed5a50..d065bf7fd 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_SHORTCUT_LIST_READING_UTILS_H #define LATINIME_SHORTCUT_LIST_READING_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/shortcut/ver4_shortcut_list_policy.h b/native/jni/src/suggest/policyimpl/dictionary/shortcut/ver4_shortcut_list_policy.h index f2fa5b75b..fe984615c 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/shortcut/ver4_shortcut_list_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/shortcut/ver4_shortcut_list_policy.h @@ -17,8 +17,6 @@ #ifndef LATINIME_VER4_SHORTCUT_LIST_POLICY_H #define LATINIME_VER4_SHORTCUT_LIST_POLICY_H -#include <stdint.h> - #include "defines.h" #include "suggest/core/policy/dictionary_shortcuts_structure_policy.h" #include "suggest/policyimpl/dictionary/shortcut/shortcut_list_reading_utils.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp index 79bcf6fa4..5f19534e2 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp @@ -17,7 +17,6 @@ #include "suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h" #include <climits> -#include <stdint.h> #include "defines.h" #include "suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h index 9454ddf33..6053b7ed3 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h @@ -17,8 +17,6 @@ #ifndef LATINIME_DICTIONARY_STRUCTURE_WITH_BUFFER_POLICY_FACTORY_H #define LATINIME_DICTIONARY_STRUCTURE_WITH_BUFFER_POLICY_FACTORY_H -#include <stdint.h> - #include "defines.h" #include "suggest/core/policy/dictionary_structure_with_buffer_policy.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_utils.h b/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_utils.h index 89ae12c0b..b13a075d5 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_DYNAMIC_PT_READING_UTILS_H #define LATINIME_DYNAMIC_PT_READING_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_updating_helper.h b/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_updating_helper.h index 71f473096..f703baf85 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_updating_helper.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_updating_helper.h @@ -17,8 +17,6 @@ #ifndef LATINIME_DYNAMIC_PT_UPDATING_HELPER_H #define LATINIME_DYNAMIC_PT_UPDATING_HELPER_H -#include <stdint.h> - #include "defines.h" #include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h" #include "utils/hash_map_compat.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp index ebbdc2ea2..664aeebbb 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp @@ -17,8 +17,8 @@ #include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_writing_utils.h" #include <cstddef> +#include <cstdint> #include <cstdlib> -#include <stdint.h> #include "suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp index 4e795f82c..b426dbf28 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp @@ -339,7 +339,7 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin std::vector<int> codePointVector(ptNodeParams.getCodePoints(), ptNodeParams.getCodePoints() + ptNodeParams.getCodePointCount()); // Fetch bigram information. - std::vector<WordProperty::BigramProperty> bigrams; + std::vector<BigramProperty> bigrams; const int bigramListPos = getBigramsPositionOfPtNode(ptNodePos); int bigramWord1CodePoints[MAX_WORD_LENGTH]; BinaryDictionaryBigramsIterator bigramsIt(getBigramsStructurePolicy(), bigramListPos); @@ -360,7 +360,7 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin } } // Fetch shortcut information. - std::vector<WordProperty::ShortcutProperty> shortcuts; + std::vector<UnigramProperty::ShortcutProperty> shortcuts; int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); if (shortcutPos != NOT_A_DICT_POS) { int shortcutTargetCodePoints[MAX_WORD_LENGTH]; @@ -379,11 +379,10 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin shortcuts.emplace_back(&shortcutTarget, shortcutProbability); } } - return WordProperty(&codePointVector, ptNodeParams.isNotAWord(), - ptNodeParams.isBlacklisted(), ptNodeParams.hasBigrams(), - ptNodeParams.hasShortcutTargets(), ptNodeParams.getProbability(), - NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */, - &bigrams, &shortcuts); + const UnigramProperty unigramProperty(ptNodeParams.isNotAWord(), + ptNodeParams.isBlacklisted(), ptNodeParams.getProbability(), + NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */, &shortcuts); + return WordProperty(&codePointVector, &unigramProperty, &bigrams); } int PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints) { diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h index 11a40de55..79500b9fa 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.h @@ -17,7 +17,7 @@ #ifndef LATINIME_PATRICIA_TRIE_POLICY_H #define LATINIME_PATRICIA_TRIE_POLICY_H -#include <stdint.h> +#include <cstdint> #include <vector> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_reading_utils.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_reading_utils.h index fa1430ce6..a6090a513 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_reading_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_reading_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_PATRICIA_TRIE_READING_UTILS_H #define LATINIME_PATRICIA_TRIE_READING_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h index dd1a0da51..86fc89c5e 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_patricia_trie_node_reader.h @@ -17,7 +17,7 @@ #ifndef LATINIME_VER2_PATRICIA_TRIE_NODE_READER_H #define LATINIME_VER2_PATRICIA_TRIE_NODE_READER_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_pt_node_array_reader.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_pt_node_array_reader.h index 77404adf8..548272148 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_pt_node_array_reader.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/ver2_pt_node_array_reader.h @@ -17,7 +17,7 @@ #ifndef LATINIME_VER2_PT_NODE_ARRAY_READER_H #define LATINIME_VER2_PT_NODE_ARRAY_READER_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_array_reader.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h index 1db9ea026..f24307e7b 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h @@ -17,8 +17,6 @@ #ifndef LATINIME_VER4_PATRICIA_TRIE_NODE_READER_H #define LATINIME_VER4_PATRICIA_TRIE_NODE_READER_H -#include <stdint.h> - #include "defines.h" #include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h" #include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_reader.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.h index f01b3af0e..b2b0504a1 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_writer.h @@ -17,8 +17,6 @@ #ifndef LATINIME_VER4_PATRICIA_TRIE_NODE_WRITER_H #define LATINIME_VER4_PATRICIA_TRIE_NODE_WRITER_H -#include <stdint.h> - #include "defines.h" #include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h" #include "suggest/policyimpl/dictionary/structure/pt_common/pt_node_params.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp index 107ddab2c..6cf8409dc 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp @@ -20,7 +20,9 @@ #include "suggest/core/dicnode/dic_node.h" #include "suggest/core/dicnode/dic_node_vector.h" -#include "suggest/core/dictionary/word_property.h" +#include "suggest/core/dictionary/property/bigram_property.h" +#include "suggest/core/dictionary/property/unigram_property.h" +#include "suggest/core/dictionary/property/word_property.h" #include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h" #include "suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h" #include "suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h" @@ -358,7 +360,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code ptNodeParams.getTerminalId()); const HistoricalInfo *const historicalInfo = probabilityEntry.getHistoricalInfo(); // Fetch bigram information. - std::vector<WordProperty::BigramProperty> bigrams; + std::vector<BigramProperty> bigrams; const int bigramListPos = getBigramsPositionOfPtNode(ptNodePos); if (bigramListPos != NOT_A_DICT_POS) { int bigramWord1CodePoints[MAX_WORD_LENGTH]; @@ -395,7 +397,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code } } // Fetch shortcut information. - std::vector<WordProperty::ShortcutProperty> shortcuts; + std::vector<UnigramProperty::ShortcutProperty> shortcuts; int shortcutPos = getShortcutPositionOfPtNode(ptNodePos); if (shortcutPos != NOT_A_DICT_POS) { int shortcutTarget[MAX_WORD_LENGTH]; @@ -411,11 +413,11 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code shortcuts.emplace_back(&target, shortcutProbability); } } - return WordProperty(&codePointVector, ptNodeParams.isNotAWord(), - ptNodeParams.isBlacklisted(), ptNodeParams.hasBigrams(), - ptNodeParams.hasShortcutTargets(), ptNodeParams.getProbability(), + const UnigramProperty unigramProperty(ptNodeParams.isNotAWord(), + ptNodeParams.isBlacklisted(), ptNodeParams.getProbability(), historicalInfo->getTimeStamp(), historicalInfo->getLevel(), - historicalInfo->getCount(), &bigrams, &shortcuts); + historicalInfo->getCount(), &shortcuts); + return WordProperty(&codePointVector, &unigramProperty, &bigrams); } int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints) { diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_reading_utils.h b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_reading_utils.h index e418c4933..466ff55d5 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_reading_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_reading_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_VER4_PATRICIA_TRIE_READING_UTILS_H #define LATINIME_VER4_PATRICIA_TRIE_READING_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h b/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h index 76be16518..23cbe3aa3 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h @@ -18,7 +18,7 @@ #define LATINIME_BUFFER_WITH_EXTENDABLE_BUFFER_H #include <cstddef> -#include <stdint.h> +#include <cstdint> #include <vector> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/byte_array_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/byte_array_utils.h index ebdd523e1..c0a9fcb1d 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/byte_array_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/byte_array_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_BYTE_ARRAY_UTILS_H #define LATINIME_BYTE_ARRAY_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h index 7c6a21dd7..759b1c9b2 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/format_utils.h @@ -17,7 +17,7 @@ #ifndef LATINIME_FORMAT_UTILS_H #define LATINIME_FORMAT_UTILS_H -#include <stdint.h> +#include <cstdint> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/mmapped_buffer.h b/native/jni/src/suggest/policyimpl/dictionary/utils/mmapped_buffer.h index f73716c8e..8460087ab 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/mmapped_buffer.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/mmapped_buffer.h @@ -17,8 +17,8 @@ #ifndef LATINIME_MMAPPED_BUFFER_H #define LATINIME_MMAPPED_BUFFER_H +#include <cstdint> #include <memory> -#include <stdint.h> #include "defines.h" diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h index 14fdf53cb..3b339e61a 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h @@ -17,8 +17,6 @@ #ifndef LATINIME_PROBABILITY_UTILS_H #define LATINIME_PROBABILITY_UTILS_H -#include <stdint.h> - #include "defines.h" namespace latinime { diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.h b/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.h index 21c167506..fca8120f1 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.h +++ b/native/jni/src/suggest/policyimpl/dictionary/utils/sparse_table.h @@ -17,7 +17,7 @@ #ifndef LATINIME_SPARSE_TABLE_H #define LATINIME_SPARSE_TABLE_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h" diff --git a/native/jni/src/suggest/policyimpl/typing/typing_traversal.h b/native/jni/src/suggest/policyimpl/typing/typing_traversal.h index 7c86b7dc9..5ba8bfa01 100644 --- a/native/jni/src/suggest/policyimpl/typing/typing_traversal.h +++ b/native/jni/src/suggest/policyimpl/typing/typing_traversal.h @@ -17,7 +17,7 @@ #ifndef LATINIME_TYPING_TRAVERSAL_H #define LATINIME_TYPING_TRAVERSAL_H -#include <stdint.h> +#include <cstdint> #include "defines.h" #include "suggest/core/dicnode/dic_node.h" |