satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 1 | /* |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 2 | * Copyright (C) 2010, The Android Open Source Project |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 16 | |
Ken Wakasa | f1008c5 | 2012-07-31 17:56:40 +0900 | [diff] [blame] | 17 | #include <cstring> |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 18 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 19 | #define LOG_TAG "LatinIME: bigram_dictionary.cpp" |
| 20 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 21 | #include "bigram_dictionary.h" |
Ken Wakasa | a65c267 | 2013-05-31 00:02:57 +0900 | [diff] [blame] | 22 | |
Ken Wakasa | 3b088a2 | 2012-05-16 23:05:32 +0900 | [diff] [blame] | 23 | #include "defines.h" |
Ken Wakasa | a65c267 | 2013-05-31 00:02:57 +0900 | [diff] [blame] | 24 | #include "suggest/core/dictionary/binary_format.h" |
| 25 | #include "suggest/core/dictionary/bloom_filter.h" |
Ken Wakasa | 464d3ba | 2013-05-31 20:25:10 +0900 | [diff] [blame] | 26 | #include "suggest/core/dictionary/char_utils.h" |
Ken Wakasa | a65c267 | 2013-05-31 00:02:57 +0900 | [diff] [blame] | 27 | #include "suggest/core/dictionary/dictionary.h" |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 28 | |
| 29 | namespace latinime { |
| 30 | |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 31 | BigramDictionary::BigramDictionary(const uint8_t *const streamStart) : DICT_ROOT(streamStart) { |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 32 | if (DEBUG_DICT) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 33 | AKLOGI("BigramDictionary - constructor"); |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 34 | } |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 35 | } |
| 36 | |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 37 | BigramDictionary::~BigramDictionary() { |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 38 | } |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 39 | |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 40 | void BigramDictionary::addWordBigram(int *word, int length, int probability, int *bigramProbability, |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 41 | int *bigramCodePoints, int *outputTypes) const { |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 42 | word[length] = 0; |
Satoshi Kataoka | e320789 | 2013-04-08 17:33:32 +0900 | [diff] [blame] | 43 | if (DEBUG_DICT_FULL) { |
Doug Kwan | ce9efbf | 2011-07-07 22:53:50 -0700 | [diff] [blame] | 44 | #ifdef FLAG_DBG |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 45 | char s[length + 1]; |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 46 | for (int i = 0; i <= length; i++) s[i] = static_cast<char>(word[i]); |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 47 | AKLOGI("Bigram: Found word = %s, freq = %d :", s, probability); |
satok | 787945b | 2011-07-14 08:32:57 +0900 | [diff] [blame] | 48 | #endif |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Find the right insertion point |
| 52 | int insertAt = 0; |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 53 | while (insertAt < MAX_RESULTS) { |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 54 | if (probability > bigramProbability[insertAt] || (bigramProbability[insertAt] == probability |
Ken Wakasa | 464d3ba | 2013-05-31 20:25:10 +0900 | [diff] [blame] | 55 | && length < CharUtils::getCodePointCount(MAX_WORD_LENGTH, |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 56 | bigramCodePoints + insertAt * MAX_WORD_LENGTH))) { |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 57 | break; |
| 58 | } |
| 59 | insertAt++; |
| 60 | } |
Satoshi Kataoka | e320789 | 2013-04-08 17:33:32 +0900 | [diff] [blame] | 61 | if (DEBUG_DICT_FULL) { |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 62 | AKLOGI("Bigram: InsertAt -> %d MAX_RESULTS: %d", insertAt, MAX_RESULTS); |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 63 | } |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 64 | if (insertAt >= MAX_RESULTS) { |
| 65 | return; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 66 | } |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 67 | memmove(bigramProbability + (insertAt + 1), |
| 68 | bigramProbability + insertAt, |
| 69 | (MAX_RESULTS - insertAt - 1) * sizeof(bigramProbability[0])); |
| 70 | bigramProbability[insertAt] = probability; |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 71 | outputTypes[insertAt] = Dictionary::KIND_PREDICTION; |
| 72 | memmove(bigramCodePoints + (insertAt + 1) * MAX_WORD_LENGTH, |
| 73 | bigramCodePoints + insertAt * MAX_WORD_LENGTH, |
| 74 | (MAX_RESULTS - insertAt - 1) * sizeof(bigramCodePoints[0]) * MAX_WORD_LENGTH); |
| 75 | int *dest = bigramCodePoints + insertAt * MAX_WORD_LENGTH; |
| 76 | while (length--) { |
| 77 | *dest++ = *word++; |
| 78 | } |
| 79 | *dest = 0; // NULL terminate |
Satoshi Kataoka | e320789 | 2013-04-08 17:33:32 +0900 | [diff] [blame] | 80 | if (DEBUG_DICT_FULL) { |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 81 | AKLOGI("Bigram: Added word at %d", insertAt); |
| 82 | } |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Jean Chalard | 588e2f2 | 2011-07-25 14:03:19 +0900 | [diff] [blame] | 85 | /* Parameters : |
| 86 | * prevWord: the word before, the one for which we need to look up bigrams. |
| 87 | * prevWordLength: its length. |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 88 | * inputCodePoints: what user typed, in the same format as for UnigramDictionary::getSuggestions. |
| 89 | * inputSize: the size of the codes array. |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 90 | * bigramCodePoints: an array for output, at the same format as outwords for getSuggestions. |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 91 | * bigramProbability: an array to output frequencies. |
Jean Chalard | 6931df9 | 2012-07-12 12:55:48 +0900 | [diff] [blame] | 92 | * outputTypes: an array to output types. |
Jean Chalard | 588e2f2 | 2011-07-25 14:03:19 +0900 | [diff] [blame] | 93 | * This method returns the number of bigrams this word has, for backward compatibility. |
| 94 | * Note: this is not the number of bigrams output in the array, which is the number of |
| 95 | * bigrams this word has WHOSE first letter also matches the letter the user typed. |
| 96 | * TODO: this may not be a sensible thing to do. It makes sense when the bigrams are |
| 97 | * used to match the first letter of the second word, but once the user has typed more |
| 98 | * and the bigrams are used to boost unigram result scores, it makes little sense to |
| 99 | * reduce their scope to the ones that match the first letter. |
| 100 | */ |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 101 | int BigramDictionary::getBigrams(const int *prevWord, int prevWordLength, int *inputCodePoints, |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 102 | int inputSize, int *bigramCodePoints, int *bigramProbability, int *outputTypes) const { |
Jean Chalard | 588e2f2 | 2011-07-25 14:03:19 +0900 | [diff] [blame] | 103 | // TODO: remove unused arguments, and refrain from storing stuff in members of this class |
| 104 | // TODO: have "in" arguments before "out" ones, and make out args explicit in the name |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 105 | |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 106 | const uint8_t *const root = DICT_ROOT; |
Jean Chalard | e9a86e2 | 2012-06-28 21:01:29 +0900 | [diff] [blame] | 107 | int pos = getBigramListPositionForWord(prevWord, prevWordLength, |
| 108 | false /* forceLowerCaseSearch */); |
Jean Chalard | 351864b | 2012-04-24 18:06:51 +0900 | [diff] [blame] | 109 | // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams |
Jean Chalard | e9a86e2 | 2012-06-28 21:01:29 +0900 | [diff] [blame] | 110 | if (0 == pos) { |
| 111 | // If no bigrams for this exact word, search again in lower case. |
| 112 | pos = getBigramListPositionForWord(prevWord, prevWordLength, |
| 113 | true /* forceLowerCaseSearch */); |
| 114 | } |
| 115 | // If still no bigrams, we really don't have them! |
Jean Chalard | ee396df | 2012-04-17 16:02:35 +0900 | [diff] [blame] | 116 | if (0 == pos) return 0; |
Ken Wakasa | d86d313 | 2012-09-04 20:29:38 +0900 | [diff] [blame] | 117 | uint8_t bigramFlags; |
Jean Chalard | 588e2f2 | 2011-07-25 14:03:19 +0900 | [diff] [blame] | 118 | int bigramCount = 0; |
| 119 | do { |
| 120 | bigramFlags = BinaryFormat::getFlagsAndForwardPointer(root, &pos); |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 121 | int bigramBuffer[MAX_WORD_LENGTH]; |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 122 | int unigramProbability = 0; |
Jean Chalard | 588e2f2 | 2011-07-25 14:03:19 +0900 | [diff] [blame] | 123 | const int bigramPos = BinaryFormat::getAttributeAddressAndForwardPointer(root, bigramFlags, |
| 124 | &pos); |
| 125 | const int length = BinaryFormat::getWordAtAddress(root, bigramPos, MAX_WORD_LENGTH, |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 126 | bigramBuffer, &unigramProbability); |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 127 | |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 128 | // inputSize == 0 means we are trying to find bigram predictions. |
| 129 | if (inputSize < 1 || checkFirstCharacter(bigramBuffer, inputCodePoints)) { |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 130 | const int bigramProbabilityTemp = |
| 131 | BinaryFormat::MASK_ATTRIBUTE_PROBABILITY & bigramFlags; |
| 132 | // Due to space constraints, the probability for bigrams is approximate - the lower the |
| 133 | // unigram probability, the worse the precision. The theoritical maximum error in |
| 134 | // resulting probability is 8 - although in the practice it's never bigger than 3 or 4 |
Jean Chalard | 46fe49f | 2012-05-29 16:50:25 +0900 | [diff] [blame] | 135 | // in very bad cases. This means that sometimes, we'll see some bigrams interverted |
| 136 | // here, but it can't get too bad. |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 137 | const int probability = BinaryFormat::computeProbabilityForBigram( |
| 138 | unigramProbability, bigramProbabilityTemp); |
| 139 | addWordBigram(bigramBuffer, length, probability, bigramProbability, bigramCodePoints, |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 140 | outputTypes); |
| 141 | ++bigramCount; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 142 | } |
Jean Chalard | 1956050 | 2012-07-31 23:45:32 +0900 | [diff] [blame] | 143 | } while (BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags); |
Ken Wakasa | f6870cc | 2013-01-11 18:59:01 +0900 | [diff] [blame] | 144 | return min(bigramCount, MAX_RESULTS); |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Jean Chalard | ee396df | 2012-04-17 16:02:35 +0900 | [diff] [blame] | 147 | // Returns a pointer to the start of the bigram list. |
| 148 | // If the word is not found or has no bigrams, this function returns 0. |
Ken Wakasa | aa5a3e8 | 2012-12-03 19:54:30 +0900 | [diff] [blame] | 149 | int BigramDictionary::getBigramListPositionForWord(const int *prevWord, const int prevWordLength, |
| 150 | const bool forceLowerCaseSearch) const { |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 151 | if (0 >= prevWordLength) return 0; |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 152 | const uint8_t *const root = DICT_ROOT; |
Jean Chalard | e9a86e2 | 2012-06-28 21:01:29 +0900 | [diff] [blame] | 153 | int pos = BinaryFormat::getTerminalPosition(root, prevWord, prevWordLength, |
| 154 | forceLowerCaseSearch); |
Jean Chalard | 9c2a96a | 2012-04-17 11:38:44 +0900 | [diff] [blame] | 155 | |
| 156 | if (NOT_VALID_WORD == pos) return 0; |
Ken Wakasa | d86d313 | 2012-09-04 20:29:38 +0900 | [diff] [blame] | 157 | const uint8_t flags = BinaryFormat::getFlagsAndForwardPointer(root, &pos); |
Jean Chalard | 1956050 | 2012-07-31 23:45:32 +0900 | [diff] [blame] | 158 | if (0 == (flags & BinaryFormat::FLAG_HAS_BIGRAMS)) return 0; |
| 159 | if (0 == (flags & BinaryFormat::FLAG_HAS_MULTIPLE_CHARS)) { |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame] | 160 | BinaryFormat::getCodePointAndForwardPointer(root, &pos); |
Jean Chalard | 9c2a96a | 2012-04-17 11:38:44 +0900 | [diff] [blame] | 161 | } else { |
| 162 | pos = BinaryFormat::skipOtherCharacters(root, pos); |
| 163 | } |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 164 | pos = BinaryFormat::skipProbability(flags, pos); |
Jean Chalard | 402b057 | 2012-05-29 15:56:30 +0900 | [diff] [blame] | 165 | pos = BinaryFormat::skipChildrenPosition(flags, pos); |
Jean Chalard | 9c2a96a | 2012-04-17 11:38:44 +0900 | [diff] [blame] | 166 | pos = BinaryFormat::skipShortcuts(root, flags, pos); |
| 167 | return pos; |
| 168 | } |
| 169 | |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 170 | void BigramDictionary::fillBigramAddressToProbabilityMapAndFilter(const int *prevWord, |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 171 | const int prevWordLength, std::map<int, int> *map, uint8_t *filter) const { |
Jean Chalard | f1634c8 | 2012-05-02 19:05:27 +0900 | [diff] [blame] | 172 | memset(filter, 0, BIGRAM_FILTER_BYTE_SIZE); |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 173 | const uint8_t *const root = DICT_ROOT; |
Jean Chalard | e9a86e2 | 2012-06-28 21:01:29 +0900 | [diff] [blame] | 174 | int pos = getBigramListPositionForWord(prevWord, prevWordLength, |
| 175 | false /* forceLowerCaseSearch */); |
| 176 | if (0 == pos) { |
| 177 | // If no bigrams for this exact string, search again in lower case. |
| 178 | pos = getBigramListPositionForWord(prevWord, prevWordLength, |
| 179 | true /* forceLowerCaseSearch */); |
| 180 | } |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 181 | if (0 == pos) return; |
| 182 | |
Ken Wakasa | d86d313 | 2012-09-04 20:29:38 +0900 | [diff] [blame] | 183 | uint8_t bigramFlags; |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 184 | do { |
| 185 | bigramFlags = BinaryFormat::getFlagsAndForwardPointer(root, &pos); |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 186 | const int probability = BinaryFormat::MASK_ATTRIBUTE_PROBABILITY & bigramFlags; |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 187 | const int bigramPos = BinaryFormat::getAttributeAddressAndForwardPointer(root, bigramFlags, |
| 188 | &pos); |
Satoshi Kataoka | e0e6737 | 2013-03-18 13:08:31 +0900 | [diff] [blame] | 189 | (*map)[bigramPos] = probability; |
Jean Chalard | f1634c8 | 2012-05-02 19:05:27 +0900 | [diff] [blame] | 190 | setInFilter(filter, bigramPos); |
Ken Wakasa | 866a6ce | 2013-04-26 19:58:14 +0900 | [diff] [blame] | 191 | } while (BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags); |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 192 | } |
| 193 | |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 194 | bool BigramDictionary::checkFirstCharacter(int *word, int *inputCodePoints) const { |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 195 | // Checks whether this word starts with same character or neighboring characters of |
| 196 | // what user typed. |
| 197 | |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 198 | int maxAlt = MAX_ALTERNATIVES; |
Ken Wakasa | 464d3ba | 2013-05-31 20:25:10 +0900 | [diff] [blame] | 199 | const int firstBaseLowerCodePoint = CharUtils::toBaseLowerCase(*word); |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 200 | while (maxAlt > 0) { |
Ken Wakasa | 464d3ba | 2013-05-31 20:25:10 +0900 | [diff] [blame] | 201 | if (CharUtils::toBaseLowerCase(*inputCodePoints) == firstBaseLowerCodePoint) { |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 202 | return true; |
| 203 | } |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 204 | inputCodePoints++; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 205 | maxAlt--; |
| 206 | } |
| 207 | return false; |
| 208 | } |
| 209 | |
Ken Wakasa | aa5a3e8 | 2012-12-03 19:54:30 +0900 | [diff] [blame] | 210 | bool BigramDictionary::isValidBigram(const int *word1, int length1, const int *word2, |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 211 | int length2) const { |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame] | 212 | const uint8_t *const root = DICT_ROOT; |
Jean Chalard | e9a86e2 | 2012-06-28 21:01:29 +0900 | [diff] [blame] | 213 | int pos = getBigramListPositionForWord(word1, length1, false /* forceLowerCaseSearch */); |
Tom Ouyang | 4d289d3 | 2012-04-26 23:50:21 -0700 | [diff] [blame] | 214 | // getBigramListPositionForWord returns 0 if this word isn't in the dictionary or has no bigrams |
| 215 | if (0 == pos) return false; |
Jean Chalard | e9a86e2 | 2012-06-28 21:01:29 +0900 | [diff] [blame] | 216 | int nextWordPos = BinaryFormat::getTerminalPosition(root, word2, length2, |
| 217 | false /* forceLowerCaseSearch */); |
Tom Ouyang | 4d289d3 | 2012-04-26 23:50:21 -0700 | [diff] [blame] | 218 | if (NOT_VALID_WORD == nextWordPos) return false; |
Ken Wakasa | d86d313 | 2012-09-04 20:29:38 +0900 | [diff] [blame] | 219 | uint8_t bigramFlags; |
Tom Ouyang | 4d289d3 | 2012-04-26 23:50:21 -0700 | [diff] [blame] | 220 | do { |
| 221 | bigramFlags = BinaryFormat::getFlagsAndForwardPointer(root, &pos); |
| 222 | const int bigramPos = BinaryFormat::getAttributeAddressAndForwardPointer(root, bigramFlags, |
| 223 | &pos); |
| 224 | if (bigramPos == nextWordPos) { |
| 225 | return true; |
| 226 | } |
Jean Chalard | 1956050 | 2012-07-31 23:45:32 +0900 | [diff] [blame] | 227 | } while (BinaryFormat::FLAG_ATTRIBUTE_HAS_NEXT & bigramFlags); |
Tom Ouyang | 4d289d3 | 2012-04-26 23:50:21 -0700 | [diff] [blame] | 228 | return false; |
| 229 | } |
| 230 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 231 | // TODO: Move functions related to bigram to here |
| 232 | } // namespace latinime |