1 /*
2 * Copyright (C) 2008-2012 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 #include "nj_lib.h"
18 #include "nj_err.h"
19 #include "nj_ext.h"
20 #include "nj_dic.h"
21
22
23
24 static NJ_INT16 set_previous_selection(NJ_CLASS *iwnn, NJ_RESULT *result);
25 static NJ_INT16 set_learn_word_info(NJ_CLASS *iwnn, NJ_LEARN_WORD_INFO *lword, NJ_RESULT *result);
26
27
28
njx_select(NJ_CLASS * iwnn,NJ_RESULT * r_result)29 NJ_EXTERN NJ_INT16 njx_select(NJ_CLASS *iwnn, NJ_RESULT *r_result) {
30 NJ_INT16 ret;
31 NJ_DIC_SET *dics;
32
33
34 if (iwnn == NULL) {
35
36 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_SELECT, NJ_ERR_PARAM_ENV_NULL);
37 }
38 dics = &(iwnn->dic_set);
39
40 if (dics->rHandle[NJ_MODE_TYPE_HENKAN] == NULL) {
41 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_SELECT, NJ_ERR_NO_RULEDIC);
42 }
43
44
45 if ( r_result != NULL ) {
46
47 ret = set_previous_selection(iwnn, r_result);
48 if (ret < 0) {
49 return ret;
50 }
51 } else {
52
53 set_previous_selection(iwnn, NULL);
54 }
55 return 0;
56 }
57
njx_init(NJ_CLASS * iwnn)58 NJ_EXTERN NJ_INT16 njx_init(NJ_CLASS *iwnn) {
59
60 if (iwnn == NULL) {
61
62 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_INIT, NJ_ERR_PARAM_ENV_NULL);
63 }
64
65
66 set_previous_selection(iwnn, NULL);
67 return 0;
68 }
69
njx_get_candidate(NJ_CLASS * iwnn,NJ_RESULT * result,NJ_CHAR * buf,NJ_UINT16 buf_size)70 NJ_EXTERN NJ_INT16 njx_get_candidate(NJ_CLASS *iwnn, NJ_RESULT *result, NJ_CHAR *buf, NJ_UINT16 buf_size) {
71 NJ_INT16 ret;
72
73
74 if (iwnn == NULL) {
75
76 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_CANDIDATE, NJ_ERR_PARAM_ENV_NULL);
77 }
78 if (result == NULL) {
79 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_CANDIDATE, NJ_ERR_PARAM_RESULT_NULL);
80 }
81
82 if ((buf == NULL) || (buf_size == 0)) {
83 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_CANDIDATE, NJ_ERR_BUFFER_NOT_ENOUGH);
84 }
85
86 switch (NJ_GET_RESULT_OP(result->operation_id)) {
87 case NJ_OP_SEARCH:
88 ret = njd_get_candidate(iwnn, result, buf, buf_size);
89 break;
90
91 default:
92
93 ret = NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_CANDIDATE, NJ_ERR_INVALID_RESULT);
94 break;
95 }
96
97 return ret;
98 }
99
njx_get_stroke(NJ_CLASS * iwnn,NJ_RESULT * result,NJ_CHAR * buf,NJ_UINT16 buf_size)100 NJ_EXTERN NJ_INT16 njx_get_stroke(NJ_CLASS *iwnn, NJ_RESULT *result, NJ_CHAR *buf, NJ_UINT16 buf_size) {
101 NJ_INT16 ret;
102
103
104 if (iwnn == NULL) {
105
106 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_PARAM_ENV_NULL);
107 }
108 if (result == NULL) {
109 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_PARAM_RESULT_NULL);
110 }
111
112 if ((buf == NULL) || (buf_size == 0)) {
113 return NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_BUFFER_NOT_ENOUGH);
114 }
115
116 switch (NJ_GET_RESULT_OP(result->operation_id)) {
117 case NJ_OP_SEARCH:
118 ret = njd_get_stroke(iwnn, result, buf, buf_size);
119 break;
120
121 default:
122
123 ret = NJ_SET_ERR_VAL(NJ_FUNC_NJ_GET_STROKE, NJ_ERR_INVALID_RESULT);
124 break;
125 }
126 return ret;
127 }
128
129
set_previous_selection(NJ_CLASS * iwnn,NJ_RESULT * result)130 static NJ_INT16 set_previous_selection(NJ_CLASS *iwnn, NJ_RESULT *result) {
131 NJ_INT16 ret;
132 NJ_PREVIOUS_SELECTION_INFO *prev_info = &(iwnn->previous_selection);
133
134
135 if (result == NULL) {
136 prev_info->count = 0;
137 } else {
138 ret = set_learn_word_info(iwnn, &(prev_info->selection_data), result);
139 if (ret < 0) {
140
141 return ret;
142 }
143
144 prev_info->count = 1;
145 }
146
147 return 0;
148 }
149
set_learn_word_info(NJ_CLASS * iwnn,NJ_LEARN_WORD_INFO * lword,NJ_RESULT * result)150 static NJ_INT16 set_learn_word_info(NJ_CLASS *iwnn, NJ_LEARN_WORD_INFO *lword, NJ_RESULT *result)
151 {
152 NJ_INT16 ret;
153 NJ_DIC_SET *dics = &(iwnn->dic_set);
154
155
156
157 #if 0
158
159 ret = njx_get_stroke(iwnn, result, lword->yomi, sizeof(lword->yomi));
160 if (ret < 0) {
161 return ret;
162 }
163 lword->yomi_len = (NJ_UINT8)ret;
164 ret = njx_get_candidate(iwnn, result, lword->hyouki, sizeof(lword->hyouki));
165 if (ret < 0) {
166 return ret;
167 }
168 lword->hyouki_len = (NJ_UINT8)ret;
169 #else
170 lword->yomi[0] = 0x0000;
171 lword->yomi_len = 0;
172 lword->hyouki[0] = 0x0000;
173 lword->hyouki_len = 0;
174 #endif
175
176
177 lword->f_hinsi = NJ_GET_FPOS_FROM_STEM(&(result->word));
178 lword->stem_b_hinsi = NJ_GET_BPOS_FROM_STEM(&(result->word));
179 lword->b_hinsi = NJ_GET_BPOS_FROM_STEM(&(result->word));
180
181
182 ret = njd_r_get_hinsi(dics->rHandle[NJ_MODE_TYPE_HENKAN], NJ_HINSI_TANKANJI_F);
183 if ((ret != 0) && (lword->f_hinsi == (NJ_UINT16)ret)) {
184 ret = njd_r_get_hinsi(dics->rHandle[NJ_MODE_TYPE_HENKAN], NJ_HINSI_CHIMEI_F);
185 if (ret != 0) {
186 lword->f_hinsi = (NJ_UINT16)ret;
187 }
188 }
189
190
191 ret = njd_r_get_hinsi(dics->rHandle[NJ_MODE_TYPE_HENKAN], NJ_HINSI_TANKANJI_B);
192 if ((ret != 0) && (lword->b_hinsi == (NJ_UINT16)ret)) {
193 ret = njd_r_get_hinsi(dics->rHandle[NJ_MODE_TYPE_HENKAN], NJ_HINSI_CHIMEI_B);
194 if (ret != 0) {
195 lword->b_hinsi = (NJ_UINT16)ret;
196 }
197 }
198
199
200 ret = njd_r_get_hinsi(dics->rHandle[NJ_MODE_TYPE_HENKAN], NJ_HINSI_TANKANJI_B);
201 if ((ret != 0) && (lword->stem_b_hinsi == (NJ_UINT16)ret)) {
202 ret = njd_r_get_hinsi(dics->rHandle[NJ_MODE_TYPE_HENKAN], NJ_HINSI_CHIMEI_B);
203 if (ret != 0) {
204 lword->stem_b_hinsi = (NJ_UINT16)ret;
205 }
206 }
207
208 return 0;
209
210 }
211