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 20 #include <stdint.h> 21 22 #include "defines.h" 23 24 namespace latinime { 25 26 class BigramDictionary; 27 class IncrementalDecoderInterface; 28 class ProximityInfo; 29 class UnigramDictionary; 30 31 class Dictionary { 32 public: 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 44 Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler, 45 int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions); 46 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, 50 bool useFullEditDistance, unsigned short *outWords, 51 int *frequencies, int *spaceIndices, int *outputTypes) const; 52 53 int getBigrams(const int32_t *word, int length, int *codes, int codesSize, 54 unsigned short *outWords, int *frequencies, int *outputTypes) const; 55 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 const uint8_t *getDict() const { // required to release dictionary buffer 59 return mDict; 60 } 61 const uint8_t *getOffsetDict() const { 62 return mOffsetDict; 63 } 64 int getDictSize() const { return mDictSize; } 65 int getMmapFd() const { return mMmapFd; } 66 int getDictBufAdjust() const { return mDictBufAdjust; } 67 virtual ~Dictionary(); 68 69 // public static utility methods 70 // static inline methods should be defined in the header file 71 static int wideStrLen(unsigned short *str); 72 73 private: 74 DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); 75 const uint8_t *mDict; 76 const uint8_t *mOffsetDict; 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 84 const UnigramDictionary *mUnigramDictionary; 85 const BigramDictionary *mBigramDictionary; 86 IncrementalDecoderInterface *mGestureDecoder; 87 }; 88 89 // public static utility methods 90 // static inline methods should be defined in the header file 91 inline int Dictionary::wideStrLen(unsigned short *str) { 92 if (!str) return 0; 93 int length = 0; 94 while (*str) { 95 str++; 96 length++; 97 } 98 return length; 99 } 100 } // namespace latinime 101 #endif // LATINIME_DICTIONARY_H 102