diff options
author | 2014-11-20 15:27:30 +0900 | |
---|---|---|
committer | 2014-11-25 19:07:10 +0900 | |
commit | 78212a6d3de2c1fdaa394c58a16cbdee3ad5d046 (patch) | |
tree | ba9eaa5eb0f14c444b922b5cd380e15bf442f759 /native/jni/src/utils/ngram_utils.h | |
parent | a94733cbca5bc3544fa73fa1649bbb1dadf31356 (diff) | |
download | latinime-78212a6d3de2c1fdaa394c58a16cbdee3ad5d046.tar.gz latinime-78212a6d3de2c1fdaa394c58a16cbdee3ad5d046.tar.xz latinime-78212a6d3de2c1fdaa394c58a16cbdee3ad5d046.zip |
Use enum to specify ngram type.
Change-Id: Ie28768ceadcd7a2d940c57eb30be7d4c364e509f
Diffstat (limited to 'native/jni/src/utils/ngram_utils.h')
-rw-r--r-- | native/jni/src/utils/ngram_utils.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/native/jni/src/utils/ngram_utils.h b/native/jni/src/utils/ngram_utils.h new file mode 100644 index 000000000..6227812d4 --- /dev/null +++ b/native/jni/src/utils/ngram_utils.h @@ -0,0 +1,62 @@ +/* + * 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_NGRAM_UTILS_H +#define LATINIME_NGRAM_UTILS_H + +#include "defines.h" + +namespace latinime { + +enum class NgramType : int { + Unigram = 0, + Bigram = 1, + Trigram = 2, + NotANgramType = -1, +}; + +namespace AllNgramTypes { +// Use anonymous namespace to avoid ODR (One Definition Rule) violation. +namespace { + +const NgramType ASCENDING[] = { + NgramType::Unigram, NgramType::Bigram, NgramType::Trigram +}; + +const NgramType DESCENDING[] = { + NgramType::Trigram, NgramType::Bigram, NgramType::Unigram +}; + +} // namespace +} // namespace AllNgramTypes + +class NgramUtils final { + public: + static AK_FORCE_INLINE NgramType getNgramTypeFromWordCount(const int wordCount) { + // Max supported ngram is (MAX_PREV_WORD_COUNT_FOR_N_GRAM + 1)-gram. + if (wordCount <= 0 || wordCount > MAX_PREV_WORD_COUNT_FOR_N_GRAM + 1) { + return NgramType::NotANgramType; + } + // Convert word count to 0-origin enum value. + return static_cast<NgramType>(wordCount - 1); + } + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(NgramUtils); + +}; +} +#endif /* LATINIME_NGRAM_UTILS_H */ |