~ubuntu-branches/ubuntu/trusty/sunpinyin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/pinyin/pinyin_data.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Zhengpeng Hou
  • Date: 2010-09-06 12:23:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100906122346-yamofztk2j5p85fs
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 * 
 
4
 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
 
5
 * 
 
6
 * The contents of this file are subject to the terms of either the GNU Lesser
 
7
 * General Public License Version 2.1 only ("LGPL") or the Common Development and
 
8
 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
 
9
 * file except in compliance with the License. You can obtain a copy of the CDDL at
 
10
 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
 
11
 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the 
 
12
 * specific language governing permissions and limitations under the License. When
 
13
 * distributing the software, include this License Header Notice in each file and
 
14
 * include the full text of the License in the License file as well as the
 
15
 * following notice:
 
16
 * 
 
17
 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
 
18
 * (CDDL)
 
19
 * For Covered Software in this distribution, this License shall be governed by the
 
20
 * laws of the State of California (excluding conflict-of-law provisions).
 
21
 * Any litigation relating to this License shall be subject to the jurisdiction of
 
22
 * the Federal Courts of the Northern District of California and the state courts
 
23
 * of the State of California, with venue lying in Santa Clara County, California.
 
24
 * 
 
25
 * Contributor(s):
 
26
 * 
 
27
 * If you wish your version of this file to be governed by only the CDDL or only
 
28
 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
 
29
 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
 
30
 * license." If you don't indicate a single choice of license, a recipient has the
 
31
 * option to distribute your version of this file under either the CDDL or the LGPL
 
32
 * Version 2.1, or to extend the choice of license to its licensees as provided
 
33
 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
 
34
 * Version 2 license, then the option applies only if the new code is made subject
 
35
 * to such option by the copyright holder. 
 
36
 */
 
37
 
 
38
#include <stdio.h>
 
39
#include <stdlib.h>
 
40
#include <string.h>
 
41
#include "pinyin_data.h"
 
42
 
 
43
static const char *initials[] = {"", "b", "p", "m", "f", "d", "t", "n", "l", "g", "k", "h", "j", "q", "x", "zh", "ch", "sh", "r", "z", "c", "s", "y", "w", };
 
44
static const unsigned num_initials = sizeof(initials)/sizeof(*initials);
 
45
 
 
46
static const char *finals[] = {"", "a", "o", "e", "ai", "ei", "ao", "ou", "an", "en", "ang", "eng", "er", "i", "ia", "ie", "iao", "iu", "ian", "in", "iang", "ing", "u", "ua", "uo", "uai", "ui", "uan", "un", "uang", "ong", "v", "ue", "iong", };
 
47
static const unsigned num_finals = sizeof(finals)/sizeof(*finals);
 
48
 
 
49
static const char *fuzzy_finals[] = {"ia", "iao", "ian", "iang", "ie", "ua", "uai", "uan", "uang", "ue"};
 
50
static const unsigned num_fuzzy_finals = sizeof(fuzzy_finals)/sizeof(*fuzzy_finals);
 
51
 
 
52
static const unsigned fuzzy_finals_map[] = {
 
53
    0x0e,        0x10,        1,           /* ia   -> a    len 1 */
 
54
    0x10,        0x60,        2,           /* iao  -> ao   len 2 */
 
55
    0x12,        0x80,        2,           /* ian  -> an   len 2 */
 
56
    0x14,        0xa0,        3,           /* iang -> ang  len 3 */
 
57
    0x0f,        0x30,        1,           /* ie   -> e    len 1 */
 
58
    0x17,        0x10,        1,           /* ua   -> a    len 1 */
 
59
    0x19,        0x40,        2,           /* uai  -> ai   len 2 */
 
60
    0x1b,        0x80,        2,           /* uan  -> an   len 2 */
 
61
    0x1d,        0xa0,        3,           /* uang -> ang  len 3 */
 
62
    0x20,        0x30,        1,           /* ue   -> e    len 1 */
 
63
};
 
64
 
 
65
static const unsigned fuzzy_pre_syllables [] = {
 
66
    0x0d0e0,     'n',         0x0d120,     /* qian */
 
67
    0x09080,     'g',         0x090a0,     /* gang */
 
68
    0x080e0,     'n',         0x08120,     /* lian */
 
69
    0x15090,     'g',         0x150b0,     /* seng */
 
70
    0x04010,     'n',         0x04080,     /* fan */
 
71
    0x10030,     'n',         0x10090,     /* chen */
 
72
    0x050e0,     'n',         0x05120,     /* dian */
 
73
    0x15160,     'n',         0x151c0,     /* sun */
 
74
    0x07080,     'g',         0x070a0,     /* nang */
 
75
    0x0a160,     'n',         0x0a1c0,     /* kun */
 
76
    0x05030,     'n',         0x05090,     /* den */
 
77
    0x07090,     'g',         0x070b0,     /* neng */
 
78
    0x03030,     'n',         0x03090,     /* men */
 
79
    0x09090,     'g',         0x090b0,     /* geng */
 
80
    0x10080,     'g',         0x100a0,     /* chang */
 
81
    0x0f010,     'n',         0x0f080,     /* zhan */
 
82
    0x14010,     'n',         0x14080,     /* can */
 
83
    0x07130,     'g',         0x07150,     /* ning */
 
84
    0x17080,     'g',         0x170a0,     /* wang */
 
85
    0x01090,     'g',         0x010b0,     /* beng */
 
86
    0x0f1b0,     'g',         0x0f1d0,     /* zhuang */
 
87
    0x06010,     'n',         0x06080,     /* tan */
 
88
    0x00090,     'g',         0x000b0,     /* eng */
 
89
    0x0f080,     'g',         0x0f0a0,     /* zhang */
 
90
    0x02130,     'g',         0x02150,     /* ping */
 
91
    0x08010,     'n',         0x08080,     /* lan */
 
92
    0x0e160,     'n',         0x0e1c0,     /* xun */
 
93
    0x03010,     'n',         0x03080,     /* man */
 
94
    0x0c120,     'g',         0x0c140,     /* jiang */
 
95
    0x0a1b0,     'g',         0x0a1d0,     /* kuang */
 
96
    0x01130,     'g',         0x01150,     /* bing */
 
97
    0x13010,     'n',         0x13080,     /* zan */
 
98
    0x13030,     'n',         0x13090,     /* zen */
 
99
    0x02080,     'g',         0x020a0,     /* pang */
 
100
    0x0c0d0,     'n',         0x0c130,     /* jin */
 
101
    0x14030,     'n',         0x14090,     /* cen */
 
102
    0x05010,     'n',         0x05080,     /* dan */
 
103
    0x0f030,     'n',         0x0f090,     /* zhen */
 
104
    0x01080,     'g',         0x010a0,     /* bang */
 
105
    0x17090,     'g',         0x170b0,     /* weng */
 
106
    0x00030,     'n',         0x00090,     /* en */
 
107
    0x0a080,     'g',         0x0a0a0,     /* kang */
 
108
    0x09160,     'n',         0x091c0,     /* gun */
 
109
    0x00030,     'r',         0x000c0,     /* er */
 
110
    0x0a090,     'g',         0x0a0b0,     /* keng */
 
111
    0x15080,     'g',         0x150a0,     /* sang */
 
112
    0x12030,     'n',         0x12090,     /* ren */
 
113
    0x11160,     'n',         0x111c0,     /* shun */
 
114
    0x0d160,     'n',         0x0d1c0,     /* qun */
 
115
    0x16160,     'n',         0x161c0,     /* yun */
 
116
    0x0e120,     'g',         0x0e140,     /* xiang */
 
117
    0x12080,     'g',         0x120a0,     /* rang */
 
118
    0x09170,     'n',         0x091b0,     /* guan */
 
119
    0x16130,     'g',         0x16150,     /* ying */
 
120
    0x0a170,     'n',         0x0a1b0,     /* kuan */
 
121
    0x10010,     'n',         0x10080,     /* chan */
 
122
    0x160d0,     'n',         0x16130,     /* yin */
 
123
    0x0e0d0,     'n',         0x0e130,     /* xin */
 
124
    0x07120,     'g',         0x07140,     /* niang */
 
125
    0x0b160,     'n',         0x0b1c0,     /* hun */
 
126
    0x11170,     'n',         0x111b0,     /* shuan */
 
127
    0x05080,     'g',         0x050a0,     /* dang */
 
128
    0x00080,     'g',         0x000a0,     /* ang */
 
129
    0x15010,     'n',         0x15080,     /* san */
 
130
    0x12090,     'g',         0x120b0,     /* reng */
 
131
    0x03130,     'g',         0x03150,     /* ming */
 
132
    0x030d0,     'n',         0x03130,     /* min */
 
133
    0x07030,     'n',         0x07090,     /* nen */
 
134
    0x0a010,     'n',         0x0a080,     /* kan */
 
135
    0x16080,     'g',         0x160a0,     /* yang */
 
136
    0x05090,     'g',         0x050b0,     /* deng */
 
137
    0x101b0,     'g',         0x101d0,     /* chuang */
 
138
    0x04090,     'g',         0x040b0,     /* feng */
 
139
    0x03090,     'g',         0x030b0,     /* meng */
 
140
    0x10090,     'g',         0x100b0,     /* cheng */
 
141
    0x09030,     'n',         0x09090,     /* gen */
 
142
    0x01010,     'n',         0x01080,     /* ban */
 
143
    0x07160,     'n',         0x071c0,     /* nun */
 
144
    0x15030,     'n',         0x15090,     /* sen */
 
145
    0x04080,     'g',         0x040a0,     /* fang */
 
146
    0x08160,     'n',         0x081c0,     /* lun */
 
147
    0x0a030,     'n',         0x0a090,     /* ken */
 
148
    0x0b1b0,     'g',         0x0b1d0,     /* huang */
 
149
    0x03080,     'g',         0x030a0,     /* mang */
 
150
    0x06160,     'n',         0x061c0,     /* tun */
 
151
    0x0d0d0,     'n',         0x0d130,     /* qin */
 
152
    0x02090,     'g',         0x020b0,     /* peng */
 
153
    0x05160,     'n',         0x051c0,     /* dun */
 
154
    0x10160,     'n',         0x101c0,     /* chun */
 
155
    0x09010,     'n',         0x09080,     /* gan */
 
156
    0x13090,     'g',         0x130b0,     /* zeng */
 
157
    0x06080,     'g',         0x060a0,     /* tang */
 
158
    0x14080,     'g',         0x140a0,     /* cang */
 
159
    0x0b090,     'g',         0x0b0b0,     /* heng */
 
160
    0x0e0e0,     'n',         0x0e120,     /* xian */
 
161
    0x0f160,     'n',         0x0f1c0,     /* zhun */
 
162
    0x111b0,     'g',         0x111d0,     /* shuang */
 
163
    0x11010,     'n',         0x11080,     /* shan */
 
164
    0x02010,     'n',         0x02080,     /* pan */
 
165
    0x070d0,     'n',         0x07130,     /* nin */
 
166
    0x0b080,     'g',         0x0b0a0,     /* hang */
 
167
    0x0f170,     'n',         0x0f1b0,     /* zhuan */
 
168
    0x080d0,     'n',         0x08130,     /* lin */
 
169
    0x091b0,     'g',         0x091d0,     /* guang */
 
170
    0x0b010,     'n',         0x0b080,     /* han */
 
171
    0x14160,     'n',         0x141c0,     /* cun */
 
172
    0x010d0,     'n',         0x01130,     /* bin */
 
173
    0x11030,     'n',         0x11090,     /* shen */
 
174
    0x0e130,     'g',         0x0e150,     /* xing */
 
175
    0x0d120,     'g',         0x0d140,     /* qiang */
 
176
    0x12160,     'n',         0x121c0,     /* run */
 
177
    0x11090,     'g',         0x110b0,     /* sheng */
 
178
    0x10170,     'n',         0x101b0,     /* chuan */
 
179
    0x0d130,     'g',         0x0d150,     /* qing */
 
180
    0x0c0e0,     'n',         0x0c120,     /* jian */
 
181
    0x17010,     'n',         0x17080,     /* wan */
 
182
    0x0c130,     'g',         0x0c150,     /* jing */
 
183
    0x16010,     'n',         0x16080,     /* yan */
 
184
    0x08120,     'g',         0x08140,     /* liang */
 
185
    0x0b170,     'n',         0x0b1b0,     /* huan */
 
186
    0x0b030,     'n',         0x0b090,     /* hen */
 
187
    0x11080,     'g',         0x110a0,     /* shang */
 
188
    0x0c160,     'n',         0x0c1c0,     /* jun */
 
189
    0x08130,     'g',         0x08150,     /* ling */
 
190
    0x14090,     'g',         0x140b0,     /* ceng */
 
191
    0x020d0,     'n',         0x02130,     /* pin */
 
192
    0x00010,     'n',         0x00080,     /* an */
 
193
    0x13080,     'g',         0x130a0,     /* zang */
 
194
    0x07010,     'n',         0x07080,     /* nan */
 
195
    0x0f090,     'g',         0x0f0b0,     /* zheng */
 
196
    0x13160,     'n',         0x131c0,     /* zun */
 
197
    0x08080,     'g',         0x080a0,     /* lang */
 
198
    0x0,
 
199
};
 
200
 
 
201
static const unsigned fuzzy_pro_syllables [] = {
 
202
    0x09030,     'g',         0x00030,     /* ge */
 
203
    0x090a0,     'g',         0x000a0,     /* gang */
 
204
    0x09010,     'g',         0x00010,     /* ga */
 
205
    0x12070,     'r',         0x00070,     /* rou */
 
206
    0x07050,     'n',         0x00050,     /* nei */
 
207
    0x070a0,     'n',         0x000a0,     /* nang */
 
208
    0x070b0,     'n',         0x000b0,     /* neng */
 
209
    0x090b0,     'g',         0x000b0,     /* geng */
 
210
    0x07070,     'n',         0x00070,     /* nou */
 
211
    0x12030,     'r',         0x00030,     /* re */
 
212
    0x12090,     'r',         0x00090,     /* ren */
 
213
    0x09070,     'g',         0x00070,     /* gou */
 
214
    0x120a0,     'r',         0x000a0,     /* rang */
 
215
    0x120b0,     'r',         0x000b0,     /* reng */
 
216
    0x12080,     'r',         0x00080,     /* ran */
 
217
    0x12060,     'r',         0x00060,     /* rao */
 
218
    0x07090,     'n',         0x00090,     /* nen */
 
219
    0x09050,     'g',         0x00050,     /* gei */
 
220
    0x09090,     'g',         0x00090,     /* gen */
 
221
    0x09060,     'g',         0x00060,     /* gao */
 
222
    0x09080,     'g',         0x00080,     /* gan */
 
223
    0x09040,     'g',         0x00040,     /* gai */
 
224
    0x07060,     'n',         0x00060,     /* nao */
 
225
    0x07010,     'n',         0x00010,     /* na */
 
226
    0x07040,     'n',         0x00040,     /* nai */
 
227
    0x07080,     'n',         0x00080,     /* nan */
 
228
    0x07030,     'n',         0x00030,     /* ne */
 
229
    0x0,
 
230
};
 
231
 
 
232
static const char * fuzzy_pairs[] = {
 
233
    "z",       "zh", 
 
234
    "c",       "ch", 
 
235
    "s",       "sh", 
 
236
    "an",      "ang", 
 
237
    "on",      "ong", 
 
238
    "en",      "eng", 
 
239
    "in",      "ing", 
 
240
    "eng",     "ong", 
 
241
    "ian",     "iang", 
 
242
    "uan",     "uang", 
 
243
    "l",       "n", 
 
244
    "f",       "h", 
 
245
    "r",       "l", 
 
246
    "k",       "g",
 
247
};
 
248
static const unsigned num_fuzzy_pairs = sizeof(fuzzy_pairs)/sizeof(*fuzzy_pairs)/2;
 
249
 
 
250
static const char * auto_correction_pairs[] = {
 
251
    "ign",      "ing",
 
252
    "img",      "ing",
 
253
    "uei",      "ui",
 
254
    "uen",      "un",
 
255
    "iou",      "iu",
 
256
};
 
257
static const unsigned num_auto_correction_pairs = sizeof(auto_correction_pairs)/sizeof(*auto_correction_pairs)/2;
 
258
 
 
259
static const TPyTabEntry 
 
260
pinyin_table[] = {
 
261
    {"a",       0x00010},
 
262
    {"ai",      0x00040},
 
263
    {"an",      0x00080},
 
264
    {"ang",     0x000a0},
 
265
    {"ao",      0x00060},
 
266
    {"b",       0x01000},
 
267
    {"ba",      0x01010},
 
268
    {"bai",     0x01040},
 
269
    {"ban",     0x01080},
 
270
    {"bang",    0x010a0},
 
271
    {"bao",     0x01060},
 
272
    {"bei",     0x01050},
 
273
    {"ben",     0x01090},
 
274
    {"beng",    0x010b0},
 
275
    {"bi",      0x010d0},
 
276
    {"bian",    0x01120},
 
277
    {"biao",    0x01100},
 
278
    {"bie",     0x010f0},
 
279
    {"bin",     0x01130},
 
280
    {"bing",    0x01150},
 
281
    {"bo",      0x01020},
 
282
    {"bu",      0x01160},
 
283
    {"c",       0x14000},
 
284
    {"ca",      0x14010},
 
285
    {"cai",     0x14040},
 
286
    {"can",     0x14080},
 
287
    {"cang",    0x140a0},
 
288
    {"cao",     0x14060},
 
289
    {"ce",      0x14030},
 
290
    {"cei",     0x14050},
 
291
    {"cen",     0x14090},
 
292
    {"ceng",    0x140b0},
 
293
    {"ch",      0x10000},
 
294
    {"cha",     0x10010},
 
295
    {"chai",    0x10040},
 
296
    {"chan",    0x10080},
 
297
    {"chang",   0x100a0},
 
298
    {"chao",    0x10060},
 
299
    {"che",     0x10030},
 
300
    {"chen",    0x10090},
 
301
    {"cheng",   0x100b0},
 
302
    {"chi",     0x100d0},
 
303
    {"chong",   0x101e0},
 
304
    {"chou",    0x10070},
 
305
    {"chu",     0x10160},
 
306
    {"chua",    0x10170},
 
307
    {"chuai",   0x10190},
 
308
    {"chuan",   0x101b0},
 
309
    {"chuang",  0x101d0},
 
310
    {"chui",    0x101a0},
 
311
    {"chun",    0x101c0},
 
312
    {"chuo",    0x10180},
 
313
    {"ci",      0x140d0},
 
314
    {"cong",    0x141e0},
 
315
    {"cou",     0x14070},
 
316
    {"cu",      0x14160},
 
317
    {"cuan",    0x141b0},
 
318
    {"cui",     0x141a0},
 
319
    {"cun",     0x141c0},
 
320
    {"cuo",     0x14180},
 
321
    {"d",       0x05000},
 
322
    {"da",      0x05010},
 
323
    {"dai",     0x05040},
 
324
    {"dan",     0x05080},
 
325
    {"dang",    0x050a0},
 
326
    {"dao",     0x05060},
 
327
    {"de",      0x05030},
 
328
    {"dei",     0x05050},
 
329
    {"den",     0x05090},
 
330
    {"deng",    0x050b0},
 
331
    {"di",      0x050d0},
 
332
    {"dia",     0x050e0},
 
333
    {"dian",    0x05120},
 
334
    {"diao",    0x05100},
 
335
    {"die",     0x050f0},
 
336
    {"ding",    0x05150},
 
337
    {"diu",     0x05110},
 
338
    {"dong",    0x051e0},
 
339
    {"dou",     0x05070},
 
340
    {"du",      0x05160},
 
341
    {"duan",    0x051b0},
 
342
    {"dui",     0x051a0},
 
343
    {"dun",     0x051c0},
 
344
    {"duo",     0x05180},
 
345
    {"e",       0x00030},
 
346
    {"ei",      0x00050},
 
347
    {"en",      0x00090},
 
348
    {"eng",     0x000b0},
 
349
    {"er",      0x000c0},
 
350
    {"f",       0x04000},
 
351
    {"fa",      0x04010},
 
352
    {"fan",     0x04080},
 
353
    {"fang",    0x040a0},
 
354
    {"fei",     0x04050},
 
355
    {"fen",     0x04090},
 
356
    {"feng",    0x040b0},
 
357
    {"fiao",    0x04100},
 
358
    {"fo",      0x04020},
 
359
    {"fou",     0x04070},
 
360
    {"fu",      0x04160},
 
361
    {"g",       0x09000},
 
362
    {"ga",      0x09010},
 
363
    {"gai",     0x09040},
 
364
    {"gan",     0x09080},
 
365
    {"gang",    0x090a0},
 
366
    {"gao",     0x09060},
 
367
    {"ge",      0x09030},
 
368
    {"gei",     0x09050},
 
369
    {"gen",     0x09090},
 
370
    {"geng",    0x090b0},
 
371
    {"gong",    0x091e0},
 
372
    {"gou",     0x09070},
 
373
    {"gu",      0x09160},
 
374
    {"gua",     0x09170},
 
375
    {"guai",    0x09190},
 
376
    {"guan",    0x091b0},
 
377
    {"guang",   0x091d0},
 
378
    {"gui",     0x091a0},
 
379
    {"gun",     0x091c0},
 
380
    {"guo",     0x09180},
 
381
    {"h",       0x0b000},
 
382
    {"ha",      0x0b010},
 
383
    {"hai",     0x0b040},
 
384
    {"han",     0x0b080},
 
385
    {"hang",    0x0b0a0},
 
386
    {"hao",     0x0b060},
 
387
    {"he",      0x0b030},
 
388
    {"hei",     0x0b050},
 
389
    {"hen",     0x0b090},
 
390
    {"heng",    0x0b0b0},
 
391
    {"hong",    0x0b1e0},
 
392
    {"hou",     0x0b070},
 
393
    {"hu",      0x0b160},
 
394
    {"hua",     0x0b170},
 
395
    {"huai",    0x0b190},
 
396
    {"huan",    0x0b1b0},
 
397
    {"huang",   0x0b1d0},
 
398
    {"hui",     0x0b1a0},
 
399
    {"hun",     0x0b1c0},
 
400
    {"huo",     0x0b180},
 
401
    {"j",       0x0c000},
 
402
    {"ji",      0x0c0d0},
 
403
    {"jia",     0x0c0e0},
 
404
    {"jian",    0x0c120},
 
405
    {"jiang",   0x0c140},
 
406
    {"jiao",    0x0c100},
 
407
    {"jie",     0x0c0f0},
 
408
    {"jin",     0x0c130},
 
409
    {"jing",    0x0c150},
 
410
    {"jiong",   0x0c210},
 
411
    {"jiu",     0x0c110},
 
412
    {"ju",      0x0c160},
 
413
    {"juan",    0x0c1b0},
 
414
    {"jue",     0x0c200},
 
415
    {"jun",     0x0c1c0},
 
416
    {"k",       0x0a000},
 
417
    {"ka",      0x0a010},
 
418
    {"kai",     0x0a040},
 
419
    {"kan",     0x0a080},
 
420
    {"kang",    0x0a0a0},
 
421
    {"kao",     0x0a060},
 
422
    {"ke",      0x0a030},
 
423
    {"kei",     0x0a050},
 
424
    {"ken",     0x0a090},
 
425
    {"keng",    0x0a0b0},
 
426
    {"kong",    0x0a1e0},
 
427
    {"kou",     0x0a070},
 
428
    {"ku",      0x0a160},
 
429
    {"kua",     0x0a170},
 
430
    {"kuai",    0x0a190},
 
431
    {"kuan",    0x0a1b0},
 
432
    {"kuang",   0x0a1d0},
 
433
    {"kui",     0x0a1a0},
 
434
    {"kun",     0x0a1c0},
 
435
    {"kuo",     0x0a180},
 
436
    {"l",       0x08000},
 
437
    {"la",      0x08010},
 
438
    {"lai",     0x08040},
 
439
    {"lan",     0x08080},
 
440
    {"lang",    0x080a0},
 
441
    {"lao",     0x08060},
 
442
    {"le",      0x08030},
 
443
    {"lei",     0x08050},
 
444
    {"leng",    0x080b0},
 
445
    {"li",      0x080d0},
 
446
    {"lia",     0x080e0},
 
447
    {"lian",    0x08120},
 
448
    {"liang",   0x08140},
 
449
    {"liao",    0x08100},
 
450
    {"lie",     0x080f0},
 
451
    {"lin",     0x08130},
 
452
    {"ling",    0x08150},
 
453
    {"liu",     0x08110},
 
454
    {"lo",      0x08020},
 
455
    {"long",    0x081e0},
 
456
    {"lou",     0x08070},
 
457
    {"lu",      0x08160},
 
458
    {"luan",    0x081b0},
 
459
    {"lue",     0x08200},
 
460
    {"lun",     0x081c0},
 
461
    {"luo",     0x08180},
 
462
    {"lv",      0x081f0},
 
463
    {"m",       0x03000},
 
464
    {"ma",      0x03010},
 
465
    {"mai",     0x03040},
 
466
    {"man",     0x03080},
 
467
    {"mang",    0x030a0},
 
468
    {"mao",     0x03060},
 
469
    {"me",      0x03030},
 
470
    {"mei",     0x03050},
 
471
    {"men",     0x03090},
 
472
    {"meng",    0x030b0},
 
473
    {"mi",      0x030d0},
 
474
    {"mian",    0x03120},
 
475
    {"miao",    0x03100},
 
476
    {"mie",     0x030f0},
 
477
    {"min",     0x03130},
 
478
    {"ming",    0x03150},
 
479
    {"miu",     0x03110},
 
480
    {"mo",      0x03020},
 
481
    {"mou",     0x03070},
 
482
    {"mu",      0x03160},
 
483
    {"n",       0x07000},
 
484
    {"na",      0x07010},
 
485
    {"nai",     0x07040},
 
486
    {"nan",     0x07080},
 
487
    {"nang",    0x070a0},
 
488
    {"nao",     0x07060},
 
489
    {"ne",      0x07030},
 
490
    {"nei",     0x07050},
 
491
    {"nen",     0x07090},
 
492
    {"neng",    0x070b0},
 
493
    {"ni",      0x070d0},
 
494
    {"nian",    0x07120},
 
495
    {"niang",   0x07140},
 
496
    {"niao",    0x07100},
 
497
    {"nie",     0x070f0},
 
498
    {"nin",     0x07130},
 
499
    {"ning",    0x07150},
 
500
    {"niu",     0x07110},
 
501
    {"nong",    0x071e0},
 
502
    {"nou",     0x07070},
 
503
    {"nu",      0x07160},
 
504
    {"nuan",    0x071b0},
 
505
    {"nue",     0x07200},
 
506
    {"nun",     0x071c0},
 
507
    {"nuo",     0x07180},
 
508
    {"nv",      0x071f0},
 
509
    {"o",       0x00020},
 
510
    {"ou",      0x00070},
 
511
    {"p",       0x02000},
 
512
    {"pa",      0x02010},
 
513
    {"pai",     0x02040},
 
514
    {"pan",     0x02080},
 
515
    {"pang",    0x020a0},
 
516
    {"pao",     0x02060},
 
517
    {"pei",     0x02050},
 
518
    {"pen",     0x02090},
 
519
    {"peng",    0x020b0},
 
520
    {"pi",      0x020d0},
 
521
    {"pian",    0x02120},
 
522
    {"piao",    0x02100},
 
523
    {"pie",     0x020f0},
 
524
    {"pin",     0x02130},
 
525
    {"ping",    0x02150},
 
526
    {"po",      0x02020},
 
527
    {"pou",     0x02070},
 
528
    {"pu",      0x02160},
 
529
    {"q",       0x0d000},
 
530
    {"qi",      0x0d0d0},
 
531
    {"qia",     0x0d0e0},
 
532
    {"qian",    0x0d120},
 
533
    {"qiang",   0x0d140},
 
534
    {"qiao",    0x0d100},
 
535
    {"qie",     0x0d0f0},
 
536
    {"qin",     0x0d130},
 
537
    {"qing",    0x0d150},
 
538
    {"qiong",   0x0d210},
 
539
    {"qiu",     0x0d110},
 
540
    {"qu",      0x0d160},
 
541
    {"quan",    0x0d1b0},
 
542
    {"que",     0x0d200},
 
543
    {"qun",     0x0d1c0},
 
544
    {"r",       0x12000},
 
545
    {"ran",     0x12080},
 
546
    {"rang",    0x120a0},
 
547
    {"rao",     0x12060},
 
548
    {"re",      0x12030},
 
549
    {"ren",     0x12090},
 
550
    {"reng",    0x120b0},
 
551
    {"ri",      0x120d0},
 
552
    {"rong",    0x121e0},
 
553
    {"rou",     0x12070},
 
554
    {"ru",      0x12160},
 
555
    {"ruan",    0x121b0},
 
556
    {"rui",     0x121a0},
 
557
    {"run",     0x121c0},
 
558
    {"ruo",     0x12180},
 
559
    {"s",       0x15000},
 
560
    {"sa",      0x15010},
 
561
    {"sai",     0x15040},
 
562
    {"san",     0x15080},
 
563
    {"sang",    0x150a0},
 
564
    {"sao",     0x15060},
 
565
    {"se",      0x15030},
 
566
    {"sen",     0x15090},
 
567
    {"seng",    0x150b0},
 
568
    {"sh",      0x11000},
 
569
    {"sha",     0x11010},
 
570
    {"shai",    0x11040},
 
571
    {"shan",    0x11080},
 
572
    {"shang",   0x110a0},
 
573
    {"shao",    0x11060},
 
574
    {"she",     0x11030},
 
575
    {"shei",    0x11050},
 
576
    {"shen",    0x11090},
 
577
    {"sheng",   0x110b0},
 
578
    {"shi",     0x110d0},
 
579
    {"shou",    0x11070},
 
580
    {"shu",     0x11160},
 
581
    {"shua",    0x11170},
 
582
    {"shuai",   0x11190},
 
583
    {"shuan",   0x111b0},
 
584
    {"shuang",  0x111d0},
 
585
    {"shui",    0x111a0},
 
586
    {"shun",    0x111c0},
 
587
    {"shuo",    0x11180},
 
588
    {"si",      0x150d0},
 
589
    {"song",    0x151e0},
 
590
    {"sou",     0x15070},
 
591
    {"su",      0x15160},
 
592
    {"suan",    0x151b0},
 
593
    {"sui",     0x151a0},
 
594
    {"sun",     0x151c0},
 
595
    {"suo",     0x15180},
 
596
    {"t",       0x06000},
 
597
    {"ta",      0x06010},
 
598
    {"tai",     0x06040},
 
599
    {"tan",     0x06080},
 
600
    {"tang",    0x060a0},
 
601
    {"tao",     0x06060},
 
602
    {"te",      0x06030},
 
603
    {"tei",     0x06050},
 
604
    {"teng",    0x060b0},
 
605
    {"ti",      0x060d0},
 
606
    {"tian",    0x06120},
 
607
    {"tiao",    0x06100},
 
608
    {"tie",     0x060f0},
 
609
    {"ting",    0x06150},
 
610
    {"tong",    0x061e0},
 
611
    {"tou",     0x06070},
 
612
    {"tu",      0x06160},
 
613
    {"tuan",    0x061b0},
 
614
    {"tui",     0x061a0},
 
615
    {"tun",     0x061c0},
 
616
    {"tuo",     0x06180},
 
617
    {"w",       0x17000},
 
618
    {"wa",      0x17010},
 
619
    {"wai",     0x17040},
 
620
    {"wan",     0x17080},
 
621
    {"wang",    0x170a0},
 
622
    {"wei",     0x17050},
 
623
    {"wen",     0x17090},
 
624
    {"weng",    0x170b0},
 
625
    {"wo",      0x17020},
 
626
    {"wu",      0x17160},
 
627
    {"x",       0x0e000},
 
628
    {"xi",      0x0e0d0},
 
629
    {"xia",     0x0e0e0},
 
630
    {"xian",    0x0e120},
 
631
    {"xiang",   0x0e140},
 
632
    {"xiao",    0x0e100},
 
633
    {"xie",     0x0e0f0},
 
634
    {"xin",     0x0e130},
 
635
    {"xing",    0x0e150},
 
636
    {"xiong",   0x0e210},
 
637
    {"xiu",     0x0e110},
 
638
    {"xu",      0x0e160},
 
639
    {"xuan",    0x0e1b0},
 
640
    {"xue",     0x0e200},
 
641
    {"xun",     0x0e1c0},
 
642
    {"y",       0x16000},
 
643
    {"ya",      0x16010},
 
644
    {"yai",     0x16040},
 
645
    {"yan",     0x16080},
 
646
    {"yang",    0x160a0},
 
647
    {"yao",     0x16060},
 
648
    {"ye",      0x16030},
 
649
    {"yi",      0x160d0},
 
650
    {"yin",     0x16130},
 
651
    {"ying",    0x16150},
 
652
    {"yo",      0x16020},
 
653
    {"yong",    0x161e0},
 
654
    {"you",     0x16070},
 
655
    {"yu",      0x16160},
 
656
    {"yuan",    0x161b0},
 
657
    {"yue",     0x16200},
 
658
    {"yun",     0x161c0},
 
659
    {"z",       0x13000},
 
660
    {"za",      0x13010},
 
661
    {"zai",     0x13040},
 
662
    {"zan",     0x13080},
 
663
    {"zang",    0x130a0},
 
664
    {"zao",     0x13060},
 
665
    {"ze",      0x13030},
 
666
    {"zei",     0x13050},
 
667
    {"zen",     0x13090},
 
668
    {"zeng",    0x130b0},
 
669
    {"zh",      0x0f000},
 
670
    {"zha",     0x0f010},
 
671
    {"zhai",    0x0f040},
 
672
    {"zhan",    0x0f080},
 
673
    {"zhang",   0x0f0a0},
 
674
    {"zhao",    0x0f060},
 
675
    {"zhe",     0x0f030},
 
676
    {"zhei",    0x0f050},
 
677
    {"zhen",    0x0f090},
 
678
    {"zheng",   0x0f0b0},
 
679
    {"zhi",     0x0f0d0},
 
680
    {"zhong",   0x0f1e0},
 
681
    {"zhou",    0x0f070},
 
682
    {"zhu",     0x0f160},
 
683
    {"zhua",    0x0f170},
 
684
    {"zhuai",   0x0f190},
 
685
    {"zhuan",   0x0f1b0},
 
686
    {"zhuang",  0x0f1d0},
 
687
    {"zhui",    0x0f1a0},
 
688
    {"zhun",    0x0f1c0},
 
689
    {"zhuo",    0x0f180},
 
690
    {"zi",      0x130d0},
 
691
    {"zong",    0x131e0},
 
692
    {"zou",     0x13070},
 
693
    {"zu",      0x13160},
 
694
    {"zuan",    0x131b0},
 
695
    {"zui",     0x131a0},
 
696
    {"zun",     0x131c0},
 
697
    {"zuo",     0x13180},
 
698
};
 
699
 
 
700
static int 
 
701
pytab_entry_compare (const char *s, TPyTabEntry *v)
 
702
  {return strcmp (s, v->pystr);}
 
703
 
 
704
TSyllable
 
705
CPinyinData::encodeSyllable (const char *pinyin)
 
706
{
 
707
    typedef int (*bsearch_compare) (const void*, const void*);
 
708
    TPyTabEntry *e = (TPyTabEntry*) bsearch (pinyin, pinyin_table, 
 
709
                                           sizeof(pinyin_table)/sizeof(pinyin_table[0]), 
 
710
                                           sizeof(pinyin_table[0]), 
 
711
                                           (bsearch_compare) pytab_entry_compare);
 
712
    if (e)
 
713
        return e->id;
 
714
 
 
715
    return 0;
 
716
}
 
717
 
 
718
const char * 
 
719
CPinyinData::decodeSyllable (TSyllable s, const char **i, const char **f)
 
720
{
 
721
    if (i) *i = initials[s.initial];
 
722
    if (f) *f = finals[s.final];
 
723
 
 
724
    static char buf[128];
 
725
    snprintf (buf, sizeof(buf), "%s%s", initials[s.initial], finals[s.final]);
 
726
 
 
727
    typedef int (*bsearch_compare) (const void*, const void*);
 
728
    TPyTabEntry *e = (TPyTabEntry*) bsearch (buf, pinyin_table, 
 
729
                                           sizeof(pinyin_table)/sizeof(pinyin_table[0]), 
 
730
                                           sizeof(pinyin_table[0]), 
 
731
                                           (bsearch_compare) pytab_entry_compare);
 
732
 
 
733
    if (e)
 
734
        return e->pystr;
 
735
 
 
736
    return NULL;
 
737
}
 
738
 
 
739
const char **
 
740
CPinyinData::getAutoCorrectionPairs (unsigned &num)
 
741
{
 
742
    num = num_auto_correction_pairs;
 
743
    return auto_correction_pairs;
 
744
}
 
745
 
 
746
const char **
 
747
CPinyinData::getFuzzyPairs (unsigned &num)
 
748
{
 
749
    num = num_fuzzy_pairs;
 
750
    return fuzzy_pairs;
 
751
}
 
752
 
 
753
const char **
 
754
CPinyinData::getInitials (unsigned &num)
 
755
{
 
756
    num = num_initials;
 
757
    return initials;
 
758
}
 
759
 
 
760
const char **
 
761
CPinyinData::getFinals (unsigned &num)
 
762
{
 
763
    num = num_finals;
 
764
    return finals;
 
765
}
 
766
 
 
767
const TPyTabEntry *
 
768
CPinyinData::getPinyinTable(unsigned &num)
 
769
{
 
770
    num = sizeof(pinyin_table) / sizeof(TPyTabEntry);
 
771
    return pinyin_table;
 
772
}
 
773
 
 
774
const unsigned *
 
775
CPinyinData::getInnerFuzzyFinalMap (unsigned &num)
 
776
{
 
777
    num = num_fuzzy_finals;
 
778
    return fuzzy_finals_map;
 
779
}
 
780
 
 
781
void
 
782
CPinyinData::getFuzzyPreProSyllables (const unsigned **pre_syls, const unsigned **pro_syls)
 
783
{
 
784
    *pre_syls = fuzzy_pre_syllables;
 
785
    *pro_syls = fuzzy_pro_syllables;
 
786
}