blob: 2ce6c1d0d244b662c108cec706e6eff5de83e124 [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
satok30088252010-12-01 21:22:15 +090027class BigramDictionary {
Ken Wakasae12e9b52012-01-06 12:24:38 +090028 public:
Ken Wakasa5db594a2013-01-12 01:18:00 +090029 BigramDictionary(const uint8_t *const streamStart);
30 int getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords,
Ken Wakasa1e614932012-10-29 18:06:22 +090031 int *frequencies, int *outputTypes) const;
32 void fillBigramAddressToFrequencyMapAndFilter(const int *prevWord, const int prevWordLength,
satokb1ed1d42012-06-14 16:35:23 -070033 std::map<int, int> *map, uint8_t *filter) const;
Ken Wakasa1e614932012-10-29 18:06:22 +090034 bool isValidBigram(const int *word1, int length1, const int *word2, int length2) const;
satok30088252010-12-01 21:22:15 +090035 ~BigramDictionary();
Ken Wakasae12e9b52012-01-06 12:24:38 +090036 private:
satok1bc038c2012-06-14 11:25:50 -070037 DISALLOW_IMPLICIT_CONSTRUCTORS(BigramDictionary);
Ken Wakasaf6870cc2013-01-11 18:59:01 +090038 void addWordBigram(int *word, int length, int frequency, int *bigramFreq, int *bigramCodePoints,
Ken Wakasa1e614932012-10-29 18:06:22 +090039 int *outputTypes) const;
Ken Wakasa5db594a2013-01-12 01:18:00 +090040 bool checkFirstCharacter(int *word, int *inputCodePoints) const;
Ken Wakasa1e614932012-10-29 18:06:22 +090041 int getBigramListPositionForWord(const int *prevWord, const int prevWordLength,
Ken Wakasade8a9a82012-08-17 13:06:28 +090042 const bool forceLowerCaseSearch) const;
satok18c28f42010-12-02 18:11:54 +090043
Ken Wakasa5db594a2013-01-12 01:18:00 +090044 const uint8_t *const DICT_ROOT;
satok6ba8de22012-03-28 18:21:04 +090045 // TODO: Re-implement proximity correction for bigram correction
46 static const int MAX_ALTERNATIVES = 1;
satok30088252010-12-01 21:22:15 +090047};
Ken Wakasace9e52a2011-06-18 13:09:55 +090048} // namespace latinime
satok30088252010-12-01 21:22:15 +090049#endif // LATINIME_BIGRAM_DICTIONARY_H