1 /* 2 * Copyright (C) 2008,2009 OMRON SOFTWARE Co., Ltd. 3 * 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 */ 16 17 #define NJ_VERSION "iWnn Version 1.1.2" 18 19 #ifndef _NJ_LIB_H_ 20 #define _NJ_LIB_H_ 21 22 typedef signed char NJ_INT8; 23 typedef unsigned char NJ_UINT8; 24 typedef signed short NJ_INT16; 25 typedef unsigned short NJ_UINT16; 26 typedef signed long NJ_INT32; 27 typedef unsigned long NJ_UINT32; 28 29 typedef unsigned short NJ_CHAR; 30 31 #define NJ_CHAR_NUL 0x0000 32 33 #define NJ_TERM_LEN 1 34 #define NJ_TERM_SIZE (NJ_TERM_LEN) 35 36 #ifndef NULL 37 #define NULL 0 38 #endif 39 40 #ifdef NJ_STACK_CHECK_FILE 41 typedef NJ_VOID VOID; 42 #endif 43 44 #ifndef NJ_CHAR_WAVE_DASH_BIG 45 #define NJ_CHAR_WAVE_DASH_BIG 0xFF5E 46 #endif 47 #ifndef NJ_CHAR_WAVE_DASH_SMALL 48 #define NJ_CHAR_WAVE_DASH_SMALL 0x007E 49 #endif 50 51 typedef NJ_INT16 NJ_HINDO; 52 53 #define NJ_INDEX_SIZE 2 54 55 #define NJ_LEARN_DIC_HEADER_SIZE 72 56 57 #ifndef NJ_MAX_DIC 58 #define NJ_MAX_DIC 20 59 #endif 60 61 #ifndef NJ_MAX_CHARSET 62 #define NJ_MAX_CHARSET 200 63 #endif 64 65 #ifndef NJ_SEARCH_CACHE_SIZE 66 #define NJ_SEARCH_CACHE_SIZE 200 67 #endif 68 69 #ifndef NJ_CACHE_VIEW_CNT 70 #define NJ_CACHE_VIEW_CNT 2 71 #endif 72 73 74 #ifndef NJ_MAX_RESULT_LEN 75 #define NJ_MAX_RESULT_LEN 50 76 #endif 77 78 #ifndef NJ_MAX_LEN 79 #define NJ_MAX_LEN 50 80 #endif 81 82 #ifndef NJ_MAX_KEYWORD 83 #define NJ_MAX_KEYWORD (NJ_MAX_RESULT_LEN + NJ_TERM_LEN) 84 #endif 85 86 #ifndef NJ_MAX_PHRASE 87 #define NJ_MAX_PHRASE NJ_MAX_LEN 88 #endif 89 90 #ifndef NJ_MAX_PHR_CONNECT 91 #define NJ_MAX_PHR_CONNECT 5 92 #endif 93 94 #ifndef NJ_MAX_USER_LEN 95 #define NJ_MAX_USER_LEN 50 96 #endif 97 98 #ifndef NJ_MAX_USER_KOUHO_LEN 99 #define NJ_MAX_USER_KOUHO_LEN 50 100 #endif 101 102 #ifndef NJ_MAX_USER_COUNT 103 #define NJ_MAX_USER_COUNT 100 104 #endif 105 106 #define NJ_USER_QUE_SIZE (((NJ_MAX_USER_LEN + NJ_MAX_USER_KOUHO_LEN) * sizeof(NJ_CHAR)) + 5) 107 #define NJ_USER_DIC_SIZE ((NJ_USER_QUE_SIZE + NJ_INDEX_SIZE + NJ_INDEX_SIZE) * NJ_MAX_USER_COUNT + NJ_INDEX_SIZE + NJ_INDEX_SIZE + NJ_LEARN_DIC_HEADER_SIZE + 4) 108 109 typedef NJ_UINT8 * NJ_DIC_HANDLE; 110 111 typedef struct { 112 NJ_UINT16 base; 113 NJ_UINT16 high; 114 } NJ_DIC_FREQ; 115 116 typedef struct { 117 NJ_UINT32 current; 118 NJ_UINT32 top; 119 NJ_UINT32 bottom; 120 NJ_UINT8 *node; 121 NJ_UINT8 *now; 122 NJ_UINT16 idx_no; 123 } NJ_CACHE_INFO; 124 125 typedef struct { 126 NJ_UINT8 statusFlg; 127 #define NJ_STATUSFLG_CACHEOVER ((NJ_UINT8)0x01) 128 #define NJ_STATUSFLG_AIMAI ((NJ_UINT8)0x02) 129 #define NJ_STATUSFLG_HINDO ((NJ_UINT8)0x04) 130 NJ_UINT8 viewCnt; 131 NJ_UINT16 keyPtr[NJ_MAX_KEYWORD]; 132 NJ_CACHE_INFO storebuff[NJ_SEARCH_CACHE_SIZE]; 133 } NJ_SEARCH_CACHE; 134 135 #define NJ_GET_CACHEOVER_FROM_SCACHE(s) ((s)->statusFlg & NJ_STATUSFLG_CACHEOVER) 136 #define NJ_GET_AIMAI_FROM_SCACHE(s) ((s)->statusFlg & NJ_STATUSFLG_AIMAI) 137 #define NJ_SET_CACHEOVER_TO_SCACHE(s) ((s)->statusFlg |= NJ_STATUSFLG_CACHEOVER) 138 #define NJ_SET_AIMAI_TO_SCACHE(s) ((s)->statusFlg |= NJ_STATUSFLG_AIMAI) 139 #define NJ_UNSET_CACHEOVER_TO_SCACHE(s) ((s)->statusFlg &= ~NJ_STATUSFLG_CACHEOVER) 140 #define NJ_UNSET_AIMAI_TO_SCACHE(s) ((s)->statusFlg &= ~NJ_STATUSFLG_AIMAI) 141 142 143 typedef struct { 144 NJ_UINT8 type; 145 #define NJ_DIC_H_TYPE_NORMAL 0x00 146 NJ_UINT8 limit; 147 148 NJ_DIC_HANDLE handle; 149 150 #define NJ_MODE_TYPE_MAX 1 151 152 NJ_DIC_FREQ dic_freq[NJ_MODE_TYPE_MAX]; 153 #define NJ_MODE_TYPE_HENKAN 0 154 155 NJ_SEARCH_CACHE * srhCache; 156 } NJ_DIC_INFO; 157 158 159 typedef struct { 160 NJ_DIC_INFO dic[NJ_MAX_DIC]; 161 NJ_DIC_HANDLE rHandle[NJ_MODE_TYPE_MAX]; 162 163 164 NJ_UINT16 mode; 165 #define NJ_CACHE_MODE_NONE 0x0000 166 #define NJ_CACHE_MODE_VALID 0x0001 167 168 169 NJ_CHAR keyword[NJ_MAX_KEYWORD]; 170 } NJ_DIC_SET; 171 172 typedef struct { 173 NJ_UINT16 charset_count; 174 NJ_CHAR *from[NJ_MAX_CHARSET]; 175 NJ_CHAR *to[NJ_MAX_CHARSET]; 176 } NJ_CHARSET; 177 178 179 typedef struct { 180 181 NJ_UINT8 operation; 182 #define NJ_CUR_OP_COMP 0 183 #define NJ_CUR_OP_FORE 1 184 #define NJ_CUR_OP_LINK 2 185 186 NJ_UINT8 mode; 187 #define NJ_CUR_MODE_FREQ 0 188 #define NJ_CUR_MODE_YOMI 1 189 190 NJ_DIC_SET *ds; 191 192 struct { 193 NJ_UINT8 *fore; 194 NJ_UINT16 foreSize; 195 NJ_UINT16 foreFlag; 196 NJ_UINT8 *rear; 197 NJ_UINT16 rearSize; 198 NJ_UINT16 rearFlag; 199 NJ_UINT8 *yominasi_fore; 200 } hinsi; 201 202 NJ_CHAR *yomi; 203 NJ_UINT16 ylen; 204 NJ_UINT16 yclen; 205 NJ_CHAR *kanji; 206 207 NJ_CHARSET *charset; 208 209 } NJ_SEARCH_CONDITION; 210 211 typedef struct { 212 NJ_DIC_HANDLE handle; 213 NJ_UINT32 current; 214 NJ_UINT32 top; 215 NJ_UINT32 bottom; 216 NJ_UINT32 relation[NJ_MAX_PHR_CONNECT]; 217 NJ_UINT8 current_cache; 218 NJ_UINT8 current_info; 219 NJ_UINT8 status; 220 NJ_UINT8 type; 221 } NJ_SEARCH_LOCATION; 222 223 typedef struct { 224 NJ_HINDO cache_freq; 225 NJ_DIC_FREQ dic_freq; 226 NJ_SEARCH_LOCATION loct; 227 } NJ_SEARCH_LOCATION_SET; 228 229 typedef struct { 230 NJ_SEARCH_CONDITION cond; 231 NJ_SEARCH_LOCATION_SET loctset[NJ_MAX_DIC]; 232 } NJ_CURSOR; 233 234 235 typedef struct { 236 NJ_UINT8 hinsi_group; 237 #define NJ_HINSI_MEISI 0 238 #define NJ_HINSI_JINMEI 1 239 #define NJ_HINSI_MEISI_NO_CONJ 2 240 #define NJ_HINSI_CHIMEI 2 241 #define NJ_HINSI_KIGOU 3 242 243 NJ_CHAR yomi[NJ_MAX_LEN + NJ_TERM_LEN]; 244 NJ_CHAR kouho[NJ_MAX_RESULT_LEN + NJ_TERM_LEN]; 245 246 247 struct { 248 NJ_UINT16 yomi_len; 249 NJ_UINT16 kouho_len; 250 NJ_UINT32 hinsi; 251 NJ_UINT32 attr; 252 NJ_INT16 freq; 253 } stem; 254 255 256 struct { 257 NJ_UINT16 yomi_len; 258 NJ_UINT16 kouho_len; 259 NJ_UINT32 hinsi; 260 NJ_INT16 freq; 261 } fzk; 262 263 NJ_INT16 connect; 264 265 } NJ_WORD_INFO; 266 267 typedef struct { 268 NJ_CHAR *yomi; 269 270 271 struct NJ_STEM { 272 NJ_UINT16 info1; 273 NJ_UINT16 info2; 274 NJ_HINDO hindo; 275 NJ_SEARCH_LOCATION loc; 276 NJ_UINT8 type; 277 } stem; 278 279 280 struct NJ_FZK { 281 NJ_UINT16 info1; 282 NJ_UINT16 info2; 283 NJ_HINDO hindo; 284 } fzk; 285 } NJ_WORD; 286 287 #define NJ_GET_FPOS_FROM_STEM(s) ((NJ_UINT16)((s)->stem.info1 >> 7)) 288 #define NJ_GET_BPOS_FROM_STEM(s) ((NJ_UINT16)((s)->stem.info2 >> 7)) 289 290 291 #define NJ_SET_FPOS_TO_STEM(s,v) ((s)->stem.info1 = ((s)->stem.info1 & 0x007F) | (NJ_UINT16)((v) << 7)) 292 #define NJ_GET_YLEN_FROM_STEM(s) ((NJ_UINT8)((s)->stem.info1 & 0x7F)) 293 #define NJ_GET_KLEN_FROM_STEM(s) ((NJ_UINT8)((s)->stem.info2 & 0x7F)) 294 #define NJ_SET_YLEN_TO_STEM(s,v) ((s)->stem.info1 = ((s)->stem.info1 & 0xFF80) | (NJ_UINT16)((v) & 0x7F)) 295 #define NJ_SET_BPOS_TO_STEM(s,v) ((s)->stem.info2 = ((s)->stem.info2 & 0x007F) | (NJ_UINT16)((v) << 7)) 296 #define NJ_SET_KLEN_TO_STEM(s,v) ((s)->stem.info2 = ((s)->stem.info2 & 0xFF80) | (NJ_UINT16)((v) & 0x7F)) 297 298 #define NJ_GET_YLEN_FROM_FZK(f) ((NJ_UINT8)((f)->fzk.info1 & 0x7F)) 299 #define NJ_GET_BPOS_FROM_FZK(f) ((NJ_UINT16)((f)->fzk.info2 >> 7)) 300 301 typedef struct { 302 303 NJ_UINT16 operation_id; 304 #define NJ_OP_MASK 0x000f 305 #define NJ_GET_RESULT_OP(id) ((id) & NJ_OP_MASK) 306 #define NJ_OP_SEARCH 0x0000 307 308 #define NJ_FUNC_MASK 0x00f0 309 #define NJ_GET_RESULT_FUNC(id) ((id) & NJ_FUNC_MASK) 310 #define NJ_FUNC_SEARCH 0x0000 311 312 #define NJ_DIC_MASK 0xf000 313 #define NJ_GET_RESULT_DIC(id) ((id) & 0xF000) 314 #define NJ_DIC_STATIC 0x1000 315 #define NJ_DIC_CUSTOMIZE 0x2000 316 #define NJ_DIC_LEARN 0x3000 317 #define NJ_DIC_USER 0x4000 318 319 320 NJ_WORD word; 321 } NJ_RESULT; 322 323 typedef struct { 324 NJ_UINT16 mode; 325 #define NJ_DEFAULT_MODE (NJ_NO_RENBUN|NJ_NO_TANBUN|NJ_RELATION_ON|NJ_YOMINASI_ON) 326 NJ_UINT16 forecast_learn_limit; 327 #define NJ_DEFAULT_FORECAST_LEARN_LIMIT 30 328 NJ_UINT16 forecast_limit; 329 #define NJ_DEFAULT_FORECAST_LIMIT 100 330 NJ_UINT8 char_min; 331 #define NJ_DEFAULT_CHAR_MIN 0 332 NJ_UINT8 char_max; 333 #define NJ_DEFAULT_CHAR_MAX NJ_MAX_LEN 334 } NJ_ANALYZE_OPTION; 335 336 #define NJ_STATE_MAX_FREQ 1000 337 #define NJ_STATE_MIN_FREQ 0 338 339 #include "njx_lib.h" 340 341 #define NJ_EXTERN extern 342 343 NJ_EXTERN NJ_INT16 njx_get_stroke(NJ_CLASS *iwnn, NJ_RESULT *result, NJ_CHAR *buf, NJ_UINT16 buf_size); 344 NJ_EXTERN NJ_INT16 njx_get_candidate(NJ_CLASS *iwnn, NJ_RESULT *result, NJ_CHAR *buf, NJ_UINT16 buf_size); 345 NJ_EXTERN NJ_INT16 njx_search_word(NJ_CLASS *iwnn, NJ_CURSOR *cursor); 346 NJ_EXTERN NJ_INT16 njx_get_word(NJ_CLASS *iwnn, NJ_CURSOR *cursor, NJ_RESULT *result); 347 NJ_EXTERN NJ_INT16 njx_check_dic(NJ_CLASS *iwnn, NJ_DIC_HANDLE handle, NJ_UINT8 restore, NJ_UINT32 size); 348 NJ_EXTERN NJ_INT16 njx_add_word(NJ_CLASS *iwnn, NJ_WORD_INFO *word, NJ_UINT8 type, NJ_UINT8 connect); 349 NJ_EXTERN NJ_INT16 njx_delete_word(NJ_CLASS *iwnn, NJ_RESULT *result); 350 NJ_EXTERN NJ_INT16 njx_create_dic(NJ_CLASS *iwnn, NJ_DIC_HANDLE handle, NJ_INT8 type, NJ_UINT32 size); 351 352 NJ_EXTERN NJ_INT16 njx_init(NJ_CLASS *iwnn); 353 NJ_EXTERN NJ_INT16 njx_select(NJ_CLASS *iwnn, NJ_RESULT *r_result); 354 355 #endif 356