0
|
1 /*
|
|
2 * $Id: kankana.c,v 1.6 2005/04/10 15:26:37 aonoto Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
10 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
13 * Copyright FreeWnn Project 1999, 2000, 2002, 2003
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This library is free software; you can redistribute it and/or
|
|
18 * modify it under the terms of the GNU Lesser General Public
|
|
19 * License as published by the Free Software Foundation; either
|
|
20 * version 2 of the License, or (at your option) any later version.
|
|
21 *
|
|
22 * This library is distributed in the hope that it will be useful,
|
|
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
25 * Lesser General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU Lesser General Public
|
|
28 * License along with this library; if not, write to the
|
|
29 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
30 * Boston, MA 02111-1307, USA.
|
|
31 */
|
|
32
|
|
33 #ifndef lint
|
|
34 static char *rcs_id = "$Id: kankana.c,v 1.6 2005/04/10 15:26:37 aonoto Exp $";
|
|
35 #endif /* lint */
|
|
36
|
|
37 #ifdef HAVE_CONFIG_H
|
|
38 # include <config.h>
|
|
39 #endif
|
|
40
|
|
41 #include <stdio.h>
|
|
42 #if STDC_HEADERS
|
|
43 # include <stdlib.h>
|
|
44 #else
|
|
45 # if HAVE_MALLOC_H
|
|
46 # include <malloc.h>
|
|
47 # endif
|
|
48 #endif /* STDC_HEADERS */
|
|
49 #include "jslib.h"
|
|
50
|
|
51 #define FZK_FILE "pubdic/full.fzk"
|
|
52 #define KIHON_DIC "pubdic/kihon.dic"
|
|
53 #define SETTO_DIC "pubdic/setsuji.dic"
|
|
54
|
|
55 void err (void);
|
|
56 void henkan (void);
|
|
57 void p_set (struct wnn_env *env1);
|
|
58 void print_kanji (struct wnn_dai_bunsetsu *dlist, int cnt);
|
|
59 void putws (unsigned short *s);
|
|
60 void strtows (w_char *u, unsigned char *e);
|
|
61
|
|
62 WNN_JSERVER_ID *js;
|
|
63 struct wnn_env *env, *rev_env;
|
|
64 static struct wnn_ret_buf rb = { 0, NULL };
|
|
65
|
|
66 int dcnt, scnt;
|
|
67
|
|
68 char yomi[1024];
|
|
69 char kanji[5000];
|
|
70
|
|
71 int kihon_file, setto_file, rev_file, fzk_file, rev_setto_file;
|
|
72 int kihon_dic_no, setto_dic_no, rev_dic_no, rev_setto_dic_no;
|
|
73
|
|
74 int
|
|
75 main (int argc, char **argv)
|
|
76 {
|
|
77 char *mname = "";
|
|
78 rb.buf = (char *) malloc ((unsigned) (rb.size = 0));
|
|
79 if (argc > 1)
|
|
80 mname = argv[1];
|
|
81
|
|
82 if ((js = js_open (mname, 0)) == NULL)
|
|
83 err ();
|
|
84
|
|
85 if ((env = js_connect (js, "kana")) == NULL)
|
|
86 err ();
|
|
87 if ((fzk_file = js_file_read (env, FZK_FILE)) == -1)
|
|
88 err ();
|
|
89 if ((kihon_file = js_file_read (env, KIHON_DIC)) == -1)
|
|
90 err ();
|
|
91 if ((setto_file = js_file_read (env, SETTO_DIC)) == -1)
|
|
92 err ();
|
|
93
|
|
94 if (js_fuzokugo_set (env, fzk_file) == -1)
|
|
95 err ();
|
|
96 if ((kihon_dic_no = js_dic_add (env, kihon_file, -1, WNN_DIC_ADD_NOR, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
|
|
97 err ();
|
|
98 if ((setto_dic_no = js_dic_add (env, setto_file, -1, WNN_DIC_ADD_NOR, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
|
|
99 err ();
|
|
100 p_set (env);
|
|
101
|
|
102 if ((rev_env = js_connect (js, "kanji")) == NULL)
|
|
103 err ();
|
|
104
|
|
105 if ((fzk_file = js_file_read (rev_env, FZK_FILE)) == -1)
|
|
106 err ();
|
|
107 if ((rev_file = js_file_read (rev_env, KIHON_DIC)) == -1)
|
|
108 err ();
|
|
109 if ((rev_setto_file = js_file_read (rev_env, SETTO_DIC)) == -1)
|
|
110 err ();
|
|
111 if (js_fuzokugo_set (rev_env, fzk_file) == -1)
|
|
112 err ();
|
|
113
|
|
114 if ((rev_dic_no = js_dic_add (rev_env, kihon_file, -1, WNN_DIC_ADD_REV, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
|
|
115 err ();
|
|
116 if ((rev_setto_dic_no = js_dic_add (rev_env, setto_file, -1, WNN_DIC_ADD_REV, 1, WNN_DIC_RDONLY, WNN_DIC_RDONLY, NULL, NULL)) == -1)
|
|
117 err ();
|
|
118 p_set (rev_env);
|
|
119
|
|
120 #ifdef DEBUG
|
|
121 printf ("Now discard file push any key\n");
|
|
122 getchar ();
|
|
123 js_file_discard (rev_env, rev_file);
|
|
124 printf ("Now discard file\n");
|
|
125 #endif
|
|
126
|
|
127 henkan ();
|
|
128 js_close (js);
|
|
129 }
|
|
130
|
|
131 void
|
|
132 henkan (void)
|
|
133 {
|
|
134 w_char u[1024];
|
|
135 struct wnn_env *c_env = env;
|
|
136 struct wnn_dai_bunsetsu *dp;
|
|
137
|
|
138 for (;;)
|
|
139 {
|
|
140 if (c_env == env)
|
|
141 {
|
|
142 printf ("yomi> ");
|
|
143 fflush (stdout);
|
|
144 }
|
|
145 else
|
|
146 {
|
|
147 printf ("kanji> ");
|
|
148 fflush (stdout);
|
|
149 }
|
|
150 if (gets (yomi) == NULL)
|
|
151 return;
|
|
152 if (yomi[0] == '!')
|
|
153 return;
|
|
154 if (yomi[0] == '@')
|
|
155 {
|
|
156 c_env = (c_env == env) ? rev_env : env;
|
|
157 continue;
|
|
158 }
|
|
159 strtows (u, yomi);
|
|
160 dcnt = js_kanren (c_env, u, WNN_BUN_SENTOU, NULL, WNN_VECT_KANREN, WNN_VECT_NO, WNN_VECT_BUNSETSU, &rb);
|
|
161 dp = (struct wnn_dai_bunsetsu *) rb.buf;
|
|
162 print_kanji (dp, dcnt);
|
|
163 }
|
|
164 }
|
|
165
|
|
166 void
|
|
167 print_kanji (struct wnn_dai_bunsetsu *dlist, int cnt)
|
|
168 {
|
|
169 int i;
|
|
170 struct wnn_sho_bunsetsu *sbn;
|
|
171
|
|
172 if (dlist == 0)
|
|
173 return;
|
|
174 putchar ('\n');
|
|
175 for (; cnt > 0; dlist++, cnt--)
|
|
176 {
|
|
177 sbn = dlist->sbn;
|
|
178 for (i = dlist->sbncnt; i > 0; i--)
|
|
179 {
|
|
180 putws (sbn->kanji);
|
|
181 printf ("-");
|
|
182 putws (sbn->fuzoku);
|
|
183 printf (" ");
|
|
184 sbn++;
|
|
185 }
|
|
186 printf ("|");
|
|
187 }
|
|
188 putchar ('\n');
|
|
189 fflush (stdout);
|
|
190 }
|
|
191
|
|
192 void
|
|
193 p_set (struct wnn_env *env1)
|
|
194 {
|
|
195 struct wnn_param pa;
|
|
196 pa.n = 2; /* n_bun */
|
|
197 pa.nsho = 10; /* nshobun */
|
|
198 pa.p1 = 2; /* hindoval */
|
|
199 pa.p2 = 40; /* lenval */
|
|
200 pa.p3 = 0; /* jirival */
|
|
201 pa.p4 = 100; /* flagval */
|
|
202 pa.p5 = 5; /* jishoval */
|
|
203 pa.p6 = 1; /* sbn_val */
|
|
204 pa.p7 = 15; /* dbn_len_val */
|
|
205 pa.p8 = -20; /* sbn_cnt_val */
|
|
206 pa.p9 = 0; /* kan_len_val */
|
|
207
|
|
208 js_param_set (env1, &pa);
|
|
209 }
|
|
210
|
|
211 void
|
|
212 putwchar (unsigned short x)
|
|
213 {
|
|
214 putchar (x >> 8);
|
|
215 putchar (x);
|
|
216 }
|
|
217
|
|
218 void
|
|
219 putws (unsigned short *s)
|
|
220 {
|
|
221 while (*s)
|
|
222 putwchar (*s++);
|
|
223 }
|
|
224
|
|
225 void
|
|
226 strtows (w_char *u, unsigned char *e)
|
|
227 {
|
|
228 int x;
|
|
229 for (; *e;)
|
|
230 {
|
|
231 x = *e++;
|
|
232 if (x & 0x80)
|
|
233 x = (x << 8) | *e++;
|
|
234 *u++ = x;
|
|
235 }
|
|
236 *u = 0;
|
|
237 }
|
|
238
|
|
239 void
|
|
240 err (void)
|
|
241 {
|
|
242 printf (wnn_perror ());
|
|
243 printf ("\n bye.\n");
|
|
244 exit (1);
|
|
245 }
|
|
246
|