diff options
author | 2014-11-25 10:34:15 +0000 | |
---|---|---|
committer | 2014-11-25 10:34:15 +0000 | |
commit | 20da4f07be9cdf58835a79e619785b4cafd428ff (patch) | |
tree | 8e19b1d6029a7a8029d3cc472400415f20740371 /native/jni/src/utils/ngram_utils.h | |
parent | b479a56f281d7b20abbb05369a5d6d0a6ce9dc67 (diff) | |
parent | 78212a6d3de2c1fdaa394c58a16cbdee3ad5d046 (diff) | |
download | latinime-20da4f07be9cdf58835a79e619785b4cafd428ff.tar.gz latinime-20da4f07be9cdf58835a79e619785b4cafd428ff.tar.xz latinime-20da4f07be9cdf58835a79e619785b4cafd428ff.zip |
Merge "Use enum to specify ngram type."
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 */ |