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, |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 51 | int *frequencies, int *spaceIndices, int *outputTypes); |
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; |
| 58 | void *getDict() const { return (void *)mDict; } |
| 59 | int getDictSize() const { return mDictSize; } |
| 60 | int getMmapFd() const { return mMmapFd; } |
| 61 | int getDictBufAdjust() const { return mDictBufAdjust; } |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 62 | virtual ~Dictionary(); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 63 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 64 | // public static utility methods |
| 65 | // static inline methods should be defined in the header file |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 66 | static int wideStrLen(unsigned short *str); |
Jean Chalard | 581335c | 2011-06-17 12:45:17 +0900 | [diff] [blame] | 67 | |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 68 | private: |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 69 | DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 70 | const unsigned char *mDict; |
| 71 | |
| 72 | // Used only for the mmap version of dictionary loading, but we use these as dummy variables |
| 73 | // also for the malloc version. |
| 74 | const int mDictSize; |
| 75 | const int mMmapFd; |
| 76 | const int mDictBufAdjust; |
| 77 | |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 78 | const UnigramDictionary *mUnigramDictionary; |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 79 | const BigramDictionary *mBigramDictionary; |
Ken Wakasa | 8658e55 | 2012-06-30 08:53:33 +0900 | [diff] [blame] | 80 | IncrementalDecoderInterface *mGestureDecoder; |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 83 | // public static utility methods |
| 84 | // static inline methods should be defined in the header file |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 85 | inline int Dictionary::wideStrLen(unsigned short *str) { |
| 86 | if (!str) return 0; |
| 87 | unsigned short *end = str; |
| 88 | while (*end) |
| 89 | end++; |
| 90 | return end - str; |
| 91 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 92 | } // namespace latinime |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 93 | #endif // LATINIME_DICTIONARY_H |