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; |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 27 | class ProximityInfo; |
Ken Wakasa | ffd08e3 | 2012-12-20 18:32:44 +0900 | [diff] [blame] | 28 | class SuggestInterface; |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 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 | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame^] | 44 | Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust); |
satok | 1147c7b | 2011-12-14 15:04:58 +0900 | [diff] [blame] | 45 | |
Satoshi Kataoka | 9127811 | 2012-08-08 21:23:25 +0900 | [diff] [blame] | 46 | int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates, |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame^] | 47 | int *ycoordinates, int *times, int *pointerIds, int *inputCodePoints, int inputSize, |
| 48 | int *prevWordCodePoints, int prevWordLength, int commitPoint, bool isGesture, |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 49 | bool useFullEditDistance, int *outWords, int *frequencies, int *spaceIndices, |
| 50 | int *outputTypes) const; |
satok | 3008825 | 2010-12-01 21:22:15 +0900 | [diff] [blame] | 51 | |
Ken Wakasa | 5db594a | 2013-01-12 01:18:00 +0900 | [diff] [blame^] | 52 | int getBigrams(const int *word, int length, int *inputCodePoints, int inputSize, int *outWords, |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 53 | int *frequencies, int *outputTypes) const; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 54 | |
Ken Wakasa | aa5a3e8 | 2012-12-03 19:54:30 +0900 | [diff] [blame] | 55 | int getFrequency(const int *word, int length) const; |
| 56 | bool isValidBigram(const int *word1, int length1, const int *word2, int length2) const; |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 57 | const uint8_t *getDict() const { // required to release dictionary buffer |
| 58 | return mDict; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 59 | } |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 60 | const uint8_t *getOffsetDict() const { |
| 61 | return mOffsetDict; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 62 | } |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 63 | int getDictSize() const { return mDictSize; } |
| 64 | int getMmapFd() const { return mMmapFd; } |
| 65 | int getDictBufAdjust() const { return mDictBufAdjust; } |
Ken Wakasa | 77e8e81 | 2012-08-02 19:48:08 +0900 | [diff] [blame] | 66 | virtual ~Dictionary(); |
Amith Yamasani | cc3e5c7 | 2009-03-31 10:51:17 -0700 | [diff] [blame] | 67 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 68 | // public static utility methods |
| 69 | // static inline methods should be defined in the header file |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 70 | static int wideStrLen(int *str); |
Jean Chalard | 581335c | 2011-06-17 12:45:17 +0900 | [diff] [blame] | 71 | |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 72 | private: |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 73 | DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 74 | const uint8_t *mDict; |
| 75 | const uint8_t *mOffsetDict; |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 76 | |
| 77 | // Used only for the mmap version of dictionary loading, but we use these as dummy variables |
| 78 | // also for the malloc version. |
| 79 | const int mDictSize; |
| 80 | const int mMmapFd; |
| 81 | const int mDictBufAdjust; |
| 82 | |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 83 | const UnigramDictionary *mUnigramDictionary; |
satok | b1ed1d4 | 2012-06-14 16:35:23 -0700 | [diff] [blame] | 84 | const BigramDictionary *mBigramDictionary; |
Ken Wakasa | ffd08e3 | 2012-12-20 18:32:44 +0900 | [diff] [blame] | 85 | SuggestInterface *mGestureSuggest; |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 88 | // public static utility methods |
| 89 | // static inline methods should be defined in the header file |
Ken Wakasa | 1e61493 | 2012-10-29 18:06:22 +0900 | [diff] [blame] | 90 | inline int Dictionary::wideStrLen(int *str) { |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 91 | if (!str) return 0; |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame] | 92 | int length = 0; |
| 93 | while (*str) { |
| 94 | str++; |
| 95 | length++; |
Ken Wakasa | bcec82d | 2012-08-12 11:10:48 +0900 | [diff] [blame] | 96 | } |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame] | 97 | return length; |
satok | 18c28f4 | 2010-12-02 18:11:54 +0900 | [diff] [blame] | 98 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 99 | } // namespace latinime |
The Android Open Source Project | 923bf41 | 2009-03-13 15:11:42 -0700 | [diff] [blame] | 100 | #endif // LATINIME_DICTIONARY_H |