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 ProximityInfo; 28 class SuggestInterface; 29 class UnigramDictionary; 30 31 class Dictionary { 32 public: 33 // Taken from SuggestedWords.java 34 static const int KIND_MASK_KIND = 0xFF; // Mask to get only the kind 35 static const int KIND_TYPED = 0; // What user typed 36 static const int KIND_CORRECTION = 1; // Simple correction/suggestion 37 static const int KIND_COMPLETION = 2; // Completion (suggestion with appended chars) 38 static const int KIND_WHITELIST = 3; // Whitelisted word 39 static const int KIND_BLACKLIST = 4; // Blacklisted word 40 static const int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation 41 static const int KIND_APP_DEFINED = 6; // Suggested by the application 42 static const int KIND_SHORTCUT = 7; // A shortcut 43 static const int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input) 44 45 static const int KIND_MASK_FLAGS = 0xFFFFFF00; // Mask to get the flags 46 static const int KIND_FLAG_POSSIBLY_OFFENSIVE = 0x80000000; 47 static const int KIND_FLAG_EXACT_MATCH = 0x40000000; 48 49 Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust); 50 51 int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates, 52 int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, int inputSize, 53 int *prevWordCodePoints, int prevWordLength, int commitPoint, bool isGesture, 54 bool useFullEditDistance, int *outWords, int *frequencies, int *spaceIndices, 55 int *outputTypes) const; 56 57 int getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords, 58 int *frequencies, int *outputTypes) const; 59 60 int getProbability(const int *word, int length) const; 61 bool isValidBigram(const int *word1, int length1, const int *word2, int length2) const; 62 const uint8_t *getDict() const { // required to release dictionary buffer 63 return mDict; 64 } 65 const uint8_t *getOffsetDict() const { 66 return mOffsetDict; 67 } 68 int getDictSize() const { return mDictSize; } 69 int getMmapFd() const { return mMmapFd; } 70 int getDictBufAdjust() const { return mDictBufAdjust; } 71 int getDictFlags() const; 72 virtual ~Dictionary(); 73 74 private: 75 DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); 76 const uint8_t *mDict; 77 const uint8_t *mOffsetDict; 78 79 // Used only for the mmap version of dictionary loading, but we use these as dummy variables 80 // also for the malloc version. 81 const int mDictSize; 82 const int mMmapFd; 83 const int mDictBufAdjust; 84 85 const UnigramDictionary *mUnigramDictionary; 86 const BigramDictionary *mBigramDictionary; 87 SuggestInterface *mGestureSuggest; 88 SuggestInterface *mTypingSuggest; 89 }; 90 } // namespace latinime 91 #endif // LATINIME_DICTIONARY_H 92