2010-12-02 05:53:24 +00:00
|
|
|
/*
|
|
|
|
**
|
|
|
|
** Copyright 2010, The Android Open Source Project
|
|
|
|
**
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LATINIME_DEFINES_H
|
|
|
|
#define LATINIME_DEFINES_H
|
|
|
|
|
2011-07-14 00:01:09 +00:00
|
|
|
#if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
|
|
|
|
#include <cutils/log.h>
|
|
|
|
#else
|
|
|
|
#define LOGE(fmt, ...)
|
|
|
|
#define LOGI(fmt, ...)
|
|
|
|
#endif
|
|
|
|
|
2011-07-13 05:40:30 +00:00
|
|
|
#ifdef FLAG_DO_PROFILE
|
2011-01-05 05:13:07 +00:00
|
|
|
// Profiler
|
2011-07-13 23:32:57 +00:00
|
|
|
#include <cutils/log.h>
|
2011-01-05 05:13:07 +00:00
|
|
|
#include <time.h>
|
|
|
|
#define PROF_BUF_SIZE 100
|
|
|
|
static double profile_buf[PROF_BUF_SIZE];
|
|
|
|
static double profile_old[PROF_BUF_SIZE];
|
|
|
|
static unsigned int profile_counter[PROF_BUF_SIZE];
|
|
|
|
|
2011-01-07 06:01:51 +00:00
|
|
|
#define PROF_RESET prof_reset()
|
|
|
|
#define PROF_COUNT(prof_buf_id) ++profile_counter[prof_buf_id]
|
|
|
|
#define PROF_OPEN do { PROF_RESET; PROF_START(PROF_BUF_SIZE - 1); } while(0)
|
|
|
|
#define PROF_START(prof_buf_id) do { \
|
|
|
|
PROF_COUNT(prof_buf_id); profile_old[prof_buf_id] = (clock()); } while(0)
|
|
|
|
#define PROF_CLOSE do { PROF_END(PROF_BUF_SIZE - 1); PROF_OUTALL; } while(0)
|
|
|
|
#define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id])
|
|
|
|
#define PROF_CLOCKOUT(prof_buf_id) \
|
|
|
|
LOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id]))
|
|
|
|
#define PROF_OUTALL do { LOGI("--- %s ---", __FUNCTION__); prof_out(); } while(0)
|
|
|
|
|
|
|
|
static void prof_reset(void) {
|
|
|
|
for (int i = 0; i < PROF_BUF_SIZE; ++i) {
|
2011-01-05 05:13:07 +00:00
|
|
|
profile_buf[i] = 0;
|
|
|
|
profile_old[i] = 0;
|
|
|
|
profile_counter[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 06:01:51 +00:00
|
|
|
static void prof_out(void) {
|
2011-01-05 05:13:07 +00:00
|
|
|
if (profile_counter[PROF_BUF_SIZE - 1] != 1) {
|
|
|
|
LOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
|
|
|
|
}
|
|
|
|
LOGI("Total time is %6.3f ms.",
|
2011-01-07 06:01:51 +00:00
|
|
|
profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC);
|
2011-01-05 05:13:07 +00:00
|
|
|
double all = 0;
|
2011-01-07 06:01:51 +00:00
|
|
|
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
|
2011-01-05 05:13:07 +00:00
|
|
|
all += profile_buf[i];
|
|
|
|
}
|
2011-01-07 06:01:51 +00:00
|
|
|
if (all == 0) all = 1;
|
|
|
|
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
|
|
|
|
if (profile_buf[i] != 0) {
|
2011-01-05 05:13:07 +00:00
|
|
|
LOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
|
2011-01-07 06:01:51 +00:00
|
|
|
i, (profile_buf[i] * 100 / all),
|
|
|
|
profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]);
|
|
|
|
}
|
2011-01-05 05:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 05:40:30 +00:00
|
|
|
#else // FLAG_DO_PROFILE
|
2011-01-05 05:13:07 +00:00
|
|
|
#define PROF_BUF_SIZE 0
|
|
|
|
#define PROF_RESET
|
|
|
|
#define PROF_COUNT(prof_buf_id)
|
|
|
|
#define PROF_OPEN
|
|
|
|
#define PROF_START(prof_buf_id)
|
|
|
|
#define PROF_CLOSE
|
|
|
|
#define PROF_END(prof_buf_id)
|
|
|
|
#define PROF_CLOCK_OUT(prof_buf_id)
|
|
|
|
#define PROF_CLOCKOUT(prof_buf_id)
|
|
|
|
#define PROF_OUTALL
|
|
|
|
|
2011-07-13 05:40:30 +00:00
|
|
|
#endif // FLAG_DO_PROFILE
|
|
|
|
|
|
|
|
#ifdef FLAG_DBG
|
|
|
|
#include <cutils/log.h>
|
|
|
|
#ifndef LOG_TAG
|
|
|
|
#define LOG_TAG "LatinIME: "
|
|
|
|
#endif
|
|
|
|
#define DEBUG_DICT true
|
|
|
|
#define DEBUG_DICT_FULL false
|
2011-08-11 16:05:27 +00:00
|
|
|
#define DEBUG_EDIT_DISTANCE false
|
2011-08-19 13:05:59 +00:00
|
|
|
#define DEBUG_SHOW_FOUND_WORD false
|
2011-07-13 05:40:30 +00:00
|
|
|
#define DEBUG_NODE DEBUG_DICT_FULL
|
|
|
|
#define DEBUG_TRACE DEBUG_DICT_FULL
|
|
|
|
#define DEBUG_PROXIMITY_INFO true
|
2011-08-19 13:05:59 +00:00
|
|
|
#define DEBUG_CORRECTION false
|
|
|
|
#define DEBUG_CORRECTION_FREQ true
|
2011-12-12 11:53:22 +00:00
|
|
|
#define DEBUG_WORDS_PRIORITY_QUEUE true
|
2011-07-13 05:40:30 +00:00
|
|
|
|
2011-08-11 16:05:27 +00:00
|
|
|
#define DUMP_WORD(word, length) do { dumpWord(word, length); } while(0)
|
|
|
|
|
|
|
|
static char charBuf[50];
|
|
|
|
|
|
|
|
static void dumpWord(const unsigned short* word, const int length) {
|
|
|
|
for (int i = 0; i < length; ++i) {
|
|
|
|
charBuf[i] = word[i];
|
|
|
|
}
|
|
|
|
charBuf[length] = 0;
|
|
|
|
LOGI("[ %s ]", charBuf);
|
|
|
|
}
|
|
|
|
|
2011-07-13 05:40:30 +00:00
|
|
|
#else // FLAG_DBG
|
2011-07-14 00:01:09 +00:00
|
|
|
|
2011-07-13 05:40:30 +00:00
|
|
|
#define DEBUG_DICT false
|
|
|
|
#define DEBUG_DICT_FULL false
|
2011-08-11 16:05:27 +00:00
|
|
|
#define DEBUG_EDIT_DISTANCE false
|
2011-07-13 05:40:30 +00:00
|
|
|
#define DEBUG_SHOW_FOUND_WORD false
|
|
|
|
#define DEBUG_NODE false
|
|
|
|
#define DEBUG_TRACE false
|
|
|
|
#define DEBUG_PROXIMITY_INFO false
|
2011-08-19 13:05:59 +00:00
|
|
|
#define DEBUG_CORRECTION false
|
|
|
|
#define DEBUG_CORRECTION_FREQ false
|
2011-12-12 11:53:22 +00:00
|
|
|
#define DEBUG_WORDS_PRIORITY_QUEUE false
|
2011-07-13 05:40:30 +00:00
|
|
|
|
2011-08-11 16:05:27 +00:00
|
|
|
#define DUMP_WORD(word, length)
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
#endif // FLAG_DBG
|
|
|
|
|
2010-12-08 08:05:39 +00:00
|
|
|
#ifndef U_SHORT_MAX
|
2011-09-20 05:03:42 +00:00
|
|
|
#define U_SHORT_MAX 65535 // ((1 << 16) - 1)
|
2010-12-08 08:05:39 +00:00
|
|
|
#endif
|
2011-02-18 08:50:58 +00:00
|
|
|
#ifndef S_INT_MAX
|
2011-03-05 06:50:19 +00:00
|
|
|
#define S_INT_MAX 2147483647 // ((1 << 31) - 1)
|
2011-02-18 08:50:58 +00:00
|
|
|
#endif
|
2010-12-08 08:05:39 +00:00
|
|
|
|
2011-01-07 06:01:51 +00:00
|
|
|
// Define this to use mmap() for dictionary loading. Undefine to use malloc() instead of mmap().
|
|
|
|
// We measured and compared performance of both, and found mmap() is fairly good in terms of
|
|
|
|
// loading time, and acceptable even for several initial lookups which involve page faults.
|
|
|
|
#define USE_MMAP_FOR_DICTIONARY
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
|
|
|
|
#define ADDRESS_MASK 0x3FFFFF
|
|
|
|
|
|
|
|
// The bit that decides if an address follows in the next 22 bits
|
|
|
|
#define FLAG_ADDRESS_MASK 0x40
|
|
|
|
// The bit that decides if this is a terminal node for a word. The node could still have children,
|
|
|
|
// if the word has other endings.
|
|
|
|
#define FLAG_TERMINAL_MASK 0x80
|
|
|
|
|
|
|
|
#define FLAG_BIGRAM_READ 0x80
|
|
|
|
#define FLAG_BIGRAM_CHILDEXIST 0x40
|
|
|
|
#define FLAG_BIGRAM_CONTINUED 0x80
|
|
|
|
#define FLAG_BIGRAM_FREQ 0x7F
|
|
|
|
|
|
|
|
#define DICTIONARY_VERSION_MIN 200
|
2011-06-28 11:45:05 +00:00
|
|
|
// TODO: remove this constant when the switch to the new dict format is over
|
2010-12-02 05:53:24 +00:00
|
|
|
#define DICTIONARY_HEADER_SIZE 2
|
2011-06-28 11:45:05 +00:00
|
|
|
#define NEW_DICTIONARY_HEADER_SIZE 5
|
2010-12-02 05:53:24 +00:00
|
|
|
#define NOT_VALID_WORD -99
|
2011-06-28 11:45:05 +00:00
|
|
|
#define NOT_A_CHARACTER -1
|
2011-10-05 05:55:07 +00:00
|
|
|
#define NOT_A_DISTANCE -1
|
2011-10-06 10:12:20 +00:00
|
|
|
#define EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO -2
|
|
|
|
#define PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO -3
|
|
|
|
#define NOT_A_INDEX -1
|
2010-12-02 05:53:24 +00:00
|
|
|
|
2011-03-04 14:06:45 +00:00
|
|
|
#define KEYCODE_SPACE ' '
|
|
|
|
|
2011-10-05 09:11:42 +00:00
|
|
|
#define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true
|
2011-09-28 03:59:43 +00:00
|
|
|
|
2010-12-08 08:05:39 +00:00
|
|
|
#define SUGGEST_WORDS_WITH_MISSING_CHARACTER true
|
|
|
|
#define SUGGEST_WORDS_WITH_MISSING_SPACE_CHARACTER true
|
|
|
|
#define SUGGEST_WORDS_WITH_EXCESSIVE_CHARACTER true
|
2010-12-09 13:08:33 +00:00
|
|
|
#define SUGGEST_WORDS_WITH_TRANSPOSED_CHARACTERS true
|
2011-03-04 14:06:45 +00:00
|
|
|
#define SUGGEST_WORDS_WITH_SPACE_PROXIMITY true
|
2010-12-09 13:08:33 +00:00
|
|
|
|
2011-01-27 05:20:22 +00:00
|
|
|
// The following "rate"s are used as a multiplier before dividing by 100, so they are in percent.
|
2011-04-13 08:23:27 +00:00
|
|
|
#define WORDS_WITH_MISSING_CHARACTER_DEMOTION_RATE 80
|
2011-04-11 07:14:45 +00:00
|
|
|
#define WORDS_WITH_MISSING_CHARACTER_DEMOTION_START_POS_10X 12
|
2011-05-24 05:28:13 +00:00
|
|
|
#define WORDS_WITH_MISSING_SPACE_CHARACTER_DEMOTION_RATE 67
|
2010-12-09 13:08:33 +00:00
|
|
|
#define WORDS_WITH_EXCESSIVE_CHARACTER_DEMOTION_RATE 75
|
2010-12-13 05:42:35 +00:00
|
|
|
#define WORDS_WITH_EXCESSIVE_CHARACTER_OUT_OF_PROXIMITY_DEMOTION_RATE 75
|
2010-12-09 13:08:33 +00:00
|
|
|
#define WORDS_WITH_TRANSPOSED_CHARACTERS_DEMOTION_RATE 60
|
2011-01-26 18:23:39 +00:00
|
|
|
#define FULL_MATCHED_WORDS_PROMOTION_RATE 120
|
2011-04-14 10:13:34 +00:00
|
|
|
#define WORDS_WITH_PROXIMITY_CHARACTER_DEMOTION_RATE 90
|
2011-08-10 13:19:33 +00:00
|
|
|
#define WORDS_WITH_MATCH_SKIP_PROMOTION_RATE 105
|
2011-08-15 13:30:33 +00:00
|
|
|
#define WORDS_WITH_JUST_ONE_CORRECTION_PROMOTION_RATE 160
|
2011-08-19 13:05:59 +00:00
|
|
|
#define CORRECTION_COUNT_RATE_DEMOTION_RATE_BASE 45
|
|
|
|
#define INPUT_EXCEEDS_OUTPUT_DEMOTION_RATE 70
|
|
|
|
#define FIRST_CHAR_DIFFERENT_DEMOTION_RATE 96
|
2011-10-03 10:21:13 +00:00
|
|
|
#define TWO_WORDS_CAPITALIZED_DEMOTION_RATE 50
|
2011-10-06 10:12:20 +00:00
|
|
|
#define ZERO_DISTANCE_PROMOTION_RATE 110
|
|
|
|
#define NEUTRAL_SCORE_SQUARED_RADIUS 8.0f
|
|
|
|
#define HALF_SCORE_SQUARED_RADIUS 32.0f
|
2010-12-02 05:53:24 +00:00
|
|
|
|
2011-12-14 06:04:58 +00:00
|
|
|
// This must be greater than or equal to MAX_WORD_LENGTH defined in BinaryDictionary.java
|
2010-12-06 12:28:24 +00:00
|
|
|
// This is only used for the size of array. Not to be used in c functions.
|
|
|
|
#define MAX_WORD_LENGTH_INTERNAL 48
|
2010-12-02 11:19:59 +00:00
|
|
|
|
2011-12-15 07:49:12 +00:00
|
|
|
// Word limit for sub queues used in WordsPriorityQueuePool. Sub queues are temporary queues used
|
|
|
|
// for better performance.
|
|
|
|
#define SUB_QUEUE_MAX_WORDS 5
|
|
|
|
|
2010-12-03 10:38:08 +00:00
|
|
|
#define MAX_DEPTH_MULTIPLIER 3
|
|
|
|
|
2011-03-04 03:17:48 +00:00
|
|
|
// TODO: Reduce this constant if possible; check the maximum number of umlauts in the same German
|
|
|
|
// word in the dictionary
|
|
|
|
#define DEFAULT_MAX_UMLAUT_SEARCH_DEPTH 5
|
|
|
|
|
2010-12-13 05:42:35 +00:00
|
|
|
// Minimum suggest depth for one word for all cases except for missing space suggestions.
|
|
|
|
#define MIN_SUGGEST_DEPTH 1
|
|
|
|
#define MIN_USER_TYPED_LENGTH_FOR_MISSING_SPACE_SUGGESTION 3
|
|
|
|
#define MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION 3
|
2010-12-08 08:05:39 +00:00
|
|
|
|
2010-12-06 12:28:24 +00:00
|
|
|
#define min(a,b) ((a)<(b)?(a):(b))
|
2011-08-15 13:30:33 +00:00
|
|
|
#define max(a,b) ((a)>(b)?(a):(b))
|
2010-12-06 12:28:24 +00:00
|
|
|
|
2011-09-28 03:59:43 +00:00
|
|
|
// The ratio of neutral area radius to sweet spot radius.
|
|
|
|
#define NEUTRAL_AREA_RADIUS_RATIO 1.3f
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
#endif // LATINIME_DEFINES_H
|