2010-12-02 05:53:24 +00:00
|
|
|
/*
|
2013-01-08 08:23:43 +00:00
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
2012-07-25 08:51:43 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2013-01-08 08:23:43 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-07-25 08:51:43 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-12-02 05:53:24 +00:00
|
|
|
|
|
|
|
#ifndef LATINIME_DEFINES_H
|
|
|
|
#define LATINIME_DEFINES_H
|
|
|
|
|
2012-11-15 10:09:11 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define AK_FORCE_INLINE __attribute__((always_inline)) __inline__
|
|
|
|
#else // __GNUC__
|
|
|
|
#define AK_FORCE_INLINE inline
|
|
|
|
#endif // __GNUC__
|
|
|
|
|
2013-01-15 07:15:48 +00:00
|
|
|
#if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
|
|
|
|
#undef AK_FORCE_INLINE
|
|
|
|
#define AK_FORCE_INLINE inline
|
|
|
|
#endif // defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
|
|
|
|
|
2013-01-22 04:14:53 +00:00
|
|
|
// Must be equal to Constants.Dictionary.MAX_WORD_LENGTH in Java
|
2013-01-11 16:18:00 +00:00
|
|
|
#define MAX_WORD_LENGTH 48
|
2013-01-22 04:14:53 +00:00
|
|
|
// Must be equal to BinaryDictionary.MAX_RESULTS in Java
|
2013-01-11 16:18:00 +00:00
|
|
|
#define MAX_RESULTS 18
|
2013-01-22 04:14:53 +00:00
|
|
|
// Must be equal to ProximityInfo.MAX_PROXIMITY_CHARS_SIZE in Java
|
|
|
|
#define MAX_PROXIMITY_CHARS_SIZE 16
|
|
|
|
#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2
|
2013-06-27 08:31:13 +00:00
|
|
|
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
|
2012-12-17 14:28:17 +00:00
|
|
|
|
2013-06-27 08:31:13 +00:00
|
|
|
AK_FORCE_INLINE static int intArrayToCharArray(const int *const source, const int sourceSize,
|
|
|
|
char *dest, const int destSize) {
|
|
|
|
// We want to always terminate with a 0 char, so stop one short of the length to make
|
|
|
|
// sure there is room.
|
|
|
|
const int destLimit = destSize - 1;
|
2012-12-17 14:28:17 +00:00
|
|
|
int si = 0;
|
|
|
|
int di = 0;
|
2013-06-27 08:31:13 +00:00
|
|
|
while (si < sourceSize && di < destLimit && 0 != source[si]) {
|
2012-12-17 14:28:17 +00:00
|
|
|
const int codePoint = source[si++];
|
2013-06-27 08:31:13 +00:00
|
|
|
if (codePoint < 0x7F) { // One byte
|
2012-12-17 14:28:17 +00:00
|
|
|
dest[di++] = codePoint;
|
2013-06-27 08:31:13 +00:00
|
|
|
} else if (codePoint < 0x7FF) { // Two bytes
|
|
|
|
if (di + 1 >= destLimit) break;
|
2012-12-17 14:28:17 +00:00
|
|
|
dest[di++] = 0xC0 + (codePoint >> 6);
|
|
|
|
dest[di++] = 0x80 + (codePoint & 0x3F);
|
2013-06-27 08:31:13 +00:00
|
|
|
} else if (codePoint < 0xFFFF) { // Three bytes
|
|
|
|
if (di + 2 >= destLimit) break;
|
2012-12-17 14:28:17 +00:00
|
|
|
dest[di++] = 0xE0 + (codePoint >> 12);
|
2013-06-27 08:31:13 +00:00
|
|
|
dest[di++] = 0x80 + ((codePoint >> 6) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + (codePoint & 0x3F);
|
|
|
|
} else if (codePoint <= 0x1FFFFF) { // Four bytes
|
|
|
|
if (di + 3 >= destLimit) break;
|
|
|
|
dest[di++] = 0xF0 + (codePoint >> 18);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 12) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 6) & 0x3F);
|
2012-12-17 14:28:17 +00:00
|
|
|
dest[di++] = 0x80 + (codePoint & 0x3F);
|
2013-06-27 08:31:13 +00:00
|
|
|
} else if (codePoint <= 0x3FFFFFF) { // Five bytes
|
|
|
|
if (di + 4 >= destLimit) break;
|
|
|
|
dest[di++] = 0xF8 + (codePoint >> 24);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 18) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 12) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 6) & 0x3F);
|
|
|
|
dest[di++] = codePoint & 0x3F;
|
|
|
|
} else if (codePoint <= 0x7FFFFFFF) { // Six bytes
|
|
|
|
if (di + 5 >= destLimit) break;
|
|
|
|
dest[di++] = 0xFC + (codePoint >> 30);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 24) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 18) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 12) & 0x3F);
|
|
|
|
dest[di++] = 0x80 + ((codePoint >> 6) & 0x3F);
|
|
|
|
dest[di++] = codePoint & 0x3F;
|
|
|
|
} else {
|
|
|
|
// Not a code point... skip.
|
2012-12-17 14:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dest[di] = 0;
|
|
|
|
return di;
|
|
|
|
}
|
|
|
|
|
2013-06-27 08:31:13 +00:00
|
|
|
#if defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
|
|
|
|
#include <android/log.h>
|
|
|
|
#ifndef LOG_TAG
|
|
|
|
#define LOG_TAG "LatinIME: "
|
|
|
|
#endif // LOG_TAG
|
|
|
|
#define AKLOGE(fmt, ...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, fmt, ##__VA_ARGS__)
|
|
|
|
#define AKLOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define DUMP_RESULT(words, frequencies) do { dumpResult(words, frequencies); } while (0)
|
|
|
|
#define DUMP_WORD(word, length) do { dumpWord(word, length); } while (0)
|
|
|
|
#define INTS_TO_CHARS(input, length, output, outlength) do { \
|
|
|
|
intArrayToCharArray(input, length, output, outlength); } while (0)
|
|
|
|
|
2012-10-29 09:06:22 +00:00
|
|
|
static inline void dumpWordInfo(const int *word, const int length, const int rank,
|
2013-03-18 04:08:31 +00:00
|
|
|
const int probability) {
|
2012-03-06 06:35:46 +00:00
|
|
|
static char charBuf[50];
|
2013-06-27 08:31:13 +00:00
|
|
|
const int N = intArrayToCharArray(word, length, charBuf, NELEMS(charBuf));
|
2012-12-17 14:28:17 +00:00
|
|
|
if (N > 1) {
|
2013-03-18 04:08:31 +00:00
|
|
|
AKLOGI("%2d [ %s ] (%d)", rank, charBuf, probability);
|
2012-08-06 02:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 07:21:21 +00:00
|
|
|
|
2013-01-11 16:18:00 +00:00
|
|
|
static inline void dumpResult(const int *outWords, const int *frequencies) {
|
2012-08-06 02:20:54 +00:00
|
|
|
AKLOGI("--- DUMP RESULT ---------");
|
2013-01-11 16:18:00 +00:00
|
|
|
for (int i = 0; i < MAX_RESULTS; ++i) {
|
|
|
|
dumpWordInfo(&outWords[i * MAX_WORD_LENGTH], MAX_WORD_LENGTH, i, frequencies[i]);
|
2012-08-06 02:20:54 +00:00
|
|
|
}
|
|
|
|
AKLOGI("-------------------------");
|
|
|
|
}
|
|
|
|
|
2012-11-15 10:09:11 +00:00
|
|
|
static AK_FORCE_INLINE void dumpWord(const int *word, const int length) {
|
2012-08-06 02:20:54 +00:00
|
|
|
static char charBuf[50];
|
2013-06-27 08:31:13 +00:00
|
|
|
const int N = intArrayToCharArray(word, length, charBuf, NELEMS(charBuf));
|
2012-12-17 14:28:17 +00:00
|
|
|
if (N > 1) {
|
2012-08-06 02:20:54 +00:00
|
|
|
AKLOGI("[ %s ]", charBuf);
|
2012-01-16 07:21:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-03 09:35:32 +00:00
|
|
|
#ifndef __ANDROID__
|
2012-09-06 12:31:54 +00:00
|
|
|
#include <cassert>
|
2012-09-03 09:35:32 +00:00
|
|
|
#include <execinfo.h>
|
|
|
|
#include <stdlib.h>
|
2012-09-06 12:31:54 +00:00
|
|
|
|
2013-01-09 03:54:39 +00:00
|
|
|
#define DO_ASSERT_TEST
|
2012-09-06 12:31:54 +00:00
|
|
|
#define ASSERT(success) do { if (!(success)) { showStackTrace(); assert(success);} } while (0)
|
|
|
|
#define SHOW_STACK_TRACE do { showStackTrace(); } while (0)
|
|
|
|
|
2012-09-03 09:35:32 +00:00
|
|
|
static inline void showStackTrace() {
|
|
|
|
void *callstack[128];
|
|
|
|
int i, frames = backtrace(callstack, 128);
|
|
|
|
char **strs = backtrace_symbols(callstack, frames);
|
|
|
|
for (i = 0; i < frames; ++i) {
|
|
|
|
if (i == 0) {
|
|
|
|
AKLOGI("=== Trace ===");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AKLOGI("%s", strs[i]);
|
|
|
|
}
|
|
|
|
free(strs);
|
|
|
|
}
|
2013-01-15 07:15:48 +00:00
|
|
|
#else // __ANDROID__
|
2012-09-06 12:31:54 +00:00
|
|
|
#include <cassert>
|
2013-01-09 03:54:39 +00:00
|
|
|
#define DO_ASSERT_TEST
|
2012-09-06 12:31:54 +00:00
|
|
|
#define ASSERT(success) assert(success)
|
2012-09-03 09:35:32 +00:00
|
|
|
#define SHOW_STACK_TRACE
|
2013-01-15 07:15:48 +00:00
|
|
|
#endif // __ANDROID__
|
2012-09-03 09:35:32 +00:00
|
|
|
|
2013-01-15 07:15:48 +00:00
|
|
|
#else // defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
|
2012-01-13 09:01:22 +00:00
|
|
|
#define AKLOGE(fmt, ...)
|
|
|
|
#define AKLOGI(fmt, ...)
|
2013-01-11 16:18:00 +00:00
|
|
|
#define DUMP_RESULT(words, frequencies)
|
2012-01-16 07:21:21 +00:00
|
|
|
#define DUMP_WORD(word, length)
|
2013-01-09 03:54:39 +00:00
|
|
|
#undef DO_ASSERT_TEST
|
2012-09-03 09:35:32 +00:00
|
|
|
#define ASSERT(success)
|
|
|
|
#define SHOW_STACK_TRACE
|
2012-10-29 09:06:22 +00:00
|
|
|
#define INTS_TO_CHARS(input, length, output)
|
2013-01-15 07:15:48 +00:00
|
|
|
#endif // defined(FLAG_DO_PROFILE) || defined(FLAG_DBG)
|
2011-07-14 00:01:09 +00:00
|
|
|
|
2011-07-13 05:40:30 +00:00
|
|
|
#ifdef FLAG_DO_PROFILE
|
2011-01-05 05:13:07 +00:00
|
|
|
// Profiler
|
|
|
|
#include <time.h>
|
2012-01-13 09:01:22 +00:00
|
|
|
|
2011-01-05 05:13:07 +00:00
|
|
|
#define PROF_BUF_SIZE 100
|
2012-05-16 11:42:12 +00:00
|
|
|
static float profile_buf[PROF_BUF_SIZE];
|
|
|
|
static float profile_old[PROF_BUF_SIZE];
|
2011-01-05 05:13:07 +00:00
|
|
|
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]
|
2012-09-04 03:49:46 +00:00
|
|
|
#define PROF_OPEN do { PROF_RESET; PROF_START(PROF_BUF_SIZE - 1); } while (0)
|
2011-01-07 06:01:51 +00:00
|
|
|
#define PROF_START(prof_buf_id) do { \
|
2012-09-04 03:49:46 +00:00
|
|
|
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)
|
2011-01-07 06:01:51 +00:00
|
|
|
#define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id])
|
|
|
|
#define PROF_CLOCKOUT(prof_buf_id) \
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id]))
|
2012-09-04 03:49:46 +00:00
|
|
|
#define PROF_OUTALL do { AKLOGI("--- %s ---", __FUNCTION__); prof_out(); } while (0)
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2012-03-06 06:35:46 +00:00
|
|
|
static inline void prof_reset(void) {
|
2011-01-07 06:01:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 06:35:46 +00:00
|
|
|
static inline void prof_out(void) {
|
2011-01-05 05:13:07 +00:00
|
|
|
if (profile_counter[PROF_BUF_SIZE - 1] != 1) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
|
2011-01-05 05:13:07 +00:00
|
|
|
}
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGI("Total time is %6.3f ms.",
|
2012-08-02 10:48:08 +00:00
|
|
|
profile_buf[PROF_BUF_SIZE - 1] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC));
|
2012-11-27 10:40:38 +00:00
|
|
|
float all = 0.0f;
|
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];
|
|
|
|
}
|
2012-11-27 10:40:38 +00:00
|
|
|
if (all < 1.0f) all = 1.0f;
|
2011-01-07 06:01:51 +00:00
|
|
|
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
|
2012-11-27 10:40:38 +00:00
|
|
|
if (profile_buf[i] > 0.0f) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
|
2012-11-27 10:40:38 +00:00
|
|
|
i, (profile_buf[i] * 100.0f / all),
|
2012-08-02 10:48:08 +00:00
|
|
|
profile_buf[i] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC),
|
|
|
|
profile_counter[i]);
|
2011-01-07 06:01:51 +00:00
|
|
|
}
|
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
|
|
|
|
#define DEBUG_DICT true
|
|
|
|
#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_NODE DEBUG_DICT_FULL
|
|
|
|
#define DEBUG_TRACE DEBUG_DICT_FULL
|
2011-12-16 14:15:06 +00:00
|
|
|
#define DEBUG_PROXIMITY_INFO false
|
2012-03-13 13:07:56 +00:00
|
|
|
#define DEBUG_PROXIMITY_CHARS false
|
2011-08-19 13:05:59 +00:00
|
|
|
#define DEBUG_CORRECTION false
|
2012-01-17 06:59:15 +00:00
|
|
|
#define DEBUG_CORRECTION_FREQ false
|
2012-12-04 07:28:06 +00:00
|
|
|
#define DEBUG_SAMPLING_POINTS false
|
|
|
|
#define DEBUG_POINTS_PROBABILITY false
|
|
|
|
#define DEBUG_DOUBLE_LETTER false
|
2013-02-21 12:54:21 +00:00
|
|
|
#define DEBUG_CACHE false
|
|
|
|
#define DEBUG_DUMP_ERROR false
|
2013-04-10 02:45:12 +00:00
|
|
|
#define DEBUG_EVALUATE_MOST_PROBABLE_STRING false
|
2011-07-13 05:40:30 +00:00
|
|
|
|
2012-09-11 06:51:38 +00:00
|
|
|
#ifdef FLAG_FULL_DBG
|
|
|
|
#define DEBUG_GEO_FULL true
|
|
|
|
#else
|
2012-09-10 08:59:17 +00:00
|
|
|
#define DEBUG_GEO_FULL false
|
2012-09-11 06:51:38 +00:00
|
|
|
#endif
|
2012-09-10 08:59:17 +00:00
|
|
|
|
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_NODE false
|
|
|
|
#define DEBUG_TRACE false
|
|
|
|
#define DEBUG_PROXIMITY_INFO false
|
2012-03-13 13:07:56 +00:00
|
|
|
#define DEBUG_PROXIMITY_CHARS false
|
2011-08-19 13:05:59 +00:00
|
|
|
#define DEBUG_CORRECTION false
|
|
|
|
#define DEBUG_CORRECTION_FREQ false
|
2012-10-09 10:57:08 +00:00
|
|
|
#define DEBUG_SAMPLING_POINTS false
|
|
|
|
#define DEBUG_POINTS_PROBABILITY false
|
2012-11-16 14:06:41 +00:00
|
|
|
#define DEBUG_DOUBLE_LETTER false
|
2013-02-21 12:54:21 +00:00
|
|
|
#define DEBUG_CACHE false
|
|
|
|
#define DEBUG_DUMP_ERROR false
|
2013-04-10 02:45:12 +00:00
|
|
|
#define DEBUG_EVALUATE_MOST_PROBABLE_STRING false
|
2011-07-13 05:40:30 +00:00
|
|
|
|
2012-09-10 08:59:17 +00:00
|
|
|
#define DEBUG_GEO_FULL false
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
#endif // FLAG_DBG
|
|
|
|
|
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
|
2012-11-20 12:19:26 +00:00
|
|
|
#ifndef S_INT_MIN
|
|
|
|
// The literal constant -2147483648 does not work in C prior C90, because
|
|
|
|
// the compiler tries to fit the positive number into an int and then negate it.
|
|
|
|
// GCC warns about this.
|
|
|
|
#define S_INT_MIN (-2147483647 - 1) // -(1 << 31)
|
|
|
|
#endif
|
2013-01-21 09:29:27 +00:00
|
|
|
|
2013-01-22 04:14:53 +00:00
|
|
|
#define M_PI_F 3.14159265f
|
2013-01-21 09:29:27 +00:00
|
|
|
#define MAX_PERCENTILE 100
|
|
|
|
|
2012-11-29 08:33:53 +00:00
|
|
|
// Number of base-10 digits in the largest integer + 1 to leave room for a zero terminator.
|
|
|
|
// As such, this is the maximum number of characters will be needed to represent an int as a
|
|
|
|
// string, including the terminator; this is used as the size of a string buffer large enough to
|
|
|
|
// hold any value that is intended to fit in an integer, e.g. in the code that reads the header
|
|
|
|
// of the binary dictionary where a {key,value} string pair scheme is used.
|
|
|
|
#define LARGEST_INT_DIGIT_COUNT 11
|
2010-12-08 08:05:39 +00:00
|
|
|
|
2012-09-04 03:49:46 +00:00
|
|
|
#define NOT_A_CODE_POINT (-1)
|
|
|
|
#define NOT_A_DISTANCE (-1)
|
|
|
|
#define NOT_A_COORDINATE (-1)
|
|
|
|
#define NOT_AN_INDEX (-1)
|
|
|
|
#define NOT_A_PROBABILITY (-1)
|
2013-06-27 03:53:31 +00:00
|
|
|
#define NOT_A_DICT_POS (S_INT_MIN)
|
2013-10-01 08:30:40 +00:00
|
|
|
|
2013-09-30 12:39:43 +00:00
|
|
|
// A special value to mean the first word confidence makes no sense in this case,
|
|
|
|
// e.g. this is not a multi-word suggestion.
|
2013-10-01 08:30:40 +00:00
|
|
|
#define NOT_A_FIRST_WORD_CONFIDENCE (S_INT_MAX)
|
|
|
|
// How high the confidence needs to be for us to auto-commit. Arbitrary.
|
|
|
|
// This needs to be the same as CONFIDENCE_FOR_AUTO_COMMIT in BinaryDictionary.java
|
|
|
|
#define CONFIDENCE_FOR_AUTO_COMMIT (1000000)
|
|
|
|
// 80% of the full confidence
|
|
|
|
#define DISTANCE_WEIGHT_FOR_AUTO_COMMIT (80 * CONFIDENCE_FOR_AUTO_COMMIT / 100)
|
|
|
|
// 100% of the full confidence
|
|
|
|
#define LENGTH_WEIGHT_FOR_AUTO_COMMIT (CONFIDENCE_FOR_AUTO_COMMIT)
|
|
|
|
// 80% of the full confidence
|
|
|
|
#define SPACE_COUNT_WEIGHT_FOR_AUTO_COMMIT (80 * CONFIDENCE_FOR_AUTO_COMMIT / 100)
|
2010-12-02 05:53:24 +00:00
|
|
|
|
2011-03-04 14:06:45 +00:00
|
|
|
#define KEYCODE_SPACE ' '
|
2012-10-29 09:06:22 +00:00
|
|
|
#define KEYCODE_SINGLE_QUOTE '\''
|
|
|
|
#define KEYCODE_HYPHEN_MINUS '-'
|
2011-03-04 14:06:45 +00:00
|
|
|
|
2013-02-21 23:42:05 +00:00
|
|
|
#define SUGGEST_INTERFACE_OUTPUT_SCALE 1000000.0f
|
2013-03-18 04:08:31 +00:00
|
|
|
#define MAX_PROBABILITY 255
|
|
|
|
#define MAX_BIGRAM_ENCODED_PROBABILITY 15
|
2010-12-02 05:53:24 +00:00
|
|
|
|
2012-08-09 13:26:58 +00:00
|
|
|
// Assuming locale strings such as en_US, sr-Latn etc.
|
|
|
|
#define MAX_LOCALE_STRING_LENGTH 10
|
|
|
|
|
2013-03-05 05:12:06 +00:00
|
|
|
// Max value for length, distance and probability which are used in weighting
|
|
|
|
// TODO: Remove
|
|
|
|
#define MAX_VALUE_FOR_WEIGHTING 10000000
|
2012-08-23 06:46:43 +00:00
|
|
|
|
2012-09-04 08:00:24 +00:00
|
|
|
// The max number of the keys in one keyboard layout
|
|
|
|
#define MAX_KEY_COUNT_IN_A_KEYBOARD 64
|
|
|
|
|
2012-09-27 10:21:25 +00:00
|
|
|
// TODO: Remove
|
2012-12-10 08:17:52 +00:00
|
|
|
#define MAX_POINTER_COUNT 1
|
2013-01-30 11:55:31 +00:00
|
|
|
#define MAX_POINTER_COUNT_G 2
|
2012-09-27 10:21:25 +00:00
|
|
|
|
2013-01-31 09:05:26 +00:00
|
|
|
template<typename T> AK_FORCE_INLINE const T &min(const T &a, const T &b) { return a < b ? a : b; }
|
|
|
|
template<typename T> AK_FORCE_INLINE const T &max(const T &a, const T &b) { return a > b ? a : b; }
|
2010-12-06 12:28:24 +00:00
|
|
|
|
2012-01-31 08:15:43 +00:00
|
|
|
// DEBUG
|
2012-09-04 03:49:46 +00:00
|
|
|
#define INPUTLENGTH_FOR_DEBUG (-1)
|
|
|
|
#define MIN_OUTPUT_INDEX_FOR_DEBUG (-1)
|
2012-01-31 08:15:43 +00:00
|
|
|
|
2012-06-14 18:25:50 +00:00
|
|
|
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
|
|
|
TypeName(const TypeName&); \
|
|
|
|
void operator=(const TypeName&)
|
|
|
|
|
|
|
|
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
|
|
|
|
TypeName(); \
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TypeName)
|
|
|
|
|
2012-06-05 08:55:52 +00:00
|
|
|
// Used as a return value for character comparison
|
|
|
|
typedef enum {
|
|
|
|
// Same char, possibly with different case or accent
|
2013-03-07 04:06:32 +00:00
|
|
|
MATCH_CHAR,
|
2012-06-05 08:55:52 +00:00
|
|
|
// It is a char located nearby on the keyboard
|
2013-03-07 04:06:32 +00:00
|
|
|
PROXIMITY_CHAR,
|
2012-06-05 08:55:52 +00:00
|
|
|
// Additional proximity char which can differ by language.
|
2013-03-07 04:06:32 +00:00
|
|
|
ADDITIONAL_PROXIMITY_CHAR,
|
|
|
|
// It is a substitution char
|
|
|
|
SUBSTITUTION_CHAR,
|
|
|
|
// It is an unrelated char
|
|
|
|
UNRELATED_CHAR,
|
2012-06-05 08:55:52 +00:00
|
|
|
} ProximityType;
|
2012-11-22 11:15:40 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NOT_A_DOUBLE_LETTER,
|
|
|
|
A_DOUBLE_LETTER,
|
|
|
|
A_STRONG_DOUBLE_LETTER
|
|
|
|
} DoubleLetterLevel;
|
2013-03-04 08:05:28 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2013-04-24 11:21:18 +00:00
|
|
|
// Correction for MATCH_CHAR
|
2013-03-04 08:05:28 +00:00
|
|
|
CT_MATCH,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Correction for PROXIMITY_CHAR
|
2013-03-07 04:06:32 +00:00
|
|
|
CT_PROXIMITY,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Correction for ADDITIONAL_PROXIMITY_CHAR
|
2013-03-07 04:06:32 +00:00
|
|
|
CT_ADDITIONAL_PROXIMITY,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Correction for SUBSTITUTION_CHAR
|
2013-03-07 04:06:32 +00:00
|
|
|
CT_SUBSTITUTION,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Skip one omitted letter
|
2013-03-04 08:05:28 +00:00
|
|
|
CT_OMISSION,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Delete an unnecessarily inserted letter
|
2013-03-04 08:05:28 +00:00
|
|
|
CT_INSERTION,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Swap the order of next two touch points
|
2013-03-04 08:05:28 +00:00
|
|
|
CT_TRANSPOSITION,
|
|
|
|
CT_COMPLETION,
|
|
|
|
CT_TERMINAL,
|
2013-06-14 09:40:59 +00:00
|
|
|
CT_TERMINAL_INSERTION,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Create new word with space omission
|
2013-09-30 09:41:55 +00:00
|
|
|
CT_NEW_WORD_SPACE_OMISSION,
|
2013-04-24 11:21:18 +00:00
|
|
|
// Create new word with space substitution
|
2013-04-16 05:39:30 +00:00
|
|
|
CT_NEW_WORD_SPACE_SUBSTITUTION,
|
2013-03-04 08:05:28 +00:00
|
|
|
} CorrectionType;
|
2013-04-25 07:47:38 +00:00
|
|
|
|
|
|
|
// ErrorType is mainly decided by CorrectionType but it is also depending on if
|
|
|
|
// the correction has really been performed or not.
|
|
|
|
typedef enum {
|
|
|
|
// Substitution, omission and transposition
|
|
|
|
ET_EDIT_CORRECTION,
|
|
|
|
// Proximity error
|
|
|
|
ET_PROXIMITY_CORRECTION,
|
|
|
|
// Completion
|
|
|
|
ET_COMPLETION,
|
|
|
|
// New word
|
|
|
|
// TODO: Remove.
|
|
|
|
// A new word error should be an edit correction error or a proximity correction error.
|
|
|
|
ET_NEW_WORD,
|
|
|
|
// Treat error as an intentional omission when the CorrectionType is omission and the node can
|
|
|
|
// be intentional omission.
|
|
|
|
ET_INTENTIONAL_OMISSION,
|
|
|
|
// Not treated as an error. Tracked for checking exact match
|
|
|
|
ET_NOT_AN_ERROR
|
|
|
|
} ErrorType;
|
2010-12-02 05:53:24 +00:00
|
|
|
#endif // LATINIME_DEFINES_H
|