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 | |
| 21 | #ifdef FLAG_DBG |
| 22 | #include <cutils/log.h> |
| 23 | #ifndef LOG_TAG |
| 24 | #define LOG_TAG "LatinIME: " |
| 25 | #endif |
satok | cdbbea7 | 2010-12-08 16:04:16 +0900 | [diff] [blame] | 26 | #define DEBUG_DICT true |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 27 | #define DEBUG_DICT_FULL false |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 28 | #define DEBUG_SHOW_FOUND_WORD DEBUG_DICT_FULL |
| 29 | #define DEBUG_NODE DEBUG_DICT_FULL |
| 30 | #define DEBUG_TRACE DEBUG_DICT_FULL |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 31 | |
| 32 | // Profiler |
| 33 | #include <time.h> |
| 34 | #define PROF_BUF_SIZE 100 |
| 35 | static double profile_buf[PROF_BUF_SIZE]; |
| 36 | static double profile_old[PROF_BUF_SIZE]; |
| 37 | static unsigned int profile_counter[PROF_BUF_SIZE]; |
| 38 | |
| 39 | #define PROF_RESET prof_reset(); |
| 40 | #define PROF_COUNT(prof_buf_id) ++profile_counter[prof_buf_id]; |
| 41 | #define PROF_OPEN PROF_RESET;PROF_START(PROF_BUF_SIZE - 1); |
| 42 | #define PROF_START(prof_buf_id) PROF_COUNT(prof_buf_id);profile_old[prof_buf_id] = (clock()); |
| 43 | #define PROF_CLOSE PROF_END(PROF_BUF_SIZE - 1);PROF_OUTALL; |
| 44 | #define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id]); |
| 45 | #define PROF_CLOCKOUT(prof_buf_id) LOGI("%s : clock is %f", __FUNCTION__,\ |
| 46 | (clock() - profile_old[prof_buf_id])); |
| 47 | #define PROF_OUTALL LOGI("--- %s ---", __FUNCTION__); prof_out(); |
| 48 | |
| 49 | static void prof_reset(void){ |
| 50 | for(int i = 0;i < PROF_BUF_SIZE;++i){ |
| 51 | profile_buf[i] = 0; |
| 52 | profile_old[i] = 0; |
| 53 | profile_counter[i] = 0; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static void prof_out(void){ |
| 58 | if (profile_counter[PROF_BUF_SIZE - 1] != 1) { |
| 59 | LOGI("Error: You must call PROF_OPEN before PROF_CLOSE."); |
| 60 | } |
| 61 | LOGI("Total time is %6.3f ms.", |
| 62 | profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double) CLOCKS_PER_SEC); |
| 63 | double all = 0; |
| 64 | for(int i = 0; i < PROF_BUF_SIZE - 1; ++i){ |
| 65 | all += profile_buf[i]; |
| 66 | } |
| 67 | if(all == 0) all = 1; |
| 68 | for(int i = 0; i < PROF_BUF_SIZE - 1; ++i){ |
| 69 | if(profile_buf[i] != 0) { |
| 70 | LOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.", |
| 71 | i, (profile_buf[i] * 100 /all), |
| 72 | profile_buf[i] * 1000 / (double) CLOCKS_PER_SEC, profile_counter[i]); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 77 | #else // FLAG_DBG |
| 78 | #define LOGI |
satok | cdbbea7 | 2010-12-08 16:04:16 +0900 | [diff] [blame] | 79 | #define DEBUG_DICT false |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 80 | #define DEBUG_DICT_FULL false |
satok | cdbbea7 | 2010-12-08 16:04:16 +0900 | [diff] [blame] | 81 | #define DEBUG_SHOW_FOUND_WORD false |
satok | aee09dc | 2010-12-09 19:21:51 +0900 | [diff] [blame] | 82 | #define DEBUG_NODE false |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 83 | #define DEBUG_TRACE false |
satok | 61e2f85 | 2011-01-05 14:13:07 +0900 | [diff] [blame] | 84 | |
| 85 | #define PROF_BUF_SIZE 0 |
| 86 | #define PROF_RESET |
| 87 | #define PROF_COUNT(prof_buf_id) |
| 88 | #define PROF_OPEN |
| 89 | #define PROF_START(prof_buf_id) |
| 90 | #define PROF_CLOSE |
| 91 | #define PROF_END(prof_buf_id) |
| 92 | #define PROF_CLOCK_OUT(prof_buf_id) |
| 93 | #define PROF_CLOCKOUT(prof_buf_id) |
| 94 | #define PROF_OUTALL |
| 95 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 96 | #endif // FLAG_DBG |
| 97 | |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 98 | #ifndef U_SHORT_MAX |
| 99 | #define U_SHORT_MAX 1 << 16 |
| 100 | #endif |
| 101 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 102 | // 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words |
| 103 | #define ADDRESS_MASK 0x3FFFFF |
| 104 | |
| 105 | // The bit that decides if an address follows in the next 22 bits |
| 106 | #define FLAG_ADDRESS_MASK 0x40 |
| 107 | // The bit that decides if this is a terminal node for a word. The node could still have children, |
| 108 | // if the word has other endings. |
| 109 | #define FLAG_TERMINAL_MASK 0x80 |
| 110 | |
| 111 | #define FLAG_BIGRAM_READ 0x80 |
| 112 | #define FLAG_BIGRAM_CHILDEXIST 0x40 |
| 113 | #define FLAG_BIGRAM_CONTINUED 0x80 |
| 114 | #define FLAG_BIGRAM_FREQ 0x7F |
| 115 | |
| 116 | #define DICTIONARY_VERSION_MIN 200 |
| 117 | #define DICTIONARY_HEADER_SIZE 2 |
| 118 | #define NOT_VALID_WORD -99 |
| 119 | |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 120 | #define SUGGEST_WORDS_WITH_MISSING_CHARACTER true |
| 121 | #define SUGGEST_WORDS_WITH_MISSING_SPACE_CHARACTER true |
| 122 | #define SUGGEST_WORDS_WITH_EXCESSIVE_CHARACTER true |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 123 | #define SUGGEST_WORDS_WITH_TRANSPOSED_CHARACTERS true |
| 124 | |
| 125 | #define WORDS_WITH_MISSING_CHARACTER_DEMOTION_RATE 75 |
| 126 | #define WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE 80 |
| 127 | #define WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE 75 |
satok | 54fe9e0 | 2010-12-13 14:42:35 +0900 | [diff] [blame] | 128 | #define WORDS_WITH_EXCESSIVE_CHARACTER_OUT_OF_PROXIMITY_DEMOTION_RATE 75 |
satok | a3d78f6 | 2010-12-09 22:08:33 +0900 | [diff] [blame] | 129 | #define WORDS_WITH_TRANSPOSED_CHARACTERS_DEMOTION_RATE 60 |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 130 | |
satok | f5cded1 | 2010-12-06 21:28:24 +0900 | [diff] [blame] | 131 | // This should be greater than or equal to MAX_WORD_LENGTH defined in BinaryDictionary.java |
| 132 | // This is only used for the size of array. Not to be used in c functions. |
| 133 | #define MAX_WORD_LENGTH_INTERNAL 48 |
satok | 715514d | 2010-12-02 20:19:59 +0900 | [diff] [blame] | 134 | |
satok | 6831926 | 2010-12-03 19:38:08 +0900 | [diff] [blame] | 135 | #define MAX_DEPTH_MULTIPLIER 3 |
| 136 | |
satok | 54fe9e0 | 2010-12-13 14:42:35 +0900 | [diff] [blame] | 137 | // Minimum suggest depth for one word for all cases except for missing space suggestions. |
| 138 | #define MIN_SUGGEST_DEPTH 1 |
| 139 | #define MIN_USER_TYPED_LENGTH_FOR_MISSING_SPACE_SUGGESTION 3 |
| 140 | #define MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION 3 |
satok | 662fe69 | 2010-12-08 17:05:39 +0900 | [diff] [blame] | 141 | |
satok | f5cded1 | 2010-12-06 21:28:24 +0900 | [diff] [blame] | 142 | #define min(a,b) ((a)<(b)?(a):(b)) |
| 143 | |
satok | e808e43 | 2010-12-02 14:53:24 +0900 | [diff] [blame] | 144 | #endif // LATINIME_DEFINES_H |