blob: 0286365bcd45b6ce0f936c523e7b7726e836e44c [file] [log] [blame]
satoke808e432010-12-02 14:53:24 +09001/*
Ken Wakasa5460ea32012-07-30 16:27:44 +09002 * Copyright (C) 2010, The Android Open Source Project
Ken Wakasa0bbb9172012-07-25 17:51:43 +09003 *
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 */
satoke808e432010-12-02 14:53:24 +090016
17#ifndef LATINIME_DEFINES_H
18#define LATINIME_DEFINES_H
19
Ken Wakasaf2789812012-09-04 12:49:46 +090020#include <stdint.h>
21
satok827ced82011-07-14 09:01:09 +090022#if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
Ken Wakasae3f26dd2012-07-27 18:06:06 +090023#include <android/log.h>
24#ifndef LOG_TAG
25#define LOG_TAG "LatinIME: "
26#endif
27#define AKLOGE(fmt, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##__VA_ARGS__)
28#define AKLOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##__VA_ARGS__)
satok6ad15fc2012-01-16 16:21:21 +090029
Satoshi Kataoka586b0ca2012-08-06 11:20:54 +090030#define DUMP_RESULT(words, frequencies, maxWordCount, maxWordLength) do { \
Ken Wakasaf2789812012-09-04 12:49:46 +090031 dumpResult(words, frequencies, maxWordCount, maxWordLength); } while (0)
32#define DUMP_WORD(word, length) do { dumpWord(word, length); } while (0)
33#define DUMP_WORD_INT(word, length) do { dumpWordInt(word, length); } while (0)
satok6ad15fc2012-01-16 16:21:21 +090034
Satoshi Kataoka586b0ca2012-08-06 11:20:54 +090035static inline void dumpWordInfo(const unsigned short *word, const int length,
36 const int rank, const int frequency) {
37 static char charBuf[50];
38 int i = 0;
39 for (; i < length; ++i) {
40 const unsigned short c = word[i];
41 if (c == 0) {
42 break;
43 }
Ken Wakasaf2789812012-09-04 12:49:46 +090044 // static_cast only for debugging
45 charBuf[i] = static_cast<char>(c);
Satoshi Kataoka586b0ca2012-08-06 11:20:54 +090046 }
47 charBuf[i] = 0;
48 if (i > 1) {
49 AKLOGI("%2d [ %s ] (%d)", rank, charBuf, frequency);
50 }
51}
52
53static inline void dumpResult(
54 const unsigned short *outWords, const int *frequencies, const int maxWordCounts,
55 const int maxWordLength) {
56 AKLOGI("--- DUMP RESULT ---------");
57 for (int i = 0; i < maxWordCounts; ++i) {
58 dumpWordInfo(&outWords[i * maxWordLength], maxWordLength, i, frequencies[i]);
59 }
60 AKLOGI("-------------------------");
61}
62
Ken Wakasa0bbb9172012-07-25 17:51:43 +090063static inline void dumpWord(const unsigned short *word, const int length) {
Tadashi G. Takaokad1dbdb62012-03-06 15:35:46 +090064 static char charBuf[50];
Satoshi Kataoka586b0ca2012-08-06 11:20:54 +090065 int i = 0;
66 for (; i < length; ++i) {
67 const unsigned short c = word[i];
68 if (c == 0) {
69 break;
70 }
Ken Wakasaf2789812012-09-04 12:49:46 +090071 // static_cast only for debugging
72 charBuf[i] = static_cast<char>(c);
satok6ad15fc2012-01-16 16:21:21 +090073 }
Satoshi Kataoka586b0ca2012-08-06 11:20:54 +090074 charBuf[i] = 0;
75 if (i > 1) {
76 AKLOGI("[ %s ]", charBuf);
77 }
satok6ad15fc2012-01-16 16:21:21 +090078}
79
Ken Wakasa0bbb9172012-07-25 17:51:43 +090080static inline void dumpWordInt(const int *word, const int length) {
Satoshi Kataoka6cbe2042012-05-30 17:28:34 +090081 static char charBuf[50];
82
83 for (int i = 0; i < length; ++i) {
84 charBuf[i] = word[i];
85 }
86 charBuf[length] = 0;
87 AKLOGI("i[ %s ]", charBuf);
88}
89
Satoshi Kataoka5540acb2012-09-03 18:35:32 +090090#ifndef __ANDROID__
Ken Wakasaf2789812012-09-04 12:49:46 +090091#define ASSERT(success) do { if (!success) { showStackTrace(); assert(success);};} while (0)
Satoshi Kataoka5540acb2012-09-03 18:35:32 +090092#define SHOW_STACK_TRACE do { showStackTrace(); } while (0)
93
94#include <execinfo.h>
95#include <stdlib.h>
96static inline void showStackTrace() {
97 void *callstack[128];
98 int i, frames = backtrace(callstack, 128);
99 char **strs = backtrace_symbols(callstack, frames);
100 for (i = 0; i < frames; ++i) {
101 if (i == 0) {
102 AKLOGI("=== Trace ===");
103 continue;
104 }
105 AKLOGI("%s", strs[i]);
106 }
107 free(strs);
108}
109#else
110#define ASSERT(success)
111#define SHOW_STACK_TRACE
112#endif
113
satok827ced82011-07-14 09:01:09 +0900114#else
satok9fb6f472012-01-13 18:01:22 +0900115#define AKLOGE(fmt, ...)
116#define AKLOGI(fmt, ...)
Satoshi Kataoka586b0ca2012-08-06 11:20:54 +0900117#define DUMP_RESULT(words, frequencies, maxWordCount, maxWordLength)
satok6ad15fc2012-01-16 16:21:21 +0900118#define DUMP_WORD(word, length)
Satoshi Kataoka6cbe2042012-05-30 17:28:34 +0900119#define DUMP_WORD_INT(word, length)
Satoshi Kataoka5540acb2012-09-03 18:35:32 +0900120#define ASSERT(success)
121#define SHOW_STACK_TRACE
satok827ced82011-07-14 09:01:09 +0900122#endif
123
satok20d9fda2011-07-13 14:40:30 +0900124#ifdef FLAG_DO_PROFILE
satok61e2f852011-01-05 14:13:07 +0900125// Profiler
126#include <time.h>
satok9fb6f472012-01-13 18:01:22 +0900127
satok61e2f852011-01-05 14:13:07 +0900128#define PROF_BUF_SIZE 100
satok0028ed32012-05-16 20:42:12 +0900129static float profile_buf[PROF_BUF_SIZE];
130static float profile_old[PROF_BUF_SIZE];
satok61e2f852011-01-05 14:13:07 +0900131static unsigned int profile_counter[PROF_BUF_SIZE];
132
Ken Wakasae90b3332011-01-07 15:01:51 +0900133#define PROF_RESET prof_reset()
134#define PROF_COUNT(prof_buf_id) ++profile_counter[prof_buf_id]
Ken Wakasaf2789812012-09-04 12:49:46 +0900135#define PROF_OPEN do { PROF_RESET; PROF_START(PROF_BUF_SIZE - 1); } while (0)
Ken Wakasae90b3332011-01-07 15:01:51 +0900136#define PROF_START(prof_buf_id) do { \
Ken Wakasaf2789812012-09-04 12:49:46 +0900137 PROF_COUNT(prof_buf_id); profile_old[prof_buf_id] = (clock()); } while (0)
138#define PROF_CLOSE do { PROF_END(PROF_BUF_SIZE - 1); PROF_OUTALL; } while (0)
Ken Wakasae90b3332011-01-07 15:01:51 +0900139#define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id])
140#define PROF_CLOCKOUT(prof_buf_id) \
satok9fb6f472012-01-13 18:01:22 +0900141 AKLOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id]))
Ken Wakasaf2789812012-09-04 12:49:46 +0900142#define PROF_OUTALL do { AKLOGI("--- %s ---", __FUNCTION__); prof_out(); } while (0)
satok61e2f852011-01-05 14:13:07 +0900143
Tadashi G. Takaokad1dbdb62012-03-06 15:35:46 +0900144static inline void prof_reset(void) {
Ken Wakasae90b3332011-01-07 15:01:51 +0900145 for (int i = 0; i < PROF_BUF_SIZE; ++i) {
satok61e2f852011-01-05 14:13:07 +0900146 profile_buf[i] = 0;
147 profile_old[i] = 0;
148 profile_counter[i] = 0;
149 }
150}
151
Tadashi G. Takaokad1dbdb62012-03-06 15:35:46 +0900152static inline void prof_out(void) {
satok61e2f852011-01-05 14:13:07 +0900153 if (profile_counter[PROF_BUF_SIZE - 1] != 1) {
satok9fb6f472012-01-13 18:01:22 +0900154 AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
satok61e2f852011-01-05 14:13:07 +0900155 }
satok9fb6f472012-01-13 18:01:22 +0900156 AKLOGI("Total time is %6.3f ms.",
Ken Wakasa77e8e812012-08-02 19:48:08 +0900157 profile_buf[PROF_BUF_SIZE - 1] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC));
satok0028ed32012-05-16 20:42:12 +0900158 float all = 0;
Ken Wakasae90b3332011-01-07 15:01:51 +0900159 for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
satok61e2f852011-01-05 14:13:07 +0900160 all += profile_buf[i];
161 }
Ken Wakasae90b3332011-01-07 15:01:51 +0900162 if (all == 0) all = 1;
163 for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
Ken Wakasa5460ea32012-07-30 16:27:44 +0900164 if (profile_buf[i]) {
satok9fb6f472012-01-13 18:01:22 +0900165 AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
Ken Wakasae90b3332011-01-07 15:01:51 +0900166 i, (profile_buf[i] * 100 / all),
Ken Wakasa77e8e812012-08-02 19:48:08 +0900167 profile_buf[i] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC),
168 profile_counter[i]);
Ken Wakasae90b3332011-01-07 15:01:51 +0900169 }
satok61e2f852011-01-05 14:13:07 +0900170 }
171}
172
satok20d9fda2011-07-13 14:40:30 +0900173#else // FLAG_DO_PROFILE
satok61e2f852011-01-05 14:13:07 +0900174#define PROF_BUF_SIZE 0
175#define PROF_RESET
176#define PROF_COUNT(prof_buf_id)
177#define PROF_OPEN
178#define PROF_START(prof_buf_id)
179#define PROF_CLOSE
180#define PROF_END(prof_buf_id)
181#define PROF_CLOCK_OUT(prof_buf_id)
182#define PROF_CLOCKOUT(prof_buf_id)
183#define PROF_OUTALL
184
satok20d9fda2011-07-13 14:40:30 +0900185#endif // FLAG_DO_PROFILE
186
187#ifdef FLAG_DBG
satok20d9fda2011-07-13 14:40:30 +0900188#define DEBUG_DICT true
189#define DEBUG_DICT_FULL false
satok0cedd2b2011-08-12 01:05:27 +0900190#define DEBUG_EDIT_DISTANCE false
satok10266c02011-08-19 22:05:59 +0900191#define DEBUG_SHOW_FOUND_WORD false
satok20d9fda2011-07-13 14:40:30 +0900192#define DEBUG_NODE DEBUG_DICT_FULL
193#define DEBUG_TRACE DEBUG_DICT_FULL
satok1a6da632011-12-16 23:15:06 +0900194#define DEBUG_PROXIMITY_INFO false
satok0cb20972012-03-13 22:07:56 +0900195#define DEBUG_PROXIMITY_CHARS false
satok10266c02011-08-19 22:05:59 +0900196#define DEBUG_CORRECTION false
satok29dc8062012-01-17 15:59:15 +0900197#define DEBUG_CORRECTION_FREQ false
198#define DEBUG_WORDS_PRIORITY_QUEUE false
satok20d9fda2011-07-13 14:40:30 +0900199
200#else // FLAG_DBG
satok827ced82011-07-14 09:01:09 +0900201
satok20d9fda2011-07-13 14:40:30 +0900202#define DEBUG_DICT false
203#define DEBUG_DICT_FULL false
satok0cedd2b2011-08-12 01:05:27 +0900204#define DEBUG_EDIT_DISTANCE false
satok20d9fda2011-07-13 14:40:30 +0900205#define DEBUG_SHOW_FOUND_WORD false
206#define DEBUG_NODE false
207#define DEBUG_TRACE false
208#define DEBUG_PROXIMITY_INFO false
satok0cb20972012-03-13 22:07:56 +0900209#define DEBUG_PROXIMITY_CHARS false
satok10266c02011-08-19 22:05:59 +0900210#define DEBUG_CORRECTION false
211#define DEBUG_CORRECTION_FREQ false
satok16379df2011-12-12 20:53:22 +0900212#define DEBUG_WORDS_PRIORITY_QUEUE false
satok20d9fda2011-07-13 14:40:30 +0900213
satoke808e432010-12-02 14:53:24 +0900214#endif // FLAG_DBG
215
satok662fe692010-12-08 17:05:39 +0900216#ifndef U_SHORT_MAX
Yusuke Nojima63095932011-09-20 14:03:42 +0900217#define U_SHORT_MAX 65535 // ((1 << 16) - 1)
satok662fe692010-12-08 17:05:39 +0900218#endif
Jean Chalarda5d58492011-02-18 17:50:58 +0900219#ifndef S_INT_MAX
satok3c4bb772011-03-04 22:50:19 -0800220#define S_INT_MAX 2147483647 // ((1 << 31) - 1)
Jean Chalarda5d58492011-02-18 17:50:58 +0900221#endif
satok662fe692010-12-08 17:05:39 +0900222
Ken Wakasae90b3332011-01-07 15:01:51 +0900223// Define this to use mmap() for dictionary loading. Undefine to use malloc() instead of mmap().
224// We measured and compared performance of both, and found mmap() is fairly good in terms of
225// loading time, and acceptable even for several initial lookups which involve page faults.
226#define USE_MMAP_FOR_DICTIONARY
227
satoke808e432010-12-02 14:53:24 +0900228// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
229#define ADDRESS_MASK 0x3FFFFF
230
231// The bit that decides if an address follows in the next 22 bits
232#define FLAG_ADDRESS_MASK 0x40
233// The bit that decides if this is a terminal node for a word. The node could still have children,
234// if the word has other endings.
235#define FLAG_TERMINAL_MASK 0x80
236
237#define FLAG_BIGRAM_READ 0x80
238#define FLAG_BIGRAM_CHILDEXIST 0x40
239#define FLAG_BIGRAM_CONTINUED 0x80
240#define FLAG_BIGRAM_FREQ 0x7F
241
242#define DICTIONARY_VERSION_MIN 200
Ken Wakasaf2789812012-09-04 12:49:46 +0900243#define NOT_VALID_WORD (-99)
244#define NOT_A_CODE_POINT (-1)
245#define NOT_A_DISTANCE (-1)
246#define NOT_A_COORDINATE (-1)
247#define EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO (-2)
248#define PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO (-3)
249#define ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO (-4)
250#define NOT_AN_INDEX (-1)
251#define NOT_A_PROBABILITY (-1)
satoke808e432010-12-02 14:53:24 +0900252
satok817e5172011-03-04 06:06:45 -0800253#define KEYCODE_SPACE ' '
254
Yusuke Nojimaafb90762011-10-05 18:11:42 +0900255#define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900256
satok662fe692010-12-08 17:05:39 +0900257#define SUGGEST_WORDS_WITH_MISSING_CHARACTER true
satok662fe692010-12-08 17:05:39 +0900258#define SUGGEST_WORDS_WITH_EXCESSIVE_CHARACTER true
satoka3d78f62010-12-09 22:08:33 +0900259#define SUGGEST_WORDS_WITH_TRANSPOSED_CHARACTERS true
satok99557162012-01-26 22:49:13 +0900260#define SUGGEST_MULTIPLE_WORDS true
satoka3d78f62010-12-09 22:08:33 +0900261
Jean Chalard8dc754a2011-01-27 14:20:22 +0900262// The following "rate"s are used as a multiplier before dividing by 100, so they are in percent.
satok72bc17e2011-04-13 17:23:27 +0900263#define WORDS_WITH_MISSING_CHARACTER_DEMOTION_RATE 80
satokdc5301e2011-04-11 16:14:45 +0900264#define WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X 12
satok54af64a2012-01-17 15:58:23 +0900265#define WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE 58
satok8330b482012-01-23 16:52:37 +0900266#define WORDS_WITH_MISTYPED_SPACE_DEMOTION_RATE 50
satoka3d78f62010-12-09 22:08:33 +0900267#define WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE 75
satok54fe9e02010-12-13 14:42:35 +0900268#define WORDS_WITH_EXCESSIVE_CHARACTER_OUT_OF_PROXIMITY_DEMOTION_RATE 75
satoka161a4a2012-01-16 18:38:32 +0900269#define WORDS_WITH_TRANSPOSED_CHARACTERS_DEMOTION_RATE 70
satok58c49b92011-01-27 03:23:39 +0900270#define FULL_MATCHED_WORDS_PROMOTION_RATE 120
satok9d2a3022011-04-14 19:13:34 +0900271#define WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE 90
satok1b9fa942012-02-02 18:49:22 +0900272#define WORDS_WITH_ADDITIONAL_PROXIMITY_CHARACTER_DEMOTION_RATE 70
satok635f68e2011-08-10 22:19:33 +0900273#define WORDS_WITH_MATCH_SKIP_PROMOTION_RATE 105
satok1b9fa942012-02-02 18:49:22 +0900274#define WORDS_WITH_JUST_ONE_CORRECTION_PROMOTION_RATE 148
275#define WORDS_WITH_JUST_ONE_CORRECTION_PROMOTION_MULTIPLIER 3
satok10266c02011-08-19 22:05:59 +0900276#define CORRECTION_COUNT_RATE_DEMOTION_RATE_BASE 45
277#define INPUT_EXCEEDS_OUTPUT_DEMOTION_RATE 70
278#define FIRST_CHAR_DIFFERENT_DEMOTION_RATE 96
satokeb050fc2011-10-03 19:21:13 +0900279#define TWO_WORDS_CAPITALIZED_DEMOTION_RATE 50
satok54af64a2012-01-17 15:58:23 +0900280#define TWO_WORDS_CORRECTION_DEMOTION_BASE 80
281#define TWO_WORDS_PLUS_OTHER_ERROR_CORRECTION_DEMOTION_DIVIDER 1
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900282#define ZERO_DISTANCE_PROMOTION_RATE 110
283#define NEUTRAL_SCORE_SQUARED_RADIUS 8.0f
284#define HALF_SCORE_SQUARED_RADIUS 32.0f
satoka85f4922012-01-30 18:18:30 +0900285#define MAX_FREQ 255
Jean Chalard9416c812012-05-15 19:24:47 +0900286#define MAX_BIGRAM_FREQ 15
satoke808e432010-12-02 14:53:24 +0900287
satok1147c7b2011-12-14 15:04:58 +0900288// This must be greater than or equal to MAX_WORD_LENGTH defined in BinaryDictionary.java
satokf5cded12010-12-06 21:28:24 +0900289// This is only used for the size of array. Not to be used in c functions.
290#define MAX_WORD_LENGTH_INTERNAL 48
satok715514d2010-12-02 20:19:59 +0900291
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +0900292// This must be the same as ProximityInfo#MAX_PROXIMITY_CHARS_SIZE, currently it's 16.
293#define MAX_PROXIMITY_CHARS_SIZE_INTERNAL 16
294
satoke05b3f42012-01-31 17:15:43 +0900295// This must be equal to ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE in KeyDetector.java
296#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2
297
Ken Wakasa9e0c7112012-08-09 22:26:58 +0900298// Assuming locale strings such as en_US, sr-Latn etc.
299#define MAX_LOCALE_STRING_LENGTH 10
300
satoka7e5a5a2011-12-15 16:49:12 +0900301// Word limit for sub queues used in WordsPriorityQueuePool. Sub queues are temporary queues used
302// for better performance.
satok6ad15fc2012-01-16 16:21:21 +0900303// Holds up to 1 candidate for each word
304#define SUB_QUEUE_MAX_WORDS 1
satokb9604772012-01-13 15:41:17 +0900305#define SUB_QUEUE_MAX_COUNT 10
satok54af64a2012-01-17 15:58:23 +0900306#define SUB_QUEUE_MIN_WORD_LENGTH 4
Satoshi Kataoka67e3cc82012-05-31 15:04:58 +0900307// TODO: Extend this limitation
308#define MULTIPLE_WORDS_SUGGESTION_MAX_WORDS 5
Satoshi Kataoka6cbe2042012-05-30 17:28:34 +0900309// TODO: Remove this limitation
310#define MULTIPLE_WORDS_SUGGESTION_MAX_WORD_LENGTH 12
311// TODO: Remove this limitation
Satoshi Kataoka67e3cc82012-05-31 15:04:58 +0900312#define MULTIPLE_WORDS_SUGGESTION_MAX_TOTAL_TRAVERSE_COUNT 45
satoka85f4922012-01-30 18:18:30 +0900313#define MULTIPLE_WORDS_DEMOTION_RATE 80
314#define MIN_INPUT_LENGTH_FOR_THREE_OR_MORE_WORDS_CORRECTION 6
satoka7e5a5a2011-12-15 16:49:12 +0900315
Jean Chalard9416c812012-05-15 19:24:47 +0900316#define TWO_WORDS_CORRECTION_WITH_OTHER_ERROR_THRESHOLD 0.35
317#define START_TWO_WORDS_CORRECTION_THRESHOLD 0.185
satoka0ac31f2012-05-23 19:55:27 +0900318/* heuristic... This should be changed if we change the unit of the frequency. */
319#define SUPPRESS_SHORT_MULTIPLE_WORDS_THRESHOLD_FREQ (MAX_FREQ * 58 / 100)
satok29dc8062012-01-17 15:59:15 +0900320
satok68319262010-12-03 19:38:08 +0900321#define MAX_DEPTH_MULTIPLIER 3
322
satok1f6b52e2012-01-30 13:53:58 +0900323#define FIRST_WORD_INDEX 0
satok8330b482012-01-23 16:52:37 +0900324
Satoshi Kataoka712e02f2012-06-28 15:13:57 +0900325#define MAX_SPACES_INTERNAL 16
326
Satoshi Kataoka687a2442012-08-23 15:46:43 +0900327// Max Distance between point to key
328#define MAX_POINT_TO_KEY_LENGTH 10000000
329
Keisuke Kuroyanagi95a49a52012-09-04 17:00:24 +0900330// The max number of the keys in one keyboard layout
331#define MAX_KEY_COUNT_IN_A_KEYBOARD 64
332
Jean Chalard6c300612012-03-06 19:54:03 +0900333// TODO: Reduce this constant if possible; check the maximum number of digraphs in the same
334// word in the dictionary for languages with digraphs, like German and French
335#define DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH 5
Jean Chalarda787dba2011-03-04 12:17:48 +0900336
satok99557162012-01-26 22:49:13 +0900337#define MIN_USER_TYPED_LENGTH_FOR_MULTIPLE_WORD_SUGGESTION 3
satok54fe9e02010-12-13 14:42:35 +0900338#define MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION 3
satok662fe692010-12-08 17:05:39 +0900339
Jean Chalardf1634c82012-05-02 19:05:27 +0900340// Size, in bytes, of the bloom filter index for bigrams
341// 128 gives us 1024 buckets. The probability of false positive is (1 - e ** (-kn/m))**k,
342// where k is the number of hash functions, n the number of bigrams, and m the number of
343// bits we can test.
344// At the moment 100 is the maximum number of bigrams for a word with the current
345// dictionaries, so n = 100. 1024 buckets give us m = 1024.
346// With 1 hash function, our false positive rate is about 9.3%, which should be enough for
347// our uses since we are only using this to increase average performance. For the record,
348// k = 2 gives 3.1% and k = 3 gives 1.6%. With k = 1, making m = 2048 gives 4.8%,
349// and m = 4096 gives 2.4%.
350#define BIGRAM_FILTER_BYTE_SIZE 128
351// Must be smaller than BIGRAM_FILTER_BYTE_SIZE * 8, and preferably prime. 1021 is the largest
352// prime under 128 * 8.
353#define BIGRAM_FILTER_MODULO 1021
354#if BIGRAM_FILTER_BYTE_SIZE * 8 < BIGRAM_FILTER_MODULO
355#error "BIGRAM_FILTER_MODULO is larger than BIGRAM_FILTER_BYTE_SIZE"
356#endif
357
Tadashi G. Takaoka09baa362012-02-03 21:24:53 +0900358template<typename T> inline T min(T a, T b) { return a < b ? a : b; }
359template<typename T> inline T max(T a, T b) { return a > b ? a : b; }
satokf5cded12010-12-06 21:28:24 +0900360
Yusuke Nojima258bfe62011-09-28 12:59:43 +0900361// The ratio of neutral area radius to sweet spot radius.
362#define NEUTRAL_AREA_RADIUS_RATIO 1.3f
363
satoke05b3f42012-01-31 17:15:43 +0900364// DEBUG
Ken Wakasaf2789812012-09-04 12:49:46 +0900365#define INPUTLENGTH_FOR_DEBUG (-1)
366#define MIN_OUTPUT_INDEX_FOR_DEBUG (-1)
satoke05b3f42012-01-31 17:15:43 +0900367
satok1bc038c2012-06-14 11:25:50 -0700368#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
369 TypeName(const TypeName&); \
370 void operator=(const TypeName&)
371
372#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
373 TypeName(); \
374 DISALLOW_COPY_AND_ASSIGN(TypeName)
375
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +0900376// Used as a return value for character comparison
377typedef enum {
378 // Same char, possibly with different case or accent
379 EQUIVALENT_CHAR,
380 // It is a char located nearby on the keyboard
381 NEAR_PROXIMITY_CHAR,
382 // It is an unrelated char
383 UNRELATED_CHAR,
384 // Additional proximity char which can differ by language.
385 ADDITIONAL_PROXIMITY_CHAR
386} ProximityType;
satoke808e432010-12-02 14:53:24 +0900387#endif // LATINIME_DEFINES_H