blob: af89e3255387e0730dd8cee12a9a848f3fd9e142 [file] [log] [blame]
satok30088252010-12-01 21:22:15 +09001/*
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
20namespace latinime {
21
22class Dictionary;
23class BigramDictionary {
Ken Wakasae12e9b52012-01-06 12:24:38 +090024 public:
Jean Chalard5b0761e2012-04-06 17:52:18 +090025 BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary);
satok18c28f42010-12-02 18:11:54 +090026 int getBigrams(unsigned short *word, int length, int *codes, int codesSize,
satok6ba8de22012-03-28 18:21:04 +090027 unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams);
satok30088252010-12-01 21:22:15 +090028 ~BigramDictionary();
Ken Wakasae12e9b52012-01-06 12:24:38 +090029 private:
satok18c28f42010-12-02 18:11:54 +090030 bool addWordBigram(unsigned short *word, int length, int frequency);
31 int getBigramAddress(int *pos, bool advance);
32 int getBigramFreq(int *pos);
33 void searchForTerminalNode(int addressLookingFor, int frequency);
34 bool getFirstBitOfByte(int *pos) { return (DICT[*pos] & 0x80) > 0; }
35 bool getSecondBitOfByte(int *pos) { return (DICT[*pos] & 0x40) > 0; }
36 bool checkFirstCharacter(unsigned short *word);
37
38 const unsigned char *DICT;
39 const int MAX_WORD_LENGTH;
satok6ba8de22012-03-28 18:21:04 +090040 // TODO: Re-implement proximity correction for bigram correction
41 static const int MAX_ALTERNATIVES = 1;
satok18c28f42010-12-02 18:11:54 +090042
43 Dictionary *mParentDictionary;
44 int *mBigramFreq;
45 int mMaxBigrams;
46 unsigned short *mBigramChars;
47 int *mInputCodes;
48 int mInputLength;
satok30088252010-12-01 21:22:15 +090049};
Ken Wakasace9e52a2011-06-18 13:09:55 +090050
51} // namespace latinime
52
satok30088252010-12-01 21:22:15 +090053#endif // LATINIME_BIGRAM_DICTIONARY_H