satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 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 | */ |
| 16 | |
| 17 | #ifndef LATINIME_BIGRAM_DICTIONARY_H |
| 18 | #define LATINIME_BIGRAM_DICTIONARY_H |
| 19 | |
Jean Chalard | 9c2a96a | 2012-04-17 11:38:44 +0900 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 22 | namespace latinime { |
| 23 | |
| 24 | class Dictionary; |
| 25 | class BigramDictionary { |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 26 | public: |
Jean Chalard | 5b0761e | 2012-04-06 17:52:18 +0900 | [diff] [blame] | 27 | BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary); |
Jean Chalard | 522a04e | 2012-04-23 15:37:07 +0900 | [diff] [blame] | 28 | int getBigrams(const int32_t *word, int length, int *codes, int codesSize, |
satok | 6ba8de2 | 2012-03-28 18:21:04 +0900 | [diff] [blame] | 29 | unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams); |
Jean Chalard | 351864b | 2012-04-24 18:06:51 +0900 | [diff] [blame^] | 30 | int getBigramListPositionForWord(const int32_t *prevWord, const int prevWordLength); |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 31 | ~BigramDictionary(); |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 32 | private: |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 33 | bool addWordBigram(unsigned short *word, int length, int frequency); |
| 34 | int getBigramAddress(int *pos, bool advance); |
| 35 | int getBigramFreq(int *pos); |
| 36 | void searchForTerminalNode(int addressLookingFor, int frequency); |
| 37 | bool getFirstBitOfByte(int *pos) { return (DICT[*pos] & 0x80) > 0; } |
| 38 | bool getSecondBitOfByte(int *pos) { return (DICT[*pos] & 0x40) > 0; } |
| 39 | bool checkFirstCharacter(unsigned short *word); |
| 40 | |
| 41 | const unsigned char *DICT; |
| 42 | const int MAX_WORD_LENGTH; |
satok | 6ba8de2 | 2012-03-28 18:21:04 +0900 | [diff] [blame] | 43 | // TODO: Re-implement proximity correction for bigram correction |
| 44 | static const int MAX_ALTERNATIVES = 1; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 45 | |
| 46 | Dictionary *mParentDictionary; |
| 47 | int *mBigramFreq; |
| 48 | int mMaxBigrams; |
| 49 | unsigned short *mBigramChars; |
| 50 | int *mInputCodes; |
| 51 | int mInputLength; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 52 | }; |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 53 | |
| 54 | } // namespace latinime |
| 55 | |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 56 | #endif // LATINIME_BIGRAM_DICTIONARY_H |