The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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_DICTIONARY_H |
| 18 | #define LATINIME_DICTIONARY_H |
| 19 | |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 20 | #include <stdint.h> |
Jean Chalard | 1ff8dc4 | 2012-05-02 16:00:24 +0900 | [diff] [blame] | 21 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 22 | #include "defines.h" |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 23 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 24 | namespace latinime { |
| 25 | |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 26 | class BigramDictionary; |
| 27 | class IncrementalDecoderInterface; |
| 28 | class ProximityInfo; |
| 29 | class UnigramDictionary; |
| 30 | |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 31 | class Dictionary { |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 32 | public: |
Jean Chalard | c7387a4 | 2012-07-12 15:21:11 +0900 | [diff] [blame] | 33 | // Taken from SuggestedWords.java |
| 34 | const static int KIND_TYPED = 0; // What user typed |
| 35 | const static int KIND_CORRECTION = 1; // Simple correction/suggestion |
| 36 | const static int KIND_COMPLETION = 2; // Completion (suggestion with appended chars) |
| 37 | const static int KIND_WHITELIST = 3; // Whitelisted word |
| 38 | const static int KIND_BLACKLIST = 4; // Blacklisted word |
| 39 | const static int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation |
| 40 | const static int KIND_APP_DEFINED = 6; // Suggested by the application |
| 41 | const static int KIND_SHORTCUT = 7; // A shortcut |
| 42 | const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input) |
| 43 | |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 44 | Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler, |
Jean Chalard | b7d7c5a | 2012-07-11 11:31:48 +0900 | [diff] [blame] | 45 | int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions); |
satok | 1147c7b | 2011-12-14 15:04:58 +0900 | [diff] [blame] | 46 | |
Satoshi Kataoka | 9127811 | 2012-08-08 21:23:25 +0900 | [diff] [blame] | 47 | int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates, |
| 48 | int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize, |
| 49 | int *prevWordChars, int prevWordLength, int commitPoint, bool isGesture, |
Satoshi Kataoka | 7368009 | 2012-06-25 17:44:54 +0900 | [diff] [blame] | 50 | bool useFullEditDistance, unsigned short *outWords, |
Satoshi Kataoka | f6be15c | 2012-08-15 16:57:32 +0900 | [diff] [blame] | 51 | int *frequencies, int *spaceIndices, int *outputTypes) const; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 52 | |
Jean Chalard | 522a04e | 2012-04-23 15:37:07 +0900 | [diff] [blame] | 53 | int getBigrams(const int32_t *word, int length, int *codes, int codesSize, |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 54 | unsigned short *outWords, int *frequencies, int *outputTypes) const; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 55 | |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 56 | int getFrequency(const int32_t *word, int length) const; |
| 57 | bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const; |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 58 | const uint8_t *getDict() const { // required to release dictionary buffer |
| 59 | return mDict; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 60 | } |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 61 | const uint8_t *getOffsetDict() const { |
| 62 | return mOffsetDict; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 63 | } |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 64 | int getDictSize() const { return mDictSize; } |
| 65 | int getMmapFd() const { return mMmapFd; } |
| 66 | int getDictBufAdjust() const { return mDictBufAdjust; } |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 67 | virtual ~Dictionary(); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 68 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 69 | // public static utility methods |
| 70 | // static inline methods should be defined in the header file |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 71 | static int wideStrLen(unsigned short *str); |
Jean Chalard | 581335c | 2011-06-17 12:45:17 +0900 | [diff] [blame] | 72 | |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 73 | private: |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 74 | DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 75 | const uint8_t *mDict; |
| 76 | const uint8_t *mOffsetDict; |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 77 | |
| 78 | // Used only for the mmap version of dictionary loading, but we use these as dummy variables |
| 79 | // also for the malloc version. |
| 80 | const int mDictSize; |
| 81 | const int mMmapFd; |
| 82 | const int mDictBufAdjust; |
| 83 | |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 84 | const UnigramDictionary *mUnigramDictionary; |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 85 | const BigramDictionary *mBigramDictionary; |
Ken Wakasa | 8658e55 | 2012-06-30 08:53:33 +0900 | [diff] [blame] | 86 | IncrementalDecoderInterface *mGestureDecoder; |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 89 | // public static utility methods |
| 90 | // static inline methods should be defined in the header file |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 91 | inline int Dictionary::wideStrLen(unsigned short *str) { |
| 92 | if (!str) return 0; |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame^] | 93 | int length = 0; |
| 94 | while (*str) { |
| 95 | str++; |
| 96 | length++; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 97 | } |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame^] | 98 | return length; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 99 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 100 | } // namespace latinime |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 101 | #endif // LATINIME_DICTIONARY_H |