satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2010, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef LATINIME_DEFINES_H |
| 19 | #define LATINIME_DEFINES_H |
| 20 | |
satok | 827ced8 | 2011-07-14 09:01:09 +0900 | [diff] [blame^] | 21 | #if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG) |
| 22 | #include <cutils/log.h> |
| 23 | #else |
| 24 | #define LOGE(fmt, ...) |
| 25 | #define LOGI(fmt, ...) |
| 26 | #endif |
| 27 | |
satok | 20d9fda | 2011-07-13 14:40:30 +0900 | [diff] [blame] | 28 | #ifdef FLAG_DO_PROFILE |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 29 | // Profiler |
satok | 787945b | 2011-07-14 08:32:57 +0900 | [diff] [blame] | 30 | #include <cutils/log.h> |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 31 | #include <time.h> |
| 32 | #define PROF_BUF_SIZE 100 |
| 33 | static double profile_buf[PROF_BUF_SIZE]; |
| 34 | static double profile_old[PROF_BUF_SIZE]; |
| 35 | static unsigned int profile_counter[PROF_BUF_SIZE]; |
| 36 | |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 37 | #define PROF_RESET prof_reset() |
| 38 | #define PROF_COUNT(prof_buf_id) ++profile_counter[prof_buf_id] |
| 39 | #define PROF_OPEN do { PROF_RESET; PROF_START(PROF_BUF_SIZE - 1); } while(0) |
| 40 | #define PROF_START(prof_buf_id) do { \ |
| 41 | PROF_COUNT(prof_buf_id); profile_old[prof_buf_id] = (clock()); } while(0) |
| 42 | #define PROF_CLOSE do { PROF_END(PROF_BUF_SIZE - 1); PROF_OUTALL; } while(0) |
| 43 | #define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id]) |
| 44 | #define PROF_CLOCKOUT(prof_buf_id) \ |
| 45 | LOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id])) |
| 46 | #define PROF_OUTALL do { LOGI("--- %s ---", __FUNCTION__); prof_out(); } while(0) |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 47 | |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 48 | static void prof_reset(void) { |
| 49 | for (int i = 0; i < PROF_BUF_SIZE; ++i) { |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 50 | profile_buf[i] = 0; |
| 51 | profile_old[i] = 0; |
| 52 | profile_counter[i] = 0; |
| 53 | } |
| 54 | } |
| 55 | |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 56 | static void prof_out(void) { |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 57 | if (profile_counter[PROF_BUF_SIZE - 1] != 1) { |
| 58 | LOGI("Error: You must call PROF_OPEN before PROF_CLOSE."); |
| 59 | } |
| 60 | LOGI("Total time is %6.3f ms.", |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 61 | profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC); |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 62 | double all = 0; |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 63 | for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) { |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 64 | all += profile_buf[i]; |
| 65 | } |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 66 | if (all == 0) all = 1; |
| 67 | for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) { |
| 68 | if (profile_buf[i] != 0) { |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 69 | LOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.", |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 70 | i, (profile_buf[i] * 100 / all), |
| 71 | profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]); |
| 72 | } |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
satok | 20d9fda | 2011-07-13 14:40:30 +0900 | [diff] [blame] | 76 | #else // FLAG_DO_PROFILE |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 77 | #define PROF_BUF_SIZE 0 |
| 78 | #define PROF_RESET |
| 79 | #define PROF_COUNT(prof_buf_id) |
| 80 | #define PROF_OPEN |
| 81 | #define PROF_START(prof_buf_id) |
| 82 | #define PROF_CLOSE |
| 83 | #define PROF_END(prof_buf_id) |
| 84 | #define PROF_CLOCK_OUT(prof_buf_id) |
| 85 | #define PROF_CLOCKOUT(prof_buf_id) |
| 86 | #define PROF_OUTALL |
| 87 | |
satok | 20d9fda | 2011-07-13 14:40:30 +0900 | [diff] [blame] | 88 | #endif // FLAG_DO_PROFILE |
| 89 | |
| 90 | #ifdef FLAG_DBG |
| 91 | #include <cutils/log.h> |
| 92 | #ifndef LOG_TAG |
| 93 | #define LOG_TAG "LatinIME: " |
| 94 | #endif |
| 95 | #define DEBUG_DICT true |
| 96 | #define DEBUG_DICT_FULL false |
| 97 | #define DEBUG_SHOW_FOUND_WORD DEBUG_DICT_FULL |
| 98 | #define DEBUG_NODE DEBUG_DICT_FULL |
| 99 | #define DEBUG_TRACE DEBUG_DICT_FULL |
| 100 | #define DEBUG_PROXIMITY_INFO true |
| 101 | |
| 102 | #else // FLAG_DBG |
satok | 827ced8 | 2011-07-14 09:01:09 +0900 | [diff] [blame^] | 103 | |
satok | 20d9fda | 2011-07-13 14:40:30 +0900 | [diff] [blame] | 104 | #define DEBUG_DICT false |
| 105 | #define DEBUG_DICT_FULL false |
| 106 | #define DEBUG_SHOW_FOUND_WORD false |
| 107 | #define DEBUG_NODE false |
| 108 | #define DEBUG_TRACE false |
| 109 | #define DEBUG_PROXIMITY_INFO false |
| 110 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 111 | #endif // FLAG_DBG |
| 112 | |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 113 | #ifndef U_SHORT_MAX |
| 114 | #define U_SHORT_MAX 1 << 16 |
| 115 | #endif |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 116 | #ifndef S_INT_MAX |
satok | 3c4bb77 | 2011-03-04 22:50:19 -0800 | [diff] [blame] | 117 | #define S_INT_MAX 2147483647 // ((1 << 31) - 1) |
Jean Chalard | a5d5849 | 2011-02-18 17:50:58 +0900 | [diff] [blame] | 118 | #endif |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 119 | |
Ken Wakasa | e90b333 | 2011-01-07 15:01:51 +0900 | [diff] [blame] | 120 | // Define this to use mmap() for dictionary loading. Undefine to use malloc() instead of mmap(). |
| 121 | // We measured and compared performance of both, and found mmap() is fairly good in terms of |
| 122 | // loading time, and acceptable even for several initial lookups which involve page faults. |
| 123 | #define USE_MMAP_FOR_DICTIONARY |
| 124 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 125 | // 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words |
| 126 | #define ADDRESS_MASK 0x3FFFFF |
| 127 | |
| 128 | // The bit that decides if an address follows in the next 22 bits |
| 129 | #define FLAG_ADDRESS_MASK 0x40 |
| 130 | // The bit that decides if this is a terminal node for a word. The node could still have children, |
| 131 | // if the word has other endings. |
| 132 | #define FLAG_TERMINAL_MASK 0x80 |
| 133 | |
| 134 | #define FLAG_BIGRAM_READ 0x80 |
| 135 | #define FLAG_BIGRAM_CHILDEXIST 0x40 |
| 136 | #define FLAG_BIGRAM_CONTINUED 0x80 |
| 137 | #define FLAG_BIGRAM_FREQ 0x7F |
| 138 | |
| 139 | #define DICTIONARY_VERSION_MIN 200 |
Jean Chalard | 1059f27 | 2011-06-28 20:45:05 +0900 | [diff] [blame] | 140 | // TODO: remove this constant when the switch to the new dict format is over |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 141 | #define DICTIONARY_HEADER_SIZE 2 |
Jean Chalard | 1059f27 | 2011-06-28 20:45:05 +0900 | [diff] [blame] | 142 | #define NEW_DICTIONARY_HEADER_SIZE 5 |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 143 | #define NOT_VALID_WORD -99 |
Jean Chalard | 1059f27 | 2011-06-28 20:45:05 +0900 | [diff] [blame] | 144 | #define NOT_A_CHARACTER -1 |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 145 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 146 | #define KEYCODE_SPACE ' ' |
| 147 | |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 148 | #define SUGGEST_WORDS_WITH_MISSING_CHARACTER true |
| 149 | #define SUGGEST_WORDS_WITH_MISSING_SPACE_CHARACTER true |
| 150 | #define SUGGEST_WORDS_WITH_EXCESSIVE_CHARACTER true |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 151 | #define SUGGEST_WORDS_WITH_TRANSPOSED_CHARACTERS true |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 152 | #define SUGGEST_WORDS_WITH_SPACE_PROXIMITY true |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 153 | |
Jean Chalard | 8dc754a | 2011-01-27 14:20:22 +0900 | [diff] [blame] | 154 | // The following "rate"s are used as a multiplier before dividing by 100, so they are in percent. |
satok | 72bc17e | 2011-04-13 17:23:27 +0900 | [diff] [blame] | 155 | #define WORDS_WITH_MISSING_CHARACTER_DEMOTION_RATE 80 |
satok | dc5301e | 2011-04-11 16:14:45 +0900 | [diff] [blame] | 156 | #define WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X 12 |
satok | 99c908a | 2011-05-24 14:28:13 +0900 | [diff] [blame] | 157 | #define WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE 67 |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 158 | #define WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE 75 |
satok | 54fe9e0 | 2010-12-13 14:42:35 +0900 | [diff] [blame] | 159 | #define WORDS_WITH_EXCESSIVE_CHARACTER_OUT_OF_PROXIMITY_DEMOTION_RATE 75 |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 160 | #define WORDS_WITH_TRANSPOSED_CHARACTERS_DEMOTION_RATE 60 |
satok | 58c49b9 | 2011-01-27 03:23:39 +0900 | [diff] [blame] | 161 | #define FULL_MATCHED_WORDS_PROMOTION_RATE 120 |
satok | 9d2a302 | 2011-04-14 19:13:34 +0900 | [diff] [blame] | 162 | #define WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE 90 |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 163 | |
satok | f5cded1 | 2010-12-06 21:28:24 +0900 | [diff] [blame] | 164 | // This should be greater than or equal to MAX_WORD_LENGTH defined in BinaryDictionary.java |
| 165 | // This is only used for the size of array. Not to be used in c functions. |
| 166 | #define MAX_WORD_LENGTH_INTERNAL 48 |
satok | 715514d | 2010-12-02 20:19:59 +0900 | [diff] [blame] | 167 | |
satok | 6831926 | 2010-12-03 19:38:08 +0900 | [diff] [blame] | 168 | #define MAX_DEPTH_MULTIPLIER 3 |
| 169 | |
Jean Chalard | a787dba | 2011-03-04 12:17:48 +0900 | [diff] [blame] | 170 | // TODO: Reduce this constant if possible; check the maximum number of umlauts in the same German |
| 171 | // word in the dictionary |
| 172 | #define DEFAULT_MAX_UMLAUT_SEARCH_DEPTH 5 |
| 173 | |
satok | 54fe9e0 | 2010-12-13 14:42:35 +0900 | [diff] [blame] | 174 | // Minimum suggest depth for one word for all cases except for missing space suggestions. |
| 175 | #define MIN_SUGGEST_DEPTH 1 |
| 176 | #define MIN_USER_TYPED_LENGTH_FOR_MISSING_SPACE_SUGGESTION 3 |
| 177 | #define MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION 3 |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 178 | |
Tadashi G. Takaoka | 887f11e | 2011-02-10 20:53:58 +0900 | [diff] [blame] | 179 | // The size of next letters frequency array. Zero will disable the feature. |
| 180 | #define NEXT_LETTERS_SIZE 0 |
| 181 | |
satok | f5cded1 | 2010-12-06 21:28:24 +0900 | [diff] [blame] | 182 | #define min(a,b) ((a)<(b)?(a):(b)) |
| 183 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 184 | #endif // LATINIME_DEFINES_H |