blob: 7328d5828a36414b1cd13bf5580c601b07c57f76 [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
Jean Chalard1ff8dc42012-05-02 16:00:24 +090020#include <map>
Jean Chalard9c2a96a2012-04-17 11:38:44 +090021#include <stdint.h>
22
Jean Chalardf1634c82012-05-02 19:05:27 +090023#include "defines.h"
24
satok30088252010-12-01 21:22:15 +090025namespace latinime {
26
27class Dictionary;
28class BigramDictionary {
Ken Wakasae12e9b52012-01-06 12:24:38 +090029 public:
Jean Chalard5b0761e2012-04-06 17:52:18 +090030 BigramDictionary(const unsigned char *dict, int maxWordLength, Dictionary *parentDictionary);
Jean Chalard522a04e2012-04-23 15:37:07 +090031 int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
satok6ba8de22012-03-28 18:21:04 +090032 unsigned short *outWords, int *frequencies, int maxWordLength, int maxBigrams);
Jean Chalard351864b2012-04-24 18:06:51 +090033 int getBigramListPositionForWord(const int32_t *prevWord, const int prevWordLength);
Jean Chalardf1634c82012-05-02 19:05:27 +090034 void fillBigramAddressToFrequencyMapAndFilter(const int32_t *prevWord, const int prevWordLength,
35 std::map<int, int> *map, uint8_t *filter);
satok30088252010-12-01 21:22:15 +090036 ~BigramDictionary();
Ken Wakasae12e9b52012-01-06 12:24:38 +090037 private:
satok18c28f42010-12-02 18:11:54 +090038 bool addWordBigram(unsigned short *word, int length, int frequency);
39 int getBigramAddress(int *pos, bool advance);
40 int getBigramFreq(int *pos);
41 void searchForTerminalNode(int addressLookingFor, int frequency);
42 bool getFirstBitOfByte(int *pos) { return (DICT[*pos] & 0x80) > 0; }
43 bool getSecondBitOfByte(int *pos) { return (DICT[*pos] & 0x40) > 0; }
44 bool checkFirstCharacter(unsigned short *word);
45
46 const unsigned char *DICT;
47 const int MAX_WORD_LENGTH;
satok6ba8de22012-03-28 18:21:04 +090048 // TODO: Re-implement proximity correction for bigram correction
49 static const int MAX_ALTERNATIVES = 1;
satok18c28f42010-12-02 18:11:54 +090050
51 Dictionary *mParentDictionary;
52 int *mBigramFreq;
53 int mMaxBigrams;
54 unsigned short *mBigramChars;
55 int *mInputCodes;
56 int mInputLength;
satok30088252010-12-01 21:22:15 +090057};
Ken Wakasace9e52a2011-06-18 13:09:55 +090058
59} // namespace latinime
60
satok30088252010-12-01 21:22:15 +090061#endif // LATINIME_BIGRAM_DICTIONARY_H